diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 14824ce..5f390c8 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -187,10 +187,11 @@ const reactionEffects: IReactionEffect[] = [ entityName: 'account', where: { accountid: lead.account }, }).then(accounts => { - calculationStore.setValue( - 'clientRisk', - accounts[0].evo_client_riskid || null, - ); + if (accounts.length > 0) + calculationStore.setValue( + 'clientRisk', + accounts[0].evo_client_riskid || null, + ); }); } } @@ -414,6 +415,65 @@ const reactionEffects: IReactionEffect[] = [ }, }), + calculationStore => ({ + expression: () => { + const { indAgentRewardCondition } = calculationStore.values; + return indAgentRewardCondition; + }, + effect: indAgentRewardConditionId => { + if (!indAgentRewardConditionId) { + calculationStore.setValue('indAgentRewardSumm', null); + calculationStore.setStatus('tbxIndAgentRewardSumm', Status.Disabled); + + const leadId = calculationStore.values.lead; + if (leadId) { + const lead = calculationStore.options.selectLead?.find( + x => x.leadid === leadId, + ); + if (lead && !lead.evo_double_agent_accountid) { + calculationStore.setValue('calcDoubleAgent', null); + calculationStore.setStatus( + 'selectCalcDoubleAgent', + Status.Disabled, + ); + } + } + } else { + const indAgentRewardCondition = calculationStore.options.selectIndAgentRewardCondition?.find( + x => x.evo_reward_conditionid === indAgentRewardConditionId, + ); + if (indAgentRewardCondition) { + calculationStore.setValue( + 'indAgentRewardSumm', + indAgentRewardCondition.evo_reward_summ, + ); + calculationStore.setStatus('tbxIndAgentRewardSumm', Status.Default); + if (indAgentRewardCondition?.evo_double_agent_accountid) { + calculationStore.setStatus('selectCalcDoubleAgent', Status.Default); + const doubleAgent = calculationStore.options.selectDoubleAgent?.find( + x => + x.evo_agent_accountid === + indAgentRewardCondition?.evo_double_agent_accountid, + ); + if (doubleAgent) { + calculationStore.setOptions('selectDoubleAgent', [doubleAgent]); + calculationStore.setValue( + 'calcDoubleAgent', + doubleAgent.evo_double_agent_accountid, + ); + } + } else { + calculationStore.setValue('calcDoubleAgent', null); + calculationStore.setStatus( + 'selectCalcDoubleAgent', + Status.Disabled, + ); + } + } + } + }, + }), + calculationStore => ({ expression: () => { const { channel } = calculationStore.values; diff --git a/src/core/fakeData/entityFakes.ts b/src/core/fakeData/entityFakes.ts index 9d5f622..39670ee 100644 --- a/src/core/fakeData/entityFakes.ts +++ b/src/core/fakeData/entityFakes.ts @@ -345,6 +345,7 @@ const entityFakeData: { evo_reward_conditionid: REWARD_CONDITION_1_ID, evo_name: 'Не более 1.5%', evo_reward_summ: 1.5, + evo_double_agent_accountid: ACCOUNT_7_ID, }, { statecode: 0,