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.