1.0.10 • Published 2 years ago

@kinaxis/unit-of-measure v1.0.10

Weekly downloads
-
License
Proprietary. See ...
Repository
-
Last release
2 years ago

unit-of-measure

Helper functions for applying unit of measure conversions.

Documentation

Types

ControlSet

A grouping of RapidResponse control table settings.

To use RapidResponse control sets in an embedded algorithm, the algorithm must have appropriate dependencies on the ControlSet table.

For more information about control tables and control sets, see https://help.kinaxis.com/20162/GlobalHelp/Content/RR_Integration/Data_model_and_Integration/Control_tables_and_control_sets.htm.

PropertyTypeDescription
ValuestringThe name of the control set.

UnitOfMeasure

Defines the magnitude of a RapidResponse quantity with respect to the base unit of measure.

To use RapidResponse units of measure in an embedded algorithm, the algorithm must have appropriate dependencies on the UnitOfMeasure table.

PropertyTypeDescription
ValuestringThe name of the unit of measure.
BaseConversionnumberThe factor to use when converting from the base unit of measure.
ControlSetControlSetThe unit of measure's control set.

ItemSpecificUOMConversion

A unit of measure used on an individual item basis, rather than for all items. This is used to override the standard conversion rate.

PropertyTypeDescription
UnitOfMeasureUnitOfMeasureThe unit of measure to override.
FactornumberThe factor to use when converting from the base unit of measure.

NumberUoM

A converted quantity with its associated unit of measure.

PropertyTypeDescription
NumbernumberThe converted quantity.
UnitOfMeasureUnitOfMeasureThe unit of measure of Number.
IsMoneybooleanWhether or not Number is a money value.
ItemSpecificUoMItemSpecificUOMConversion[] | undefinedOptional list of units of measure to override when doing conversions.

Functions

GetTargetUoM(tables, uom, controlSet)

Retrieves a specific unit of measure.

For example, a user may want to retrieve the unit of measure for "Milliliter" in the "Volume" control set. The output would resemble

{
    Value: "Milliliter",
    BaseConversion: 0.001,
    ControlSet: { Value: "Volume" }
}
ArgumentTypeDescription
tablesTablesAll global tables. Currently this function only looks at the UnitOfMeasure table. A global dependency on the Mfg::UnitOfMeasure table and Core::ControlSet is required to use this library.
uomstringA string representing the desired unit of measure (e.g., "Milliliter"). This string parameter is analogous to the "Value" string key field in the Mfg::UnitOfMeasure table.
controlSetControlSetThe control set related to the desired unit of measure (e.g., "Volume"). This control set parameter is analogous to the reference key field in the Mfg::UnitOfMeasure table.

Return value: A UnitOfMeasure object which matches uom and controlSet. If a unit of measure can not be found based on the given uom and controlSet, undefined is returned.


ConvertUoM_Quantity(uom, tables, targetUoM)

Converts a quantity value from a given unit of measure to another unit of measure.

For example, a user may want to convert 5 Liters into Milliliters. One would expect the result to be 5000 Millilitres.

ArgumentTypeDescription
uomNumberUoMA quantity value with an associated unit of measure. Example: { Number: 5, UnitOfMeasure: { Value: "Liter", BaseConversion: 1, ControlSet: { Value: "Volume" } }, IsMoney: false }. The example illustrates 5 Liters.
tablesTablesAll global tables. Currently this function only looks at the UnitOfMeasure table. A global dependency on the Mfg::UnitOfMeasure table and Core::ControlSet is required to use this library.
targetUoMstringThe target unit of measure to convert the uom into. First, uom.ItemSpecificUoM is searched (if present) and then tables.UnitOfMeasures is searched if no item-specific entry for the target is found.

Return value: The converted number with its associated unit of measure. Example:

uom = {
    Number: 5,
    UnitOfMeasure: {
        Value:"Liter",
        BaseConversion: 1,
        ControlSet: { Value: "Volume" }
    },
    IsMoney: false
};

targetUoM = "Milliliter";

returns

{
    Number: 5000,
    UnitOfMeasure: {
        Value: "Milliliter",
        BaseConversion: 0.001,
        ControlSet: {Value:"Volume"}
    },
    IsMoney:false
}
  • If the targetUoM is not found, NaN is returned as the converted value with an invalid UoM
  • If ConvertUoM_Quantity() is called with uom.IsMoney === true, an Error is thrown.
  • If the conversion ratio of the base or target unit of measure is less than or equal to zero, NaN is returned.
  • If the quantity value to convert is NaN, NaN is returned

ConvertUoM_Money(uom, tables, targetUoM)

Converts a money value from a given unit of measure to another unit of measure.

Unlike quantity, money values are only converted on a per unit cost basis. Let's assume we have a part named 'Bike' with quantity '24' each with an average selling price of '2 USD'. If we wanted to convert the quantity value (24) to Dozens, we would return 2 Dozens (2 dozen units is equal to 24 units). If we wanted to convert the money value (2USD) to Dozens we would return 24 USDs (1 dozen units is worth 24USD).

ArgumentTypeDescription
uomNumberUoMA money value with an associated unit of measure. Example { Number: 2, UnitOfMeasure: { Value:"Single", BaseConversion: 1, ControlSet: { Value:"Count" } }, IsMoney: true }. The example illustrates 2 units.
tablesTablesAll global tables. Currently this function only looks at the UnitOfMeasure table. A global dependency on the Mfg::UnitOfMeasure table and Core::ControlSet is required to use this library.
targetUoMstringThe target unit of measure to convert the uom into. First, uom.ItemSpecificUoM is searched (if present) and then tables.UnitOfMeasures is searched if no item-specific entry for the target is found.

Return value: The converted number with its associated unit of measure. Example:

uom = {
    Number: 2,
    UnitOfMeasure: {
        Value: "Single",
        BaseConversion: 1,
        ControlSet: { Value: "Count" }
    },
    IsMoney: true
};

targetUoM = "Dozen";

returns

{
    Number: 24,
    UnitOfMeasure: {
        Value: "Dozen",
        BaseConversion: 12,
        ControlSet: {Value: "Count"}
    },
    IsMoney: true
}
  • If the targetUoM is not found, NaN is returned as the converted value with an invalid UoM
  • If ConvertUoM_Money() is called with uom.IsMoney === false, an Error is thrown.
  • If the conversion ratio of the base or target unit of measure is less than or equal to zero, NaN is returned.
  • If the money value to convert is NaN, NaN is returned.

For more information on unit of measure, see: https://help.kinaxis.com/20162/GlobalHelp/Content/RR_Admin/Client_Administration/uom_create.htm.

Please contact support@kinaxis.com if you experience any issues.

Copyright © 2022 Kinaxis. All Rights Reserved.