1C:Enterprise 8.3. Practical Developer’s Guide. Lesson 11 (1:20). Posting documents across multiple registers. Posting Services documents across two registers

Posting Services documents across two registers

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:

  1. Add another attribute, which stores the material cost, to the document tabular section.
  2. Modify the posting procedure of the Services document.
  3. In 1C:Enterprise mode repost all Services documents to execute the new posting algorithm for each document.

In Designer mode

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.

  1. Start 1C:Enterprise in the debug mode.
  2. In the Services section, run the Services command.

    This opens the list of services.
  3. Open the Services document #1 and set the cost of rubber tubing to 100 (fig. 11.13).

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    Fig. 11.13. Services document #1

    Now let us post the document and see how the Cost of materials register records change. 
  4. Click Post and then run the Cost of materials command (fig. 11.14).

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    Fig. 11.14. Cost of materials register records

    Now let us create and post two more Services documents.
  5. In the document list form, click the Create button.
    -OR-
    In the Services section, on the actions panel, on the Create menu, click Service (fig. 11.15).

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    Fig. 11.15. Creating the documents
  6. 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.

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    Fig. 11.16. Services document #2

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    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.

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    Fig. 11.18. Services document #2 register records

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In 1C:Enterprise mode
    Fig. 11.19. Services document #3 register records

Adding the document attribute

Let us add a new attribute to the Services document.

  1. In Designer, open the Services configuration object editor window and click the Data tab.
  2. Create the following tabular section attribute (fig. 11.10):
    • Cost. Type: Number, length: 15, precision: 2, non-negative
    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In Designer mode / Adding the document attribute
    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.
  3. Open the Services document form.
  4. In the upper left pane of the form editor, on the Attributes tab, expand the Object form attribute (fig. 11.11).

    Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In Designer mode / Adding the document attribute
    Fig. 11.11. Editing the Services document form

    You can see that it contains all of the attributes of the Services document.
  5. 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.
  6. 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).

Lesson 11 (1:20). Posting documents across multiple registers / Posting Services documents across two registers / In Designer mode / Adding the document attribute
Fig. 11.12. Editing the Services document form

Modifying the posting procedure

Let us modify the document posting procedure. 

  1. In Designer, open the Services document editor window and click the Posting tab. 
  2. 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.
  3. Click the Other tab and then click Object module.
  4. 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;
  5. 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. 

  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 Cost of materials accumulation register.
  4. Select the Visible check box for this command.

Leave a Reply

Your email address will not be published.

 

1C:Enterprise Developer's Community