In Designer mode

 


Let us modify the posting procedure.

  1. In Designer, open the editor of the GoodsReceipt document configuration object.
  2. On the Posting tab, specify that the document creates records in the Primary accounting register.
  3. On the Other tab, open the object module.
  4. Open the Posting event handler procedure, and at the end of the loop before the EndDo line add the script that generates Primary register records (listing 16.1).

    Listing 16.1. Register records of the GoodsReceipt document (fragment)

    // register Primary
    Record = RegisterRecords.Primary.Add();
    Record.AccountDr = ChartsOfAccounts.Main.Inventory;
    Record.AccountCr = ChartsOfAccounts.Main.AccountsPayable;
    Record.Period = Date;
    Record.Sum = CurRowMaterials.Total;
    Record.QuantityDr = CurRowMaterials.Quantity;
    Record.ExtDimensionsDr[ChartsOfCharacteristicTypes.ExtraDimensionTypes.Materials] = 
        CurRowMaterials.Material;
  5. Before the beginning of the loop, set the Write property of the Primary register record set to True.

    This writes the register changes to the database.

    The resulting Posting procedure should look as shown in listing 16.2.

    Listing 16.2. Register records of the GoodsReceipt document

    Procedure Posting(Cancel, Mode)
    	
        RegisterRecords.BalanceOfMaterials.Write = True;
        RegisterRecords.CostOfMaterials.Write = True;
        RegisterRecords.Primary.Write = True;
    	
        For Each CurRowMaterials In Materials Do
     
            // register BalanceOfMaterials Receipt
            Record = RegisterRecords.BalanceOfMaterials.Add();
            Record.RecordType = AccumulationRecordType.Receipt;
            Record.Period = Date;
            Record.Material = CurRowMaterials.Material;
            Record.PropertySet = CurRowMaterials.PropertySet;
            Record.Warehouse = Warehouse;
            Record.Quantity = CurRowMaterials.Quantity;
     
            // register CostOfMaterials Receipt
            Record = RegisterRecords.CostOfMaterials.Add();
            Record.RecordType = AccumulationRecordType.Receipt;
            Record.Period = Date;
            Record.Material = CurRowMaterials.Material;
            Record.Cost = CurRowMaterials.Total;
    		
            // register Primary
            Record = RegisterRecords.Primary.Add();
            Record.AccountDr = ChartsOfAccounts.Main.Inventory;
            Record.AccountCr = ChartsOfAccounts.Main.AccountsPayable;
            Record.Period = Date;
            Record.Sum = CurRowMaterials.Total;
            Record.QuantityDr = CurRowMaterials.Quantity;
            Record.ExtDimensionsDr[ChartsOfCharacteristicTypes.ExtraDimensionTypes.Materials] = 
                CurRowMaterials.Material;
     
        EndDo;
    	
    EndProcedure

Now let us examine this script.

As you can see, accounting register records are generated in the same manner as accumulation register records.

But during the creation of the data storage table the platform added a number of attribute fields that originate from using the Main chart of accounts.

First of all, these are the AccountDr and AccountCr fields. These fields store accounts that have their debit and credit values affected by this posting.

Besides, for each register dimension or attribute that is linked to an accounting flag the platform creates a pair of fields to store resource values separately for posting debits and credits: QuantityDt and QuantityCr. And for the accounts that have extra dimensions the platform creates the ExtDimensionDr and ExtDimensionCr collections.

If you take a look at the table 16.1, you will see that when a goods receipt is posted, the Inventory (5000) account serves as a debit account while AccountsPayable (4000) serves as a credit account.

You access an account using the ChartsOfAccounts global context property. This property provides access to all the charts of accounts available in the configuration. Then you specify the name of the required chart of accounts (Main), separated by a dot. And then you specify the name of a predefined account from this chart of accounts (Inventory) after another dot. It is one of the four predefined accounts that you created earlier.

Since quantitative accounting is only available for the Inventory (5000) account, the QuantityDr register field is filled with the quantity of material units from the document tabular section. The QuantityCr register field is not filled because quantitative accounting is not applied to the credit account of the posting (AccountsPayable).

Now look at the last line of the loop where a value is assigned to the debit extra dimension.

For each posting, the number of extra dimensions on the debit account is not equal to the number of extra dimensions on the credit account. These numbers are taken from the account definitions in the chart of accounts. Therefore, for each accounting register record, the platform stores two value collections: a collection of debit extra dimensions and a collection of credit extra dimensions. Each of them contains a number of elements equal to the number of extra dimension types defined for the respective account (debit or credit) in the chart of accounts.

You can access a collection element by specifying the respective extra dimension type (ChartsOfCharacteristicTypes.ExtraDimensionTypes.Materials) in square brackets.

Another way to access a collection element is specifying the name of a predefined extra dimension type separated by a dot from the debit extra dimension collection.

In other words, the statement Record.ExtDimensionsDr[ChartsOfCharacteristicTypes.ExtraDimensionTypes.Materials] gives the same result as the statement Record.ExtDimensionDr.Materials.

The ExtDimensionCr register collection is not filled because accounting by extra dimensions is not applied to the credit account of the posting (AccountsPayable).

Finally, let us edit the command interface of the document form to add the command that opens the list of the Primary register records related to that document to the form navigation panel.

  1. Open the GoodsReceipt document form.
  2. In the upper left pane, click the Command interface tab.
  3. In the Navigation panel branch, expand the Go to node and select the Visible check box for the Primary command.

Comments
0
Add comment