Creating a function that returns material or service price

 


First, let us create the RetailPrice() function that returns the current material or service retail price, and let us store it to a common module.

  1. In Designer, in the configuration object tree, in the CommonCommon modules branch, add a Common module configuration object and name it CatalogProcessing.

    In the module property palette the Server check box is selected by default. This means that the module instances are only compiled on the server.
  2. Select the Server call check box.

    This allows calling export procedures and functions of the module from the client (fig. 9.9).


    Fig. 9.9. Common module properties
  3. Add the following script to the module (listing 9.1).

    Listing 9.1. Function RetailPrice()

    Function RetailPrice(EffectiveDate, MaterialOrServiceItem) Export
        //Creating auxiliary Filter object
        Filter = New Structure("MaterialOrService", MaterialOrServiceItem); 
        
        //Getting effective register resource values
        ResourceValues = InformationRegisters.Prices.GetLast(EffectiveDate, Filter);
        Return ResourceValues.Price;
    EndFunction

Now let us examine this script.

The function has two parameters:

  • EffectiveDate, type: Date. The point on the time axis for which you want to know the retail price.
  • MaterialOrServiceItem, type: reference to an item of the MaterialsAndServices catalog. The item whose price you want to know.

The first line in the function body creates the auxiliary Filter object.

It is a structure that contains a filter by register dimensions. It includes the register records where the MaterialOrService register dimension is equal to the catalog item reference passed to the function.

The structure key name MaterialOrService must be identical to the register dimension name that you specified in Designer. The structure item value MaterialOrServiceItems is the value filtered by the specified dimension.

The second line calls the manager of the Prices information register (InformationRegisters.Prices) and executes its method GetLast(), which returns the resource values for the latest register record that corresponds to the date passed to the function (EffectiveDate) and for the specified register dimension values (Filter).

The GetLast method retrieves a structure that contains the resource values. This structure is stored to the ResourceValues variable. In general a register can have multiple resources. The Prices register has a single resource, so the method retrieves a structure with a single element.

This is why in the next line you can get the required retail price by specifying the register resource name after a dot (ResourceValues.Price). The function returns this value.

Now let us have this function called at some point in document processing algorithms.


Comments
0
Add comment