1C:Enterprise 8. Practical Developer’s Guide. Lesson 11. Posting a Document across Multiple Registers.

Lesson 11. Posting a Document across Multiple Registers

Estimated duration of the lesson is 1 hour 20 minutes.

CONTENT:

This lesson will cover how a single document can "deliver" information to multiple configuration registers and when this feature may be required.

During the lesson we will create another accumulation register for our configuration and modify document posting procedure so that the documents record the required data to both registers.

We will also prepare for studying of the next lesson.

Why Post a Document across Multiple Registers

Up to this point we have only considered the quantitative register records of materials within Jack of All Trades. We have created the BalanceOfMaterials accumulation register for that purpose.

However, as you have probably guessed, quantitative accounting only will hardly meet the needs of our company. Clearly, we will also need to know what monetary resources were expended to purchase various materials and what the company's material reserves amount to in monetary terms.

Once we started automating our company, the management at Jack of All Trades expressed a desire for all material balances to be accounted for using the average cost method.

In other words, when materials are acquired, they are accounted for in terms of purchase prices, while when expended they are accounted for at an average cost which is calculated based on the aggregate purchase of a given material and the total quantity of this available in Jack of All Trades.

Since the structure of such information is absolutely different from quantitative account, we will use yet another accumulation register named CostOfMaterials, which will store data regarding the overall cost of various materials we will use.

So the ReceiptOfGoods and ServicesRendered documents will need to create register records simultaneously in the BalanceOfMaterials register and in the CostOfMaterials register, reflecting balance changes.

Adding Another Accumulation Register

In the Designer Mode

The CostOfMaterials register is very simple so we will not detail the procedure of creating this register.

First we create a new accumulation register configuration object named CostOfMaterials.

We will enter Cost of Materials Register Records for the Extended list presentation. This title will be displayed in the window of the register records list.

On the Subsystems tab check that this register will be displayed in the following subsystems: Accounting, Goods Management, and Rendering Services.

On the Data tab create one dimension for the register (Material, type CatalogRef.Products) and one resource (Cost with a length of 15 and 2 decimal places).

Once created, the CostOfMaterials register will look as follows in the configuration tree (fig. 11.1):

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.1. Cost of materials accumulation register

Now we will edit the command interface so that the link to view our accumulation register is available in the subsystems Accounting, Rendering Services, and Goods Management.

Highlight the Subsystems branch in the configuration object tree, open its context menu and select All subsystems.

In the window that opens highlight Accounting in the Subsystems list on the left.

The right-hand Command Interface list will display all the commands of the selected subsystem.

In the Navigation Panel.Normal group enable visibility for the Cost of Materials command and drag it to the group Navigation Panel.See also (fig. 11.2).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.2. Subsystem Command Interface Setup

Similarly, highlight the subsystems RenderingServices and GoodsManagement and enable visibility for the Cost of Materials group in the Normal group of the navigation panel and drag it to See also.

Now we can proceed to making changes in the procedures for posting documents.

Let's begin with the simplest document ReceiptOfGoods.

Posting the ReceiptOfGoods across the Two Registers

In the Designer Mode

Modifying the Posting Procedure

In the Designer, open the configuration object editor for the ReceiptOfGoods document and go to the Register Records tab.

In the list of registers check that the document will now create records for the CostOfMaterials register as well (fig. 11.3).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.3. Creating register records of the ReceiptOfGoods document in the Cost of Materials register

This time, we will not use the document register records wizard and will make our changes directly in the Posting event handler for the ReceiptOfGoods document.

The thing is that the wizard supports creating records for multiple registers simultaneously (registers can be added in the register records wizard). But when the posting procedure is already available, using the wizard will result in deleting the existing procedure. So if we were to use the wizard now, we would have had to describe records for both registers.

So it is simpler to modify the existing procedure manually.

Go to the Other tab and open the object module.

To do so, click Object Module (fig. 11.4).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Open the procedure for the Posting event handler.

In the very end of the loop before the EndDo we will add some lines of code to generate records in the CostOfMaterials register (listing 11.1).

Listing 11.1. Register Records of the ReceiptOfGoods Document (fragment)

// register CostOfMaterials ReceiptOfGoods
Record = RegisterRecords.CostOfMaterials.Add();
Record.RecordType = AccumulationRecordType.ReceiptOfGoods;
Record.Period = Date;
Record.Material = CurRowMaterials.Material;
Record.Cost = CurRowMaterials.Total;

Before the beginning of the loop we will select True for the Write property for the record set of this register so that the created records could be written automatically upon exit from the document posting procedure. We will also remove the comments added by the wizard.

This results in the following appearance of the Posting procedure (listing 11.2).

Listing 11.2. Register Records of the ReceiptOfGoods Document

Procedure Posting(Cancel, Mode)

	RegisterRecords.BalanceOfMaterials.Write = True;
	RegisterRecords.CostOfMaterials.Write = True;
	
	For Each CurRowMaterials In Materials Do
	
		// register BalanceOfMaterials ReceiptOfGoods
		Record = RegisterRecords.BalanceOfMaterials.Add();
		Record.RecordType = AccumulationRecordType.ReceiptOfGoods;
		Record.Period = Date;
		Record.Material = CurRowMaterials.Material;
		Record.Warehouse = Warehouse;
		Record.Quantity = CurRowMaterials.Quantity;
		
		// register CostOfMaterials ReceiptOfGoods
		Record = RegisterRecords.CostOfMaterials.Add();
		Record.RecordType = AccumulationRecordType.ReceiptOfGoods;
		Record.Period = Date;
		Record.Material = CurRowMaterials.Material;
		Record.Cost = CurRowMaterials.Total;
		
	EndDo;
EndProcedure

Adding a Command to Navigate to the Register Records

Finally, we will edit the command interface of the document form so that the navigation panel made it possible to go to the list of Cost of Materials register records related to the document.

To do so, open the form of the ReceiptOfGoods document.

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.5. Command interface setup of the ReceiptOfGoods document Form

In the upper left window navigate to the Command Interface tab.

In the Navigation Panel section expand Go To group and locate the command that opens the accumulation register named Cost of Materials.

Check the property Visibility for this command (fig. 11.5).

In the 1C:Enterprise Mode

In the 1C:Enterprise we will need to post again (repost) all the receipts of goods. This is required for the documents to create new records in the registers in compliance with the posting algorithm we have just modified.

Run 1C:Enterprise in the debugging mode. Open the list of documents using the Receipts of goods command in the navigation panel of the Goods Management section.

Highlight all the Receipts of goods simultaneously (press and hold Ctrl) and repost them using All Actions4Post command.

Now open the first document (fig. 11.6) and use the commands to navigate to the Balance Of Materials and Cost of Materials registers to make sure that the document actually creates the required records both in the first accumulation register (fig. 11.7) and in the second one (fig. 11.8).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.6. Receipt of goods No. 1

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.7. Records of the Balance Of Materials register

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.8. Records of the Cost of Materials register

Posting the Services Rendered Document across Two Registers

Finally we will modify the procedure for posting ServicesRendered documents.

In doing so, we will follow the request of the management at Jack of All Trades. The main thrust of their request is that, at the first stage, when writing off materials expended in the course of rendering services, there should be a way to specify a separate cost for those same materials, calculated by the management on the basis of current market conditions.

Since the ServicesRendered document only reflects products price, we will need to:

  • Add another attribute to the document tabular section where product price will be specified;
  • Next modify the procedure of posting the ServicesRendered document;
  • And finally in the 1C:Enterprise mode repost all these documents for the newly modified algorithm of posting ServicesRendered documents is implemented.

In the Designer Mode

Creating a New Document Attribute

In the Designer open the configuration object editor for the ServicesRendered document and go to the Data tab.

Create a new attribute of the document tabular section named Cost (type Number, length 15, 2 decimal places, non-negative (fig. 11.9).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.9. Editing the ServicesRendered document

Now open the DocumentForm form of the ServicesRendered document and add a field to display the new Cost attribute into the ProductList tabular section.

To do so, in the upper right window of the form editor use the Attributes tab to expand the Object attribute of the form (fig. 11.10).

You can see that it includes all the attributes of the ServicesRendered document.

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.10. Editing the ServicesRendered document form

Locate the Cost attribute in the tabular section and drag it to the form controls window located in the upper left pane of the form editor.

The new control should be located in the form controls structure after the Product field. Confirm the default properties of the form control.

The new attribute will be immediately displayed in the document form located in the lower left window of the form editor (fig. 11.11).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.11. Editing the ServicesRendered document form

Modifying the Posting Procedure

Now create register records for the ServicesRendered document using the same steps we used for the ReceiptOfGoods document.

In the configuration object editor of the ServicesRendered document switch to the Register Records tab.

In the list of registers check that the document will now create records for the CostOfMaterials register as well.

Go to the Other tab and open the object module. To do so, click Object Module.

Open the procedure for the Posting event handler.

In the very end of the loop before the EndDo we will add some lines of code to generate records in the CostOfMaterials register from the ServicesRendered document (listing 11.3).

Listing 11.3. Register records of the ServicesRendered document (fragment)

// register CostOfMaterials Expense
Record = RegisterRecords.CostOfMaterials.Add();
Record.RecordType = AccumulationRecordType.Expense;
Record.Period = Date;
Record.Material = CurRowProductList.Product;
Record.Cost = CurRowProductList.Quantity * CurRowProductList.Cost;

Before the loop itself we will select True for the Write property of the record set for this register. Delete the comments added by the wizard.

This results in the following appearance of the Posting procedure (listing 11.4):

Listing 11.4. Register records of the ServicesRendered document

Procedure Posting(Cancel, Mode)

	RegisterRecords.BalanceOfMaterials.Write = True;
	RegisterRecords.CostOfMaterials.Write = True;
	
	For Each CurRowProductList In ProductList Do
		If CurRowProductList.Product.ProductType = Enums.ProductTypes.Material Then
		
			// register BalanceOfMaterials Expense
			Record = RegisterRecords.BalanceOfMaterials.Add();
			Record.RecordType = AccumulationRecordType.Expense;
			Record.Period = Date;
			Record.Material = CurRowProductList.Product;
			Record.Warehouse = Warehouse;
			Record.Quantity = CurRowProductList.Quantity;
			
			// register CostOfMaterials Expense
			Record = RegisterRecords.CostOfMaterials.Add();
			Record.RecordType = AccumulationRecordType.Expense;
			Record.Period = Date;
			Record.Material = CurRowProductList.Product;
			Record.Cost = CurRowProductList.Quantity * CurRowProductList.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, we will edit the command interface of the document form so that the navigation panel made it possible to go to the list of Cost of Materials register records related to the document.

To do so, open the form of the ServicesRendered document.

In the upper left window navigate to the Command Interface tab.

In the Navigation Panel section expand Go To group and locate the command that opens the accumulation register named Cost of Materials.

Check the property Visibility for this command.

In the 1C:Enterprise Mode

In the 1C:Enterprise mode we will need to post again (repost) all the documents recorded rendered services. This is required for the document to create new records in the registers in compliance with the posting algorithm we have just modified.

Run 1C:Enterprise in the debugging mode and open the list of documents using the Services Rendered command in the navigation panel of the Rendering Services section.

Open the document named Services Rendered No. 1 and specify the price of the rubber tubing as 100 (fig. 11.12).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.12. The Services Rendered No. 1 Document

Post the Services Rendered No. 1 document and review the document's records in the Cost of Materials register.

To do so, click Post and execute the command to navigate to the Cost of Materials register (fig. 11.13).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.13. Records of the Cost of Materials Register

Now create and post two more Services Rendered documents.

To do so, in the form of documents list click New or in the action panel of the Rendering Services section use the Services Rendered command (fig. 11.14).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

We will need these documents later so pay close attention and note that these documents are created with different dates (fig. 11.15, 11.16).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.15. The Services Rendered No. 2 document

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.16. The Services Rendered No. 3 Document

The records of the documents Services Rendered No. 2 and No. 3 for the Cost of Materials register should look as follows respectively (fig. 11.17, 11.18).

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.17. Register records of the document Services Rendered No. 2

1C:Enterprise 8. Practical Developer's Guide. Lesson 11. Posting a Document across Multiple Registers

Fig. 11.18. Register records of the document Services Rendered No. 3

Quiz

  • Why may we need to post a document across multiple registers?
  • How does one create records for the document across multiple registers in a document posting event handler?
  • How does one create document register records without using the register records wizard?
  • How does one generate and write document register records into an accumulation register using 1C:Enterprise script tools?
  • How does one add a new attribute to a document form?

Leave a Reply

Your email address will not be published.

 

1C:Enterprise Developer's Community