1C:Enterprise 8.3. Practical Developer’s Guide. Lesson 10 (0:40). Enumerations. Recording expenses for materials only

Recording expenses for materials only

In lesson 6, when you created the Services document records in the BalanceOfMaterials accumulation register, we mentioned that these records were not entirely correct because they included not only expended materials but also rendered services (listing 10.3).

Listing 10.3. The Posting() procedure of the Services document

Procedure Posting(Cancel, Mode)
    //{{__REGISTER_REGISTERRECORDS_WIZARD
    // This fragment was built by the wizard.
    // Warning! All manually made changes will be lost next time you use the wizard.
    // register BalanceOfMaterials Expense
 
    RegisterRecords.BalanceOfMaterials.Write = True;
    For Each CurRowMaterialsAndServices In MaterialsAndServices Do
        Record = RegisterRecords.BalanceOfMaterials.Add();
        Record.RecordType = AccumulationRecordType.Expense;
        Record.Period = Date;
        Record.Material = CurRowMaterialsAndServices.MaterialOrService;
        Record.Warehouse = Warehouse;
        Record.Quantity = CurRowMaterialsAndServices.Quantity;
    EndDo;
 
    //}}__REGISTER_REGISTERRECORDS_WIZARD
EndProcedure

Let us modify the document so that only material expense records are added to the register.

First, you have to change the posting procedure in Designer to add only material expense records to the register, and then you have to repost all the Services documents in 1C:Enterprise mode to have the register data modified in compliance with the new document posting algorithm.

This enhancement is not optimal in terms of performance but it ensures that the BalanceOfMaterials register stores the correct data.

Note. We will discuss a more efficient algorithm of posting this document in lesson 14, after we study how 1C:Enterprise processes queries.

In Designer mode

Let us refine the document register records by excluding any tabular section rows that contain services.

  1. In Designer, right-click the Services document and then click Open object module.

    This opens the Services document module.
  2. Add a condition to the handler of the Posting event, to the beginning of the loop that iterates through the tabular section rows, after the following line:

    For Each CurRowMaterialsAndServices In MaterialsAndServices Do
    The resulting procedure should look as shown in listing 10.4.

    Listing 10.4. The Services document records

    Procedure Posting(Cancel, Mode)
    
        //{{__REGISTER_REGISTERRECORDS_WIZARD
        // This fragment was built by the wizard.
        // Warning! All manually made changes will be lost next time you use the wizard.
     
        // register BalanceOfMaterials Expense
        RegisterRecords.BalanceOfMaterials.Write = True;
        For Each CurRowMaterialsAndServices In MaterialsAndServices Do
            If CurRowMaterialsAndServices.MaterialOrService.MaterialServiceType = Enums.MaterialServiceTypes.Material Then
                Record = RegisterRecords.BalanceOfMaterials.Add();
                Record.RecordType = AccumulationRecordType.Expense;
                Record.Period = Date;
                Record.Material = CurRowMaterialsAndServices.MaterialOrService;
                Record.Warehouse = Warehouse;
                Record.Quantity = CurRowMaterialsAndServices.Quantity;
            EndIf;
        EndDo;
    
        //}}__REGISTER_REGISTERRECORDS_WIZARD
    EndProcedure

The added script excludes the tabular section rows where the item type is not Material from the loop. Let us examine this in detail.

In each loop step the CurRowMaterialsAndServices variable contains the data of the current row of the MaterialsAndServices tabular section.

The MaterialOrService column name specified after a dot (CurRowMaterialsAndServices.MaterialOrService) calls a reference to the material or service item stored in the current tabular section row.

The MaterialServiceType specified after a dot (CurRowMaterialsAndServices.MaterialOrService.MaterialServiceType) calls the MaterialServiceType attribute of this item of the MaterialsAndServices catalog.

The comparison operator (=) compares the obtained value with the Material value of the MaterialServiceTypes enumeration (Enums.MaterialServiceTypes.Material).

If the values match, the operators included in the loop are executed. Otherwise the next loop iteration, which processes the next tabular section row, is started.

In 1C:Enterprise mode

Let us check the changes in the posting procedure of the Services document.

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

    This opens the list of documents, which contains a single Services document.
  3. Open the document and make the following changes:
    • Remove the Philips transistor.
    • Add the Water hookup service.
    • Add the Tubing, rubber material (fig. 10.7).
    Lesson 10 (0:40). Enumerations / Recording expenses for materials only / In 1C:Enterprise mode
    Fig. 10.7. The modified Services document

    Note that the prices are filled automatically based on the Prices information register data.
  4. In the document command bar, click Post.
  5. In the form navigation panel, run the Balance of materials command.

    This opens the list of Balance of materials register records related to this document (fig. 10.8).  

    Lesson 10 (0:40). Enumerations / Recording expenses for materials only / In 1C:Enterprise mode
    Fig. 10.8. Balance of materials register records

    As you can see, the records for the Balance of materials register only include the rows containing the materials. There is no record for the water hookup service. 

    Also note that the item presentation in the Material field of the Balance of materials register includes the item type (material), exactly as you specified earlier.

Leave a Reply

Your email address will not be published. Required fields are marked *

1C:Enterprise Developer's Community