...
When the user is on the Compensation Plan detail page, and clicks on Recalculate, the system will perform full recalculation of the Compensation Plan, which involves several actions.
...
it executes the header logic in pre-phase mode. Such code can create input fields on header and modify the structure of the document (e.g. create/delete/update the line items and folder)
for every item, it executes the compensation logic (only elements from group compensation) in normal mode. This logic will calculate and provide the results. The system will store those results to the line item.
it executes the header logic again, but in post-phase mode. Such code can calculate summarized results of the whole document and store the results to the header (or to line items)