First of all, let us add the total amount to the print form of the Services document.
- Open Designer, expand the Services document branch, and double-click the Print template.
As you can see, the document template consists of named areas that are printed in a certain order.
The named areas listed at the left are generated by the wizard. You can create or delete areas, rename them, and so on.
Let us create a new area for displaying the total.
- Select two empty rows under the document tabular section and then, on the Table menu, point to Names and click Set name (fig. 8.11).
Fig. 8.11. Creating a cell area for displaying totals
- In the Name field, type Total and click OK.
To have the format of the added rows match the format of the document header and tabular section, let us change the column width.
- Drag the right border of column 2 in the spreadsheet header to align it with the № column.
The platform prompts you to create a new format for the selected lines.
- Confirm the creation of the new format.
- Perform steps 4-5 for columns 3, 4, 5, and 6.
- Within the created area, under the Price column, enter Total, and then, under the Total column, enter DocumentTotal (fig. 8.12).
Fig. 8.12. Filling cells that display totals
- Right-click the DocumentTotal cell and click Properties.
This opens the cell property palette.
- In the FillType property, select Parameter.
This indicates that the cell contains a parameter rather than text (fig. 8.13).
Fig. 8.13. Properties of the DocumentTotal cell
Each cell of the spreadsheet document can contain either a text, or a parameter, or a template.
A text is displayed on the screen as is.
A parameter is replaced by a value assigned to it using 1C:Enterprise script. The cell text is actually the parameter name.
A template is a text string with parameter values at predefined locations.
So, by setting the cell property to Parameter, you defined the DocumentTotal parameter of the area, which is replaced by a value when the print form is generated.
Let us open the Services document manager module.
- In the configuration object editor of the Service document, click the Other tab and then click Manager module (fig. 8.14).
Fig. 8.14. Opening the manager module of the Services document
- In the module, find the Print procedure and edit it as shown in listing 8.1 (new lines are marked with comments).
Listing 8.1. Printing a document form (fragment)
... AreaCaption = Template.GetArea("Caption"); Header = Template.GetArea("Header"); AreaMaterialsAndServicesHeader = Template.GetArea("MaterialsAndServicesHeader"); AreaMaterialsAndServices = Template.GetArea("MaterialsAndServices"); AreaTotal = Template.GetArea("Total"); // New line Spreadsheet.Clear(); InsertPageBreak = False; While Selection.Next() Do If InsertPageBreak Then Spreadsheet.PutHorizontalPageBreak(); EndIf; Spreadsheet.Put(AreaCaption); Header.Parameters.Fill(Selection); Spreadsheet.Put(Header, Selection.Level()); Spreadsheet.Put(AreaMaterialsAndServicesHeader); SelectionMaterialsAndServices = Selection.MaterialsAndServices.Select(); TotalSum = 0; // New line While SelectionMaterialsAndServices.Next() Do AreaMaterialsAndServices.Parameters.Fill(SelectionMaterialsAndServices); Spreadsheet.Put(AreaMaterialsAndServices, SelectionMaterialsAndServices.Level()); TotalSum = TotalSum + SelectionMaterialsAndServices.Total; // New line EndDo; AreaTotal.Parameters.DocumentTotal = TotalSum; // New line Spreadsheet.Put(AreaTotal); // New line InsertPageBreak = True; EndDo; ...The meaning of the added code is simple: it calls the Services document template using its name (Template).
The Total area (the one you have added to the template) is obtained using the GetArea() method and then saved to the AreaTotal variable.
In the loop that iterates through the document tabular section rows obtained as a result of query execution, the sum of the values in the Total column of the tabular section is calculated and stored to the TotalSum variable.
Then the value of the TotalSum variable is assigned to the DocumentTotal parameter (AreaTotal.Parameters.DocumentTotal), which is displayed in the Total area.
Finally, the total area is output to the spreadsheet document that will be displayed on the screen and printed out by the user (Spreadsheet.Put(AreaTotal)).
A spreadsheet document is displayed on the screen using the Print command handler in the client module of this command, while the print procedure itself is defined in the document manager module and executed on the server.