Lifecycle and Recalculation
Lifecycle and Recalculation
Allowance lines are recalculated automatically during Doctrine flushes and manually through a console command.
Automatic recalculation
TimesheetAllowanceCalculationSubscriber listens to Doctrine onFlush.
It collects affected timesheets when scheduled insertions, updates, or deletions include:
TimesheetTimeEntryProjectClientAllowance
For project changes, it finds submitted, accepted, or approved timesheets for that project. For client allowance changes, it finds submitted, accepted, or approved timesheets for the allowance's client.
It then refreshes allowance lines only for timesheets in these statuses:
submittedacceptedapproved
The subscriber has an isRefreshing guard to avoid recursive recalculation.
Deleted allowance behavior
If a ClientAllowance is deleted, the subscriber tracks it and removes any calculated lines linked to that deleted object. New recalculation then produces any remaining valid lines from the current rule set.
Manual recalculation command
Command:
php bin/console app:allowances:recalculate-timesheets --forceOptions:
| Option | Meaning |
|---|---|
--force | Persist recalculated lines. Without it, the command only reports how many timesheets would be recalculated. |
--limit=N | Process a limited number of timesheets, ordered by updated date descending. |
--id=UUID | Recalculate one specific timesheet. |
The command targets submitted, accepted, and approved timesheets.
Recalculation order with award snapshots
Allowance recalculation and award recalculation are separate subscribers. Award calculation listens for TimesheetAllowanceLine changes as well as timesheet/time-entry/client-allowance changes, then queues a post-flush award snapshot. This lets award snapshots include current allowance lines.