- In Designer mode
- In 1C:Enterprise mode
Finally let us modify the posting procedure for the Services documents.
This posting procedure will be based on a Jack of All Trades management request. When writing off materials expended in the course of rendering services, there should be a way to specify a custom cost for each material, which is calculated by the management on the basis of current market conditions.
Since the Services document only reflects material prices, you have to:
- Add another attribute, which stores the material cost, to the document tabular section.
- Modify the posting procedure of the Services document.
- In 1C:Enterprise mode repost all Services documents to execute the new posting algorithm for each document.
In Designer mode
Adding the document attribute
Let us add a new attribute to the Services document.
- In Designer, open the Services configuration object editor window and click the Data tab.
- Create the following tabular section attribute (fig. 11.10):
- Cost. Type: Number, length: 15, precision: 2, non-negative
Fig. 11.10. Editing the Services document
Let us add the Cost field linked to the new attribute to the tabular section of the Services document form.
- Open the Services document form.
- In the upper left pane of the form editor, on the Attributes tab, expand the Object form attribute (fig. 11.11).
Fig. 11.11. Editing the Services document form
You can see that it contains all of the attributes of the Services document.
- Locate the Cost attribute in the tabular section and drag it to the form controls pane in the upper left corner of the form editor.
- Move the new control to the position after the MaterialOrService field and keep the default properties of the control.
The new attribute is immediately displayed in the form preview in the bottom of the form editor window (fig. 11.12).
Fig. 11.12. Editing the Services document form
Modifying the posting procedure
Let us modify the document posting procedure.
- In Designer, open the Services document editor window and click the Posting tab.
- Add the CostOfMaterials register to the list of registers affected by the document.
To preserve the changes that you made in the posting procedure in the previous lesson, do not use the Register records wizard this time. Instead, let us make the required changes in the Posting event handler of the Services document manually.
- Click the Other tab and then click Object module.
- Add the script lines that create CostOfMaterials register records for the Services document to the handler of the Posting event, to the end of the loop, right before the EndIf operator (listing 11.3).
Listing 11.3. Records of the Services document (fragment)
// register CostOfMaterials Expense Record = RegisterRecords.CostOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Expense; Record.Period = Date; Record.Material = CurRowMaterialsAndServices.MaterialOrService; Record.Cost = CurRowMaterialsAndServices.Quantity * CurRowMaterialsAndServices.Cost;
- Before the loop set the Write property of the register record set to True and remove the comments generated by the wizard. The resulting procedure should look as shown in listing 11.4.
Listing 11.4. Records of the Services document
Procedure Posting(Cancel, Mode) RegisterRecords.BalanceOfMaterials.Write = True; RegisterRecords.CostOfMaterials.Write = True; For Each CurRowMaterialsAndServices In MaterialsAndServices Do If CurRowMaterialsAndServices.MaterialOrService.MaterialServiceType = Enums.MaterialServiceTypes.Material Then // register BalanceOfMaterials Expense Record = RegisterRecords.BalanceOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Expense; Record.Period = Date; Record.Material = CurRowMaterialsAndServices.MaterialOrService; Record.Warehouse = Warehouse; Record.Quantity = CurRowMaterialsAndServices.Quantity; // register CostOfMaterials Expense Record = RegisterRecords.CostOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Expense; Record.Period = Date; Record.Material = CurRowMaterialsAndServices.MaterialOrService; Record.Cost = CurRowMaterialsAndServices.Quantity * CurRowMaterialsAndServices.Cost; EndIf; EndDo; EndProcedure
Note that the Cost register dimension is calculated by multiplying the cost and the quantity specified in the document tabular section.
Finally, let us edit the document form command interface to add the link for viewing the CostOfMaterial register records related to the document to the form navigation panel.
- Open the Services document form.
- In the upper left pane, click the Command interface tab.
- In the Navigation panel branch, expand the Go to node.
It contains the command that opens the list of the Cost of materials accumulation register.
- Select the Visible check box for this command.
In 1C:Enterprise mode
In 1C:Enterprise mode you have to repost all Services documents. This is required for the documents to create new register records according to the posting algorithm you have just modified.
- Start 1C:Enterprise in the debug mode.
- In the Services section, run the Services command.
This opens the list of services.
- Open the Services document #1 and set the cost of rubber tubing to 100 (fig. 11.13).
Fig. 11.13. Services document #1
Now let us post the document and see how the Cost of materials register records change.
- Click Post and then run the Cost of materials command (fig. 11.14).
Fig. 11.14. Cost of materials register records
Now let us create and post two more Services documents.
- In the document list form, click the Create button.
In the Services section, on the actions panel, on the Create menu, click Service (fig. 11.15).
Fig. 11.15. Creating the documents
- Fill the document as shown in fig. 11.16 and post it, and then create another document, fill it as shown in fig. 11.17, and post it.
Note that the dates of these documents are different from the dates of the first document, we will utilize this difference in a future lesson.
Fig. 11.16. Services document #2
Fig. 11.17. Services document #3
The Cost of materials register records for the Services documents #2 and #3 should look as shown in fig. 11.18 and 11.19.
Fig. 11.18. Services document #2 register records
Fig. 11.19. Services document #3 register records