@kinaxis/unit-of-measure
v1.0.10
Published
Helper functions for applying unit of measure conversions.
Downloads
5
Readme
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.
|Property |Type |Description|
|--------------|--------|-----------|
|Value |string
|The 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.
|Property |Type |Description|
|--------------|------------|-----------|
|Value |string
|The name of the unit of measure.|
|BaseConversion|number
|The factor to use when converting from the base unit of measure.|
|ControlSet |ControlSet
|The 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.
|Property |Type |Description|
|-------------|---------------|-----------|
|UnitOfMeasure|UnitOfMeasure
|The unit of measure to override.|
|Factor |number
|The factor to use when converting from the base unit of measure.|
NumberUoM
A converted quantity with its associated unit of measure.
|Property |Type |Description|
|---------------|-----------------------------------------|-----------|
|Number |number
|The converted quantity.|
|UnitOfMeasure |UnitOfMeasure
|The unit of measure of Number
.|
|IsMoney |boolean
|Whether or not Number
is a money value.|
|ItemSpecificUoM|ItemSpecificUOMConversion[] | undefined
|Optional 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" }
}
|Argument |Type |Description|
|----------|------------|-----------|
|tables |Tables
|All 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.|
|uom |string
|A 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.|
|controlSet|ControlSet
|The 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.
|Argument |Type |Description|
|---------|-----------|-----------|
|uom |NumberUoM
|A 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.|
|tables |Tables
|All 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.|
|targetUoM|string
|The 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 withuom.IsMoney === true
, anError
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).
|Argument |Type |Description|
|---------|-----------|-----------|
|uom |NumberUoM
|A 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.|
|tables |Tables
|All 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.|
|targetUoM|string
|The 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 withuom.IsMoney === false
, anError
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 [email protected] if you experience any issues.
Copyright © 2022 Kinaxis. All Rights Reserved.