Posting Services documents across three registers
Let us first modify the posting procedure of the Services document and then repost all Services documents in 1C:Enterprise mode to create new register records according to the modified posting algorithm.
In Designer mode
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 documentProcedure 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.
In 1C:Enterprise mode
Let us repost all of the Services documents in 1C:Enterprise mode and check that they create correct records in the Sales register.
- Start 1C:Enterprise in the debug mode.
- For each Services document, open it, click Post, and then open the Sales register records.
The sales records should look as shown in fig. 12.3a, 12.3b, 12.4a, 12.4b, 12.5a, and 12.5b.
Fig. 12.3a. Services document #1 records in the Sales register
Fig. 12.3b. Services document #1 records in the Sales register
Fig. 12.4a. Services document #2 records in the Sales register
Fig. 12.4b. Services document #2 records in the Sales register
Fig. 12.5a. Services document #3 records in the Sales register
Fig. 12.5b. Services document #3 records in the Sales register
You can see that the Sales register stores both material and service records.
Now you have virtually all the data you need to analyze operations of Jack of All Trades.
In the next lesson you will create some reports that will provide you with summary information on the company operations.