All files / apps/api/src/assets/sampleData rules.ts

100% Statements 72/72
100% Branches 6/6
100% Functions 1/1
100% Lines 72/72

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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 731x 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 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { type Filter, type Rule, type Variable } from '@amalia/core/models';
import { RuleType } from '@amalia/payout-definition/plans/types';
 
export const makeSampleRules = (filters: Filter[], variables: Variable[]): Partial<Rule>[] => [
  {
    name: 'Commission on Payment',
    machineName: 'commissionOnPayment',
    formula: 'statement.totalPayout',
    type: RuleType.PAYOUT,
  },
  {
    name: 'Accelerator',
    machineName: 'accelerator',
    formula: 'statement.acceleratorRate * statement.totalClosed * statement.targetReach',
    type: RuleType.PAYOUT,
  },
  {
    name: 'Manager Commission Booking',
    machineName: 'managerCommissionBooking',
    formula: 'SUM(filter.statementsOfMyTeam, statementMetric.total)',
    type: RuleType.PAYOUT,
  },
  {
    name: 'Commission Booking',
    machineName: 'commissionBooking',
    formula: 'opportunity.payout',
    filter: filters.find(({ machineName }) => machineName === 'closedInPeriod'),
    type: RuleType.HOLD_AND_RELEASE,
    releaseConditionVariableId: variables.find(({ machineName }) => machineName === 'releaseCondition')!.id,
    commissionVariableId: variables.find(({ machineName }) => machineName === 'payout')!.id,
  },
  {
    name: 'Qualified Commission',
    machineName: 'qualifiedCommission',
    formula: 'statement.nbAboveTarget * 75',
    type: RuleType.PAYOUT,
  },
  {
    name: 'Team Commission',
    machineName: 'teamCommission',
    formula: 'IF(statement.teamTargetReach > 1, 1000, 0)',
    type: RuleType.PAYOUT,
  },
  {
    name: 'Commission Potential',
    machineName: 'commissionPotential',
    formula: 'statement.totalPotential',
    type: RuleType.NON_PAYOUT,
  },
  {
    name: 'Split Booking',
    machineName: 'splitBooking',
    formula: 'opportunity.splitPayout',
    filter: filters.find(({ machineName }) => machineName === 'splitInPeriod'),
    type: RuleType.PAYOUT,
  },
  {
    name: 'Decelerator',
    machineName: 'decelerator',
    formula: 'statement.deceleratorRate * statement.totalClosed * (1 - statement.targetReach)',
    type: RuleType.PAYOUT,
  },
  {
    name: 'Challenge Total Closed',
    machineName: 'challengeTotalClosed',
    formula: '',
    type: RuleType.CHALLENGE,
    configuration: {
      challengeComparisonVariableId: variables.find(({ machineName }) => machineName === 'totalClosed')!.id,
    },
  },
];