Let us modify the document posting procedure.
- In Designer, open the Services document editor window and click the Posting tab.
- Add the Sales register to the list of registers affected by the document.
- Click the Other tab and then click Object module.
- Add the script lines that create Sales register records for the Services document to the handler of the Posting event, to the end of the loop, right after the EndIf operator and before the EndDo operator (listing 12.1).
Listing 12.1. Records of the Services document (fragment)
// register Sales Record = RegisterRecords.Sales.Add(); Record.Period = Date; Record.MaterialOrService = CurRowMaterialsAndServices.MaterialOrService; Record.Customer = Customer; Record.Technician = Technician; Record.Quantity = CurRowMaterialsAndServices.Quantity; Record.Revenue = CurRowMaterialsAndServices.Total; Record.Cost = CurRowMaterialsAndServices.Quantity * CurRowMaterialsAndServices.Cost;
- Before the loop set the Write property of the register record to True. The resulting procedure should look as shown in listing 12.2.
Listing 12.2. Records of the Service document
Procedure Posting(Cancel, Mode) RegisterRecords.BalanceOfMaterials.Write = True; RegisterRecords.CostOfMaterials.Write = True; RegisterRecords.Sales.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; // register Sales Record = RegisterRecords.Sales.Add(); Record.Period = Date; Record.MaterialOrService = CurRowMaterialsAndServices.MaterialOrService; Record.Customer = Customer; Record.Technician = Technician; Record.Quantity = CurRowMaterialsAndServices.Quantity; Record.Revenue = CurRowMaterialsAndServices.Total; Record.Cost = CurRowMaterialsAndServices.Quantity * CurRowMaterialsAndServices.Cost; EndDo; EndProcedure
You already know all the added expressions well.
Just note that the turnover register does not have a RecordType property, since specifying the record type (receipt or expense) only makes sense for balance accounting. As for turnover registers, we are only interested in the value that is written to the register resource.
Also note that you added the commands that create Sales register records to the end of the loop that iterates through the document tabular section, to the part that is not affected by the condition that checks whether an item is a material. This is important because in this register records are created for both materials and services.
Finally, let us edit the document form command interface to add the link for viewing the Sales 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 Sales accumulation register. - Select the Visible check box for this command.