From 7e5b126de8094120052a38fecd910a18d8a37038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A7=D0=B8=D0=BA=D0=B0=D0=BB=D0=BA=D0=B8=D0=BD?= Date: Thu, 24 Sep 2020 18:18:34 +0300 Subject: [PATCH] effect: indAgentRewardCondition=>calcDoubleAgent --- .../CalculationStore/Effects/reaction.ts | 68 +++++++++++++++++-- src/core/fakeData/entityFakes.ts | 1 + 2 files changed, 65 insertions(+), 4 deletions(-) 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,