Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
import { type ComputeEngineResult } from '@amalia/payout-calculation/types';
import { AmaliaFunctionRawArgs } from '../../AmaliaFunction';
export const miscIf = new AmaliaFunctionRawArgs({
name: AmaliaFunctionKeys.IF,
category: AmaliaFunctionCategory.MISC,
nbParamsRequired: 3,
description: 'Return an argument if a condition is met, otherwise, return a different one',
generateComputedFunctionResult: (args) => ({
condition: args[0].toString() as AmaliaFormula,
}),
execMock: () => 1,
exec: (args, _, scope) => {
const conditionValue = args[0].compile().evaluate(scope) as ComputeEngineResult;
return conditionValue
? (args[1].compile().evaluate(scope) as ComputeEngineResult)
: (args[2].compile().evaluate(scope) as ComputeEngineResult);
},
params: [
{ name: 'condition', description: 'Boolean condition (returns 1 if true or 0 if false).' },
{ name: 'trueArgument', description: 'Argument to return if the condition is true.' },
{ name: 'falseArgument', description: 'Argument to return if the condition is false.' },
],
examples: [
{
desc: 'If the close date is after the start date of the period, returns amount, else returns 0.',
formula: 'IF(opportunity.closeDate >= statementPeriod.startDate, opportunity.amount, 0)' as AmaliaFormula,
},
{
desc: 'If statement.achievement / statement.target is greater than 1, returns accelerator, else returns 0.',
formula: 'IF(statement.achievement / statement.target > 1, statement.accelerator, 0)' as AmaliaFormula,
},
{
desc: 'If opportunity type if renewal or new business, returns amount, else returns amount * 0.5.',
formula:
'IF(opportunityType="Renewal" or opportunityType="New Business", opportunity.amount, opportunity.amount * 0.5)' as AmaliaFormula,
},
{
desc: 'If oppToLineItemLink exists, returns amount, else returns 0.',
formula: 'IF(opportunity.oppToLineItemLink, opportunity.oppToLineItemLink.amount, 0)' as AmaliaFormula,
},
],
});
|