In Designer mode

Let us modify the document posting procedure.

  1. In Designer, open the Services document editor window and click the Posting tab.
  2. Add the Sales register to the list of registers affected by the document.
  3. Click the Other tab and then click Object module.
  4. 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;
  5. 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.

  1. Open the Services document form.
  2. In the upper left pane, click the Command interface tab.
  3. In the Navigation panel branch, expand the Go to node.
    It contains the command that opens the list of the Sales accumulation register.
  4. Select the Visible check box for this command.
Next page: In 1C:Enterprise mode
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.