68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import * as CRMTypes from '@/graphql/crm.types';
|
|
import type { ProcessContext } from '@/process/types';
|
|
import { reaction } from 'mobx';
|
|
import { formatter } from 'tools';
|
|
|
|
export default function reactions({ store, apolloClient }: ProcessContext) {
|
|
const { $calculation } = store;
|
|
|
|
reaction(
|
|
() => $calculation.element('radioCalcType').getValue(),
|
|
(calcType) => {
|
|
switch (calcType) {
|
|
case 100_000_001: {
|
|
$calculation.element('tbxIRR_Perc').block();
|
|
$calculation.element('tbxTotalPayments').unblock();
|
|
break;
|
|
}
|
|
case 100_000_000:
|
|
default: {
|
|
$calculation.element('tbxIRR_Perc').unblock();
|
|
$calculation.element('tbxTotalPayments').block();
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
fireImmediately: true,
|
|
}
|
|
);
|
|
|
|
reaction(
|
|
() => $calculation.$values.getValues(['product', 'tarif', 'bonusCoefficient']),
|
|
async ({ product: productId, tarif: tarifId, bonusCoefficient }) => {
|
|
let max = 0;
|
|
let min = 0;
|
|
|
|
if (productId && tarifId) {
|
|
const {
|
|
data: { evo_baseproduct },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetProductDocument,
|
|
variables: {
|
|
productId,
|
|
},
|
|
});
|
|
|
|
const {
|
|
data: { evo_tarif },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetTarifDocument,
|
|
variables: {
|
|
tarifId,
|
|
},
|
|
});
|
|
|
|
min = evo_tarif?.evo_min_irr ?? 0;
|
|
max = evo_tarif?.evo_max_irr ?? 0;
|
|
|
|
if (evo_baseproduct?.evo_cut_irr_with_bonus && bonusCoefficient < 1) {
|
|
min -= (1 - bonusCoefficient) * (evo_tarif?.evo_cut_irr_with_bonus_coefficient ?? 0);
|
|
}
|
|
}
|
|
|
|
$calculation.element('labelIrrInfo').setValue(`${formatter(min)}% - ${formatter(max)}%`);
|
|
}
|
|
);
|
|
}
|