From cdf2622969521024e33bd8928d81974490565821 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 15:56:50 +0300 Subject: [PATCH] effect for clientrisk --- .../CalculationStore/Effects/reaction.ts | 53 ++++++++++++++++++- src/core/fakeData/entityFakes.ts | 4 +- src/core/types/Entities/index.ts | 2 + 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 52cea24..a1bbbd7 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -10,7 +10,7 @@ const reactionEffects: IReactionEffect[] = [ }, effect: async leadId => { const lead = calculationStore.options.selectLead?.find( - x => x.value === leadId, + x => x.leadid === leadId, ); if (lead) { @@ -149,6 +149,57 @@ const reactionEffects: IReactionEffect[] = [ }, }), + calculationStore => ({ + expression: () => { + const { lead, opportunity } = calculationStore.values; + return { leadid: lead, opportunityid: opportunity }; + }, + effect: ({ leadid, opportunityid }) => { + if (opportunityid) { + const opportunity = calculationStore.options.selectOpportunity?.find( + x => x.opportunityid === opportunityid, + ); + if (opportunity) { + if (opportunity.evo_client_riskid) { + calculationStore.setValue( + 'clientRisk', + opportunity.evo_client_riskid, + ); + } else { + CalculationService.getEntityOptions({ + entityName: 'account', + where: { accountid: opportunity.evo_accountid }, + }).then(accounts => { + calculationStore.setValue( + 'clientRisk', + accounts[0].evo_client_riskid || null, + ); + }); + } + } + } else if (leadid && !opportunityid) { + const lead = calculationStore.options.selectLead?.find( + x => x.leadid === leadid, + ); + if (lead) { + if (lead.account) { + CalculationService.getEntityOptions({ + entityName: 'account', + where: { accountid: lead.account }, + }).then(accounts => { + calculationStore.setValue( + 'clientRisk', + accounts[0].evo_client_riskid || null, + ); + }); + } + } + } else { + calculationStore.setValue('clientRisk', null); + } + }, + }), + calculationStore => ({ expression: () => { const { channel } = calculationStore.values; diff --git a/src/core/fakeData/entityFakes.ts b/src/core/fakeData/entityFakes.ts index 9bcbdfd..9e78878 100644 --- a/src/core/fakeData/entityFakes.ts +++ b/src/core/fakeData/entityFakes.ts @@ -102,6 +102,7 @@ const entityFakeData: { evo_account_type: 100000005, evo_supplier_type: 100000000, statecode: 0, + evo_client_riskid: EVO_CLIENT_RISK_1_ID, }, { accountid: ACCOUNT_6_ID, @@ -192,8 +193,9 @@ const entityFakeData: { { fullname: '176_ООО "С финотделом', leadid: LEAD_3_ID, - evo_opportunityid: OPPORTUNITY_3_ID, + // evo_opportunityid: OPPORTUNITY_3_ID, evo_fin_department_accountid: ACCOUNT_5_ID, + account: ACCOUNT_5_ID, }, ], opportunity: [ diff --git a/src/core/types/Entities/index.ts b/src/core/types/Entities/index.ts index 7be4316..b2c854b 100644 --- a/src/core/types/Entities/index.ts +++ b/src/core/types/Entities/index.ts @@ -16,12 +16,14 @@ export interface ILead extends IBaseOption { leadid?: string; fullname?: string; evo_opportunityid?: string; + account?: string; } export interface IOpportunity extends IBaseOption { opportunityid?: string; evo_accountid?: string; evo_leadid?: string; + evo_client_riskid?: string; } export interface IQuote extends IBaseOption {