Let us create the report form.
- Open the configuration object editor for the EmployeeAccruals report.
- On the Forms tab, in the Report form field, click the Open button and create the default report form.
- In the upper right pane of the form editor, click the Commands tab, click the Form command tab, and create the Recalculate command (fig. 18.28).
Fig. 18.28. Adding a form command
Let us specify the action for this command. - In the Action field, click the Open button.
- Click Create on client and then click OK.
This adds the Recalculate() procedure template to the form module. - Add the call of the RecalculateAccruals() procedure defined in the Calculations common module to the Recalculate() procedure (listing 18.8).
Listing 18.8. Recalculate() command handler
&AtClient Procedure Recalculate(Command) Calculations.RecalculateAccruals(PredefinedValue( "ChartOfCalculationTypes.MainAccruals.Salary")); Calculations.RecalculateAccruals(PredefinedValue( "ChartOfCalculationTypes.MainAccruals.Bonus")); EndProcedure
- Create the RecalculateAccruals() procedure in the Calculations common module (listing 18.9).
Listing 18.9. RecalculateAccruals() procedure
Procedure RecalculateAccruals(RequiredCalculationType) Export // Selecting records from the recalculation record set in the following order: // records from document1 for the listed employees // records from document2 for the listed employees, and so on Query = New Query( "SELECT | AccrualsRecalculation.RecalculationObject, | AccrualsRecalculation.Employee |FROM | CalculationRegister.Accruals.Recalculation AS AccrualsRecalculation |WHERE | AccrualsRecalculation.CalculationType = &RequiredCalculationType |TOTALS BY | AccrualsRecalculation.RecalculationObject"); Query.SetParameter("RequiredCalculationType", RequiredCalculationType); EmployeeList = New ValueList; // Iterating through the grouping by recorder SelectionByRecorder = Query.Execute().Select(QueryResultIteration.ByGroups); While SelectionByRecorder.Next() Do Recorder = SelectionByRecorder.RecalculationObject; // Iterating through the employee grouping for the selected recorder // and creating the employee list SelectionByEmployee = SelectionByRecorder.Select(); EmployeeList.Clear(); While SelectionByEmployee.Next() Do EmployeeList.Add(SelectionByEmployee.Employee); EndDo; // Getting the calculation register record set for the selected recorder RecordSet = CalculationRegisters.Accruals.CreateRecordSet(); RecordSet.Filter.Recorder.Value = Recorder; RecordSet.Read(); CalculateAccruals(RecordSet, RequiredCalculationType, EmployeeList); RecordSet.Write( , True); // Removing the recalculated records from the recalculation RecalculationRecordSet = CalculationRegisters.Accruals.Recalculations.Recalculation.CreateRecordSet(); RecalculationRecordSet.Filter.RecalculationObject.Value = Recorder; RecalculationRecordSet.Write(); EndDo; EndProcedure
In the beginning of the procedure a query selects recalculation records that contain the calculation type passed to the procedure, grouped by recalculation object.
Next, the procedure iterates through the query results to generate a list of employees for each recalculation object, reads the corresponding calculation register records, and calls the CalculateAccruals procedure(), which you used earlier to calculate records in the EmployeeAccruals document.
Once the calculation of records is completed, the procedure writes the record set without generating recalculation records, and clears the recalculation records for the recalculation object that has just been processed. - Return to the EmployeeAccruals report form.
So you specified the action (the command execution handler) for the Recalculate command. To be able to use the command, you have to create a button in the form and link it to the command (in the Command name button property).
The simplest way to do it is to drag the command from the Form command pane to the form controls pane. - Drag the Recalculate command to the MainCommandBar group of form controls.
This adds the Recalculate button, which is linked to the command, to the form (fig. 18.29).
Fig. 18.29. Adding a button to a form