Creatio development guide
PDF
This documentation is valid for Creatio version 7.12.0. We recommend using the newest version of Creatio documentation.

The MoneyUtilsMixin mixin

Glossary Item Box

Introduction

The MoneyUtilsMixin mixin contains the general logic of cash transactions.

Methods

The getCurrencyDivision method

The getCurrencyDivision method is used to get the denomination (multiplicity) of a currency. Returns the denomination (multiplicity) of the currency. The type of returned value is “Number”.

NOTE

The denomination (multiplicity) of the currency is the amount of currency for which the calculation of the exchange rate will be made. For example: x1, x10, x100, etc.

Method format: this.getCurrencyDivision([config]);

Possible properties of the configuration object that are passed as a parameter are listed in Table 1.

Table 1. 1. Properties of the parameter object of the getCurrencyDivision method

Name Type Description Default values
config Object Object with additional parameter properties.
config.currencyAttribute (optional) String The name of the view model attribute containing the currency object. Currency
config.currencyDivisionProp (optional) Number The name of the currency object property containing the denomination (multiplicity) of the currency. If this property is specified it will be returned. Division
config.currencyDivision (optional) Number The value of the denomination (multiplicity) of the currency. If this property is specified it will be returned.

The recalculatePrimaryValue method

The recalculatePrimaryValue method calculates the value of the specified attribute in the base currency.

NOTE

“Base” currency is the currency that defines exchange rate for all other currencies. Base currency is defined in the [Base currency] system setting.

Method format: this.recalculatePrimaryValue(attribute [, config]);

Possible method parameters are listed in table 2.

Table 2. Parameters of the recalculatePrimaryValue method

Name Type Description Default values
attribute String The name of the view model attribute, for which the value in the base currency must be recalculated.
config (optional) Object Object with additional parameter properties. May include parameters for the getCurrencyDivision method.
config.modelInstance (optional) Terrasoft.BaseModel A view model for which the recalculation will be performed. this

config.primaryValueAttribute

(optional)

String The name of the attribute containing the value in the base currency. “Primary” + attribute
config.currencyRateAttribute (optional) String The name of the attribute containing the currency exchange rate value. CurrencyRate

The recalculateValue method

The recalculateValue method calculates the value of the specified attribute according to the base currency.

Method format: this.recalculateValue(attribute [, config]);

Possible method parameters are listed in table 3.

Table 3. Parameters of the recalculateValue method

Name Type Description
attribute String The name of the attribute, the value in the base currency must be recalculated for this attribute.
config (optional) Object Object with additional parameters. It can include parameters for the recalculatePrimaryValue method with parameters for the getCurrencyDivision method.

The getPercentage method

The getPercentage method calculates which percentage does a part of a total number make. Returns the percentage. The type of returned value is “Number”.

Method format: this.getPercentage(amount, part);

Possible method parameters are listed in table 4.

Table 4. Parameters of the getPercentage method

Name Type Description
amount Number Total number.
part Number Part of the total for which the percentage value must be calculated.

Use cases

// Returns 20.
this.getPercentage(10, 2); 
// Returns 100.
this.getPercentage(10, 10); 
// Returns 0.0001.
this.getPercentage(100, 0.0001); 

The getPercentagePart method

The getPercentagePart method calculates which number (“part”) makes the specified percentage from a total number. Returns the part of a number. The type of returned value is “Number”.

Method format: this.getPercentagePart(amount, percent);

Possible method parameters are listed in table 5.

Table 5. Parameters of the getPercentagePart method

Name Type Description
amount Number Total number.
percent Number Percentage.

Use cases

 // Returns 2.
this.getPercentagePart(10, 0.2);

The getIncludedPercentagePart method

The getIncludedPercentagePart method divides the total number into two parts. One of the parts is calculated as the percentage of the second part. Returns the part that was calculated as the percentage. The type of returned value is “Number”.

Method format: this.getIncludedPercentagePart(amount, percent);

Possible method parameters are listed in table 6.

Table 6. Parameters of the getIncludedPercentagePart method

Name Type Description
amount Number Total number.
percent Number Percentage.

Use cases

// Returns 1, because 1 is a 10% of 10, 10 + 1 = 11.
this.getIncludedPercentagePart(11, 10);

The roundMoney method

The roundMoney method rounds the value with the precision specified in the “Terrasoft.data.constants.MONEY_PRECISION”. Banking rounding is used. The type of returned value is “Number”.

Method format: this.roundMoney(amount);

Possible method parameters are listed in table 7.

Table 7. Parameters of the roundMoney method

Name Type Description
amount Number Total number.

Use cases

// If Terrasoft.data.constants.MONEY_PRECISION = 4 (by default):
// Returns 0.1235.
this.roundMoney(0.123456789);
// Returns 0.1234.
this.roundMoney(0.123449);

The roundValue method

The roundValue method rounds the value with the precision specified in the configuration object or in the “Terrasoft.data.constants.MONEY_PRECISION”. Banking rounding is used. The type of returned value is “Number”.

Method format: this.roundValue(amount [,config]);

Possible method parameters are listed in table 8.

Table 8. Parameters of the roundValue method

Name Type Description
amount Number Total number.
config (optional) Object Object with additional parameters.
config.targetColumnName (optional) String The name of the view model column for which the calculation is made. The precision of this column will be used. If the column does not have the precision property, then the precision from the “Terrasoft.data.constants.MONEY_PRECISION” will be used.
config.decimalPlaces (optional) Number Precision (number of decimals) for rounding the value.

Use cases

// Returns 0.12.
this.roundValue(0.123456789, {decimalPlaces: 2});
// If the "SomeColumnName" column has a property
//  precision = 4, Returns 0.1235.
this.roundValue(0.123456789, {targetColumnName: “SomeColumnName”});

The getMoneyCalculator method

The getMoneyCalculator method returns the DecimalUtils object that is configured with the “Terrasoft.data.constants.MONEY_PRECISION” precision. The type of returned value is “DecimalUtils”.

For more information about the DecimalUtils object, see the "The DecimalUtils module” article.

Method format: this.getMoneyCalculator();

Use cases

var calculator = this.getMoneyCalculator();
// Returns 3.
calculator.add(1, 2);
// Returns 0.3.
calculator.add(0.1, 0.2);

© bpm'online 2002-2019.

Did you find this information useful?

How can we improve it?