diff --git a/process/agents/lib/__generated__/GetDoubleAgent.ts b/process/agents/lib/__generated__/GetDoubleAgent.ts new file mode 100644 index 0000000..7fb5278 --- /dev/null +++ b/process/agents/lib/__generated__/GetDoubleAgent.ts @@ -0,0 +1,22 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetDoubleAgent +// ==================================================== + +export interface GetDoubleAgent_doubleAgent { + __typename: "account"; + label: string | null; + value: any | null; +} + +export interface GetDoubleAgent { + doubleAgent: GetDoubleAgent_doubleAgent | null; +} + +export interface GetDoubleAgentVariables { + evo_double_agent_accountid: any; +} diff --git a/process/agents/lib/__generated__/GetDoubleAgentAccountId.ts b/process/agents/lib/__generated__/GetDoubleAgentAccountId.ts new file mode 100644 index 0000000..95c9b76 --- /dev/null +++ b/process/agents/lib/__generated__/GetDoubleAgentAccountId.ts @@ -0,0 +1,24 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetDoubleAgentAccountId +// ==================================================== + +export interface GetDoubleAgentAccountId_lead { + __typename: "lead"; + evo_double_agent_accountid: any | null; +} + +export interface GetDoubleAgentAccountId { + /** + * Лизинговые сделки. statecode по умолчанию 0, можно отфильтровать по ownerid и/или domainName + */ + lead: GetDoubleAgentAccountId_lead | null; +} + +export interface GetDoubleAgentAccountIdVariables { + leadid: any; +} diff --git a/process/agents/lib/fill-agents-from-lead.ts b/process/agents/lib/fill-agents-from-lead.ts index a717ea8..d81cd4d 100644 --- a/process/agents/lib/fill-agents-from-lead.ts +++ b/process/agents/lib/fill-agents-from-lead.ts @@ -5,7 +5,15 @@ import type RootStore from 'stores/root'; import { normalizeOptions } from 'tools/entity'; import type { GetAgent } from './__generated__/GetAgent'; import type { GetAgentAccountId } from './__generated__/GetAgentAccountId'; +import type { GetDoubleAgent } from './__generated__/GetDoubleAgent'; +import type { GetDoubleAgentAccountId } from './__generated__/GetDoubleAgentAccountId'; +/** + * Если lead содержит данные, + * то indAgent заполняется ссылкой на карточку Контрагент (account), + * записанную в поле Интереса "Агент" (lead.evo_agent_accountid → account), + * иначе очищать поле калькулятора indAgent + */ const QUERY_GET_AGENT_ACCOUNTID = gql` query GetAgentAccountId($leadid: Uuid!) { lead(leadid: $leadid) { @@ -61,3 +69,68 @@ export async function fillIndAgent( $calculation.resetElement('selectIndAgent'); } } + +const QUERY_GET_DOUBLE_AGENT_ACCOUNTID = gql` + query GetDoubleAgentAccountId($leadid: Uuid!) { + lead(leadid: $leadid) { + evo_double_agent_accountid + } + } +`; + +const QUERY_GET_DOUBLE_AGENT = gql` + query GetDoubleAgent($evo_double_agent_accountid: Uuid!) { + doubleAgent: account(accountid: $evo_double_agent_accountid) { + label: name + value: accountid + } + } +`; + +/** + * Если lead содержит данные, + * то calcDoubleAgent заполняется ссылкой на карточку Контрагент (account), + * записанную в поле Интереса "Двойной агент" (lead.evo_double_agent_accountid → account) + * иначе очищать поле калькулятора calcDoubleAgent + */ +export async function fillCalcDoubleAgent( + { $calculation }: RootStore, + apolloClient: ApolloClient, + leadid: string | null +) { + if (!leadid) { + $calculation.resetElement('selectCalcDoubleAgent'); + + return; + } + + const { + data: { lead }, + } = await apolloClient.query({ + query: QUERY_GET_DOUBLE_AGENT_ACCOUNTID, + variables: { + leadid, + }, + }); + + if (lead?.evo_double_agent_accountid) { + const { + data: { doubleAgent }, + } = await apolloClient.query({ + query: QUERY_GET_DOUBLE_AGENT, + variables: { + evo_double_agent_accountid: lead.evo_double_agent_accountid, + }, + }); + + if (doubleAgent) { + $calculation.$options.setElementOptions( + 'selectCalcDoubleAgent', + normalizeOptions([doubleAgent]) + ); + $calculation.setElementValue('selectCalcDoubleAgent', doubleAgent.value); + } + } else { + $calculation.resetElement('selectCalcDoubleAgent'); + } +} diff --git a/process/agents/reactions/common.ts b/process/agents/reactions/common.ts index d968d48..0a81f5d 100644 --- a/process/agents/reactions/common.ts +++ b/process/agents/reactions/common.ts @@ -1,7 +1,7 @@ import type { ApolloClient } from '@apollo/client'; import { reaction } from 'mobx'; import type RootStore from 'stores/root'; -import { fillIndAgent } from '../lib/fill-agents-from-lead'; +import { fillCalcDoubleAgent, fillIndAgent } from '../lib/fill-agents-from-lead'; export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { const { $calculation } = store; @@ -9,6 +9,7 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl () => $calculation.getElementValue('selectLead'), (leadid) => { fillIndAgent(store, apolloClient, leadid); + fillCalcDoubleAgent(store, apolloClient, leadid); } ); }