process/supplier-agents: add base supplier reactions

This commit is contained in:
Chika 2022-10-25 19:18:31 +03:00
parent 45e540fbfb
commit d9d49be4fe
3 changed files with 314 additions and 31 deletions

View File

@ -1,6 +1,5 @@
import { gql } from '@apollo/client';
/* eslint-disable import/prefer-default-export */
export const QUERY_GET_AGENT = gql`
query GetAgent($agentid: Uuid!) {
agent: account(accountid: $agentid) {
@ -9,3 +8,27 @@ export const QUERY_GET_AGENT = gql`
}
}
`;
export const QUERY_GET_REWARD_CONDITIONS = gql`
query GetRewardConditions($agentid: Uuid!, $currentDate: DateTime) {
evo_reward_conditions(
evo_agent_accountid: $agentid
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
statecode: 0
evo_agency_agreementid_param: { has: true }
) {
label: evo_name
value: evo_reward_conditionid
evo_reward_summ
}
}
`;
export const QUERY_GET_REWARD_SUMM = gql`
query GetRewardSumm($conditionId: Uuid!) {
evo_reward_condition(evo_reward_conditionid: $conditionId) {
evo_reward_summ
}
}
`;

View File

@ -1,9 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable implicit-arrow-linebreak */
import type { ApolloClient } from '@apollo/client';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import { normalizeOptions } from 'tools/entity';
import { makeDisposable } from 'tools/mobx';
import * as fillAgentsFromLead from '../lib/fill-agents-from-lead';
import * as query from '../lib/query';
dayjs.extend(utc);
export function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
const { $calculation, $process } = store;
@ -24,6 +32,282 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
),
() => $process.has('LoadKP')
);
// IndAgent
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectIndAgent'),
async (indAgentId) => {
if (!indAgentId) {
$calculation.resetElement('selectIndAgentRewardCondition');
return;
}
const {
data: { evo_reward_conditions },
} = await apolloClient.query<
CRMTypes.GetRewardConditionsQuery,
CRMTypes.GetRewardConditionsQueryVariables
>({
query: query.QUERY_GET_REWARD_CONDITIONS,
variables: {
agentid: indAgentId,
currentDate: dayjs().toISOString(),
},
});
if (evo_reward_conditions?.length) {
$calculation.setElementOptions(
'selectIndAgentRewardCondition',
normalizeOptions(evo_reward_conditions)
);
}
}
),
() => $process.has('LoadKP')
);
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectIndAgentRewardCondition'),
async (rewardConditionId) => {
if (!rewardConditionId) {
$calculation.resetElement('tbxIndAgentRewardSumm');
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardSummQuery,
CRMTypes.GetRewardSummQueryVariables
>({
query: query.QUERY_GET_REWARD_SUMM,
variables: {
conditionId: rewardConditionId,
},
});
$calculation.setElementValue(
'tbxIndAgentRewardSumm',
evo_reward_condition?.evo_reward_summ
);
$calculation.unblockElement('tbxIndAgentRewardSumm');
}
),
() => $process.has('LoadKP')
);
// CalcDoubleAgent
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectCalcDoubleAgent'),
async (calcDoubleAgentId) => {
if (!calcDoubleAgentId) {
$calculation.resetElement('selectCalcDoubleAgentRewardCondition');
return;
}
const {
data: { evo_reward_conditions },
} = await apolloClient.query<
CRMTypes.GetRewardConditionsQuery,
CRMTypes.GetRewardConditionsQueryVariables
>({
query: query.QUERY_GET_REWARD_CONDITIONS,
variables: {
agentid: calcDoubleAgentId,
currentDate: dayjs().toISOString(),
},
});
if (evo_reward_conditions?.length) {
$calculation.setElementOptions(
'selectCalcDoubleAgentRewardCondition',
normalizeOptions(evo_reward_conditions)
);
}
}
),
() => $process.has('LoadKP')
);
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectCalcDoubleAgentRewardCondition'),
async (rewardConditionId) => {
if (!rewardConditionId) {
$calculation.resetElement('tbxCalcDoubleAgentRewardSumm');
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardSummQuery,
CRMTypes.GetRewardSummQueryVariables
>({
query: query.QUERY_GET_REWARD_SUMM,
variables: {
conditionId: rewardConditionId,
},
});
$calculation.setElementValue(
'tbxCalcDoubleAgentRewardSumm',
evo_reward_condition?.evo_reward_summ
);
$calculation.unblockElement('tbxCalcDoubleAgentRewardSumm');
}
),
() => $process.has('LoadKP')
);
// CalcBroker
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectCalcBroker'),
async (calcBrokerId) => {
if (!calcBrokerId) {
$calculation.resetElement('selectCalcBrokerRewardCondition');
return;
}
const {
data: { evo_reward_conditions },
} = await apolloClient.query<
CRMTypes.GetRewardConditionsQuery,
CRMTypes.GetRewardConditionsQueryVariables
>({
query: query.QUERY_GET_REWARD_CONDITIONS,
variables: {
agentid: calcBrokerId,
currentDate: dayjs().toISOString(),
},
});
if (evo_reward_conditions?.length) {
$calculation.setElementOptions(
'selectCalcBrokerRewardCondition',
normalizeOptions(evo_reward_conditions)
);
}
}
),
() => $process.has('LoadKP')
);
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectCalcBrokerRewardCondition'),
async (rewardConditionId) => {
if (!rewardConditionId) {
$calculation.resetElement('tbxCalcBrokerRewardSum');
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardSummQuery,
CRMTypes.GetRewardSummQueryVariables
>({
query: query.QUERY_GET_REWARD_SUMM,
variables: {
conditionId: rewardConditionId,
},
});
$calculation.setElementValue(
'tbxCalcBrokerRewardSum',
evo_reward_condition?.evo_reward_summ
);
$calculation.unblockElement('tbxCalcBrokerRewardSum');
}
),
() => $process.has('LoadKP')
);
// CalcFinDepartment
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectCalcFinDepartment'),
async (calcFinDepartmentId) => {
if (!calcFinDepartmentId) {
$calculation.resetElement('selectFinDepartmentRewardCondtion');
return;
}
const {
data: { evo_reward_conditions },
} = await apolloClient.query<
CRMTypes.GetRewardConditionsQuery,
CRMTypes.GetRewardConditionsQueryVariables
>({
query: query.QUERY_GET_REWARD_CONDITIONS,
variables: {
agentid: calcFinDepartmentId,
currentDate: dayjs().toISOString(),
},
});
if (evo_reward_conditions?.length) {
$calculation.setElementOptions(
'selectFinDepartmentRewardCondtion',
normalizeOptions(evo_reward_conditions)
);
}
}
),
() => $process.has('LoadKP')
);
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectFinDepartmentRewardCondtion'),
async (rewardConditionId) => {
if (!rewardConditionId) {
$calculation.resetElement('tbxFinDepartmentRewardSumm');
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardSummQuery,
CRMTypes.GetRewardSummQueryVariables
>({
query: query.QUERY_GET_REWARD_SUMM,
variables: {
conditionId: rewardConditionId,
},
});
$calculation.setElementValue(
'tbxFinDepartmentRewardSumm',
evo_reward_condition?.evo_reward_summ
);
$calculation.unblockElement('tbxFinDepartmentRewardSumm');
}
),
() => $process.has('LoadKP')
);
}
export function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {}

View File

@ -9,7 +9,7 @@ import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import { normalizeOptions } from 'tools/entity';
import { makeDisposable } from 'tools/mobx';
import { QUERY_GET_AGENT } from '../lib/query';
import * as query from '../lib/query';
dayjs.extend(utc);
@ -102,7 +102,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
const {
data: { agent: dealerBroker },
} = await apolloClient.query<CRMTypes.GetAgentQuery, CRMTypes.GetAgentQueryVariables>({
query: QUERY_GET_AGENT,
query: query.QUERY_GET_AGENT,
variables: {
agentid: dealer?.evo_broker_accountid,
},
@ -127,22 +127,6 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
* Заполняем selectDealerRewardCondition
*/
const QUERY_GET_REWARD_CONDITIONS = gql`
query GetRewardConditions($agentid: Uuid!, $currentDate: DateTime) {
evo_reward_conditions(
evo_agent_accountid: $agentid
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
statecode: 0
evo_agency_agreementid_param: { has: true }
) {
label: evo_name
value: evo_reward_conditionid
evo_reward_summ
}
}
`;
makeDisposable(
() =>
reaction(
@ -159,7 +143,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
CRMTypes.GetRewardConditionsQuery,
CRMTypes.GetRewardConditionsQueryVariables
>({
query: QUERY_GET_REWARD_CONDITIONS,
query: query.QUERY_GET_REWARD_CONDITIONS,
variables: {
agentid: dealerPersonId,
currentDate: dayjs().toISOString(),
@ -177,14 +161,6 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
() => $process.has('LoadKP')
);
const QUERY_GET_REWARD_SUMM = gql`
query GetRewardSumm($conditionId: Uuid!) {
evo_reward_condition(evo_reward_conditionid: $conditionId) {
evo_reward_summ
}
}
`;
makeDisposable(
() =>
reaction(
@ -202,7 +178,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
CRMTypes.GetRewardSummQuery,
CRMTypes.GetRewardSummQueryVariables
>({
query: QUERY_GET_REWARD_SUMM,
query: query.QUERY_GET_REWARD_SUMM,
variables: {
conditionId: rewardConditionId,
},
@ -238,7 +214,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
CRMTypes.GetRewardConditionsQuery,
CRMTypes.GetRewardConditionsQueryVariables
>({
query: QUERY_GET_REWARD_CONDITIONS,
query: query.QUERY_GET_REWARD_CONDITIONS,
variables: {
agentid: dealerBrokerId,
currentDate: dayjs().toISOString(),
@ -273,7 +249,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
CRMTypes.GetRewardSummQuery,
CRMTypes.GetRewardSummQueryVariables
>({
query: QUERY_GET_REWARD_SUMM,
query: query.QUERY_GET_REWARD_SUMM,
variables: {
conditionId: rewardConditionId,
},