merge migration/fix/agents

This commit is contained in:
vchikalkin 2023-01-18 15:44:15 +03:00
parent fa3b6a2390
commit d6db50a582
7 changed files with 579 additions and 282 deletions

View File

@ -1,4 +1,3 @@
/* eslint-disable max-len */
/* eslint-disable no-case-declarations */ /* eslint-disable no-case-declarations */
import { counting, max, min, shift, sort } from 'radash'; import { counting, max, min, shift, sort } from 'radash';
@ -9,12 +8,13 @@ import { SEASONS_PERIODS, SEASONS_PERIOD_NUMBER } from './lib/seasons-constants'
export default function validatePaymentsTable({ $calculation, $tables }: RootStore) { export default function validatePaymentsTable({ $calculation, $tables }: RootStore) {
switch ($calculation.element('radioGraphType').getValue()) { switch ($calculation.element('radioGraphType').getValue()) {
// Дегрессия // Дегрессия
case 100_000_001: case 100_000_001: {
if (!$calculation.element('selectSeasonType').getValue()) { if (!$calculation.element('selectSeasonType').getValue()) {
return 'Не выбран тип дегрессии'; return 'Не выбран тип дегрессии';
} }
/** /**
* в таблице платежей в столбце Соотношение платежей для строк с 2 до "Срок лизинга-1" минимальное значение должно быть равно 3 * в таблице платежей в столбце Соотношение платежей
* для строк с 2 до "Срок лизинга-1" минимальное значение должно быть равно 3
*/ */
{ {
const MIN_PAYMENT = 3; const MIN_PAYMENT = 3;
@ -27,7 +27,8 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
} }
/** /**
* при Дегрессии все значения не должны быть равны друг другу + что при Легком старте 2,3 и 4 платежи не должны быть равны 100 * при Дегрессии все значения не должны быть равны друг другу
* + что при Легком старте 2,3 и 4 платежи не должны быть равны 100
*/ */
{ {
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue(); const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
@ -51,6 +52,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
} }
} }
} }
/* eslint-disable max-len */
/** /**
* Если вид графика = Дегрессия И значения в "Соотношении платежей" у 2, 3 и 4 платежа отличаются друг от друга не более чем на 10 * Если вид графика = Дегрессия И значения в "Соотношении платежей" у 2, 3 и 4 платежа отличаются друг от друга не более чем на 10
* (т.е. берем значения в этих полях, определяем максимальное и минимальное значение и смотрим на их разницу) * (т.е. берем значения в этих полях, определяем максимальное и минимальное значение и смотрим на их разницу)
@ -58,6 +60,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
* На 2-4 платежах Соотношение платежа должен отличаться не более чем на 10%", * На 2-4 платежах Соотношение платежа должен отличаться не более чем на 10%",
* иначе осуществлять расчет * иначе осуществлять расчет
*/ */
/* eslint-enable */
{ {
const targetPayments = $tables.payments.values.slice(1, 4); const targetPayments = $tables.payments.values.slice(1, 4);
@ -66,12 +69,14 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
} }
} }
/* eslint-disable max-len */
/** /**
* Если вид графика = Дегрессия И значения в "Соотношении платежей" для строк с 2 До "Срок лизинга-1" как минимум 2 раза по 2 платежа должны между собой быть равны * Если вид графика = Дегрессия И значения в "Соотношении платежей" для строк с 2 До "Срок лизинга-1" как минимум 2 раза по 2 платежа должны между собой быть равны
* (т.е. берем значения "Соотношения платежей" для строк с 2 до "Срок лизинга-1" и делаем сводную таблицу - если кол-во одинаковых значение больше 2 встречаются 2 и более раза), * (т.е. берем значения "Соотношения платежей" для строк с 2 до "Срок лизинга-1" и делаем сводную таблицу - если кол-во одинаковых значение больше 2 встречаются 2 и более раза),
* то осуществлять расчет, * то осуществлять расчет,
* иначе не осуществлять Расчет графика и выводить ошибку "Нельзя осуществить расчет - указана очень жетская дегрессия. Не менее чем у 4х платежей "Соотношение платежа" должно не отличаться между самой", * иначе не осуществлять Расчет графика и выводить ошибку "Нельзя осуществить расчет - указана очень жетская дегрессия. Не менее чем у 4х платежей "Соотношение платежа" должно не отличаться между самой",
*/ */
/* eslint-enable */
{ {
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue(); const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const targetPayments = $tables.payments.values.slice(1, leasingPeriod - 1); const targetPayments = $tables.payments.values.slice(1, leasingPeriod - 1);
@ -82,6 +87,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
} }
break; break;
}
case 100_000_003: { case 100_000_003: {
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue(); const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
@ -127,8 +133,9 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
break; break;
} }
default: default: {
return null; return null;
}
} }
return null; return null;

View File

@ -4,7 +4,7 @@ import { gql } from '@apollo/client';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc'; import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types'; import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx'; import { autorun, reaction } from 'mobx';
import type RootStore from 'stores/root'; import type RootStore from 'stores/root';
import ValidationHelper from 'stores/validation/helper'; import ValidationHelper from 'stores/validation/helper';
import { normalizeOptions } from 'tools/entity'; import { normalizeOptions } from 'tools/entity';
@ -65,6 +65,8 @@ export function fillAgentRewardReaction(
$calculation $calculation
.element(rewardConditionField) .element(rewardConditionField)
.setOptions(normalizeOptions(evo_reward_conditions)); .setOptions(normalizeOptions(evo_reward_conditions));
} else {
$calculation.element(rewardConditionField).reset();
} }
} }
); );
@ -125,10 +127,10 @@ export function fillAgentRewardSummReaction(
reaction( reaction(
() => $calculation.element(rewardConditionField).getValue(), () => $calculation.element(rewardConditionField).getValue(),
(rewardConditionId) => { (rewardConditionId) => {
if (!rewardConditionId) { if (rewardConditionId) {
$calculation.element(rewardSummField).block();
} else {
$calculation.element(rewardSummField).unblock(); $calculation.element(rewardSummField).unblock();
} else {
$calculation.element(rewardSummField).block();
} }
} }
); );
@ -228,18 +230,38 @@ export function validateAgentRewardSumm(
validationHelper.add(removeError); validationHelper.add(removeError);
}); });
} }
$calculation
.element(rewardSummField)
.validate({
invalid:
evo_reward_condition?.evo_agency_agreementidData?.evo_required_reward === true &&
rewardSumm === 0,
message: 'Согласно агентскому договору обязательна выплата АВ. Заложите АВ в расчет',
})
.err((removeError) => {
validationHelper.add(removeError);
});
} }
); );
autorun(() => {
const rewardSumm = $calculation.element(rewardSummField).getValue();
const rewardConditionOptions = $calculation.$options.getOptions(rewardConditionField);
const conditionIds = rewardConditionOptions.map((x) => x.value);
const requests = conditionIds.map(async (conditionId) => {
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardConditionQuery,
CRMTypes.GetRewardConditionQueryVariables
>({
query: QUERY_GET_REWARD_CONDITION,
variables: {
conditionId,
},
});
return evo_reward_condition;
});
Promise.all(requests).then((results) => {
const required_reward = results.some(
(x) => x?.evo_agency_agreementidData?.evo_required_reward === true
);
$calculation.element(rewardSummField).validate({
invalid: rewardSumm === 0 && required_reward,
message: 'Согласно агентскому договору обязательна выплата АВ. Заложите АВ в расчет',
});
});
});
} }

View File

@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const QUERY_GET_AGENT = gql` export const QUERY_GET_AGENT = gql`
@ -9,3 +8,11 @@ export const QUERY_GET_AGENT = gql`
} }
} }
`; `;
export const QUERY_GET_DEALER_RETURN_LEASING = gql`
query GetDealerReturnLeasing($dealerId: Uuid!) {
dealer: account(accountid: $dealerId) {
evo_return_leasing_dealer
}
}
`;

View File

@ -3,7 +3,7 @@ import { gql } from '@apollo/client';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc'; import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types'; import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx'; import { autorun, reaction } from 'mobx';
import type { ReactionsContext } from 'process/types'; import type { ReactionsContext } from 'process/types';
import { makeDisposable } from 'tools/mobx'; import { makeDisposable } from 'tools/mobx';
import * as createReactions from '../lib/create-reactions'; import * as createReactions from '../lib/create-reactions';
@ -92,6 +92,20 @@ export function fillReactions({ store, apolloClient }: ReactionsContext) {
}); });
} }
class Helper {
enabled: boolean;
/**
*
*/
constructor() {
this.enabled = false;
}
set = (value: boolean) => {
this.enabled = value;
};
}
export function commonReactions({ store, apolloClient }: ReactionsContext) { export function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store; const { $calculation } = store;
@ -119,47 +133,56 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
selectFinDepartment selectFinDepartment
*/ */
reaction( {
() => $calculation.element('selectDealerRewardCondition').getValue(), const helper = new Helper();
async (rewardConditionId) => { reaction(
function fillAgents() { () => $calculation.element('selectDealerRewardCondition').getValue(),
const leadid = $calculation.element('selectLead').getValue(); async (rewardConditionId) => {
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); function fillAgents() {
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
}
if (!rewardConditionId) {
if (helper.enabled === true) {
helper.set(false);
fillAgents();
}
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
helper.set(true);
$calculation.element('selectDealerBroker').resetValue();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
helper.set(false);
fillAgents();
}
} }
);
if (!rewardConditionId) { }
fillAgents();
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
fillAgents();
}
}
);
/** /**
* Добавить реакцию на изменение списка в поле selectDealerBrokerRewardCondition : * Добавить реакцию на изменение списка в поле selectDealerBrokerRewardCondition :
@ -181,48 +204,58 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
selectCalcBrokerRewardCondition заполняется значением из Интереса selectCalcBrokerRewardCondition заполняется значением из Интереса
selectFinDepartmentRewardCondtion заполняется значением из Интереса selectFinDepartmentRewardCondtion заполняется значением из Интереса
*/ */
reaction(
() => $calculation.element('selectDealerBrokerRewardCondition').getValue(), {
async (rewardConditionId) => { const helper = new Helper();
function fillAgents() { reaction(
const leadid = $calculation.element('selectLead').getValue(); () => $calculation.element('selectDealerBrokerRewardCondition').getValue(),
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); async (rewardConditionId) => {
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); function fillAgents() {
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
}
if (!rewardConditionId) {
if (helper.enabled === true) {
helper.set(false);
fillAgents();
}
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
helper.set(true);
$calculation.element('selectDealerPerson').block();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
helper.set(false);
$calculation.element('selectDealerPerson').unblock();
fillAgents();
}
} }
);
if (!rewardConditionId) { }
fillAgents();
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.element('selectDealerPerson').block();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.element('selectDealerPerson').unblock();
fillAgents();
}
}
);
/** /**
* Добавить реакцию на изменение списка в поле selectIndAgentRewardCondition : * Добавить реакцию на изменение списка в поле selectIndAgentRewardCondition :
@ -245,46 +278,56 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
selectCalcFinDepartment заполняется значением из Интереса selectCalcFinDepartment заполняется значением из Интереса
*/ */
reaction( {
() => $calculation.element('selectIndAgentRewardCondition').getValue(), const helper = new Helper();
async (rewardConditionId) => { reaction(
function fillAgents() { () => $calculation.element('selectIndAgentRewardCondition').getValue(),
const leadid = $calculation.element('selectLead').getValue(); async (rewardConditionId) => {
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); function fillAgents() {
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
}
if (!rewardConditionId) {
if (helper.enabled === true) {
helper.set(false);
fillAgents();
}
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
helper.set(true);
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').resetValue();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
helper.set(false);
$calculation.element('selectDealerPerson').unblock();
fillAgents();
}
} }
);
if (!rewardConditionId) { }
fillAgents();
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.element('selectDealerPerson').unblock();
fillAgents();
}
}
);
/** /**
* Добавить реакцию на изменение списка в поле selectCalcDoubleAgentRewardCondition : * Добавить реакцию на изменение списка в поле selectCalcDoubleAgentRewardCondition :
@ -308,48 +351,57 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
selectCalcFinDepartment заполняется значением из Интереса selectCalcFinDepartment заполняется значением из Интереса
*/ */
reaction( {
() => $calculation.element('selectCalcDoubleAgentRewardCondition').getValue(), const helper = new Helper();
async (rewardConditionId) => { reaction(
function fillAgents() { () => $calculation.element('selectCalcDoubleAgentRewardCondition').getValue(),
const leadid = $calculation.element('selectLead').getValue(); async (rewardConditionId) => {
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); function fillAgents() {
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
}
if (!rewardConditionId) {
if (helper.enabled === true) {
helper.set(false);
fillAgents();
}
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
helper.set(true);
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').resetValue();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
helper.set(false);
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
} }
);
if (!rewardConditionId) { }
fillAgents();
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
}
);
/** /**
* @description * @description
* Добавить реакцию на изменение списка в поле selectCalcBrokerRewardCondition: * Добавить реакцию на изменение списка в поле selectCalcBrokerRewardCondition:
@ -372,47 +424,57 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
selectCalcDoubleAgent заполняется значением из Интереса selectCalcDoubleAgent заполняется значением из Интереса
selectCalcFinDepartment заполняется значением из Интереса selectCalcFinDepartment заполняется значением из Интереса
*/ */
reaction( {
() => $calculation.element('selectCalcBrokerRewardCondition').getValue(), const helper = new Helper();
async (rewardConditionId) => { reaction(
function fillAgents() { () => $calculation.element('selectCalcBrokerRewardCondition').getValue(),
const leadid = $calculation.element('selectLead').getValue(); async (rewardConditionId) => {
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); function fillAgents() {
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
}
if (!rewardConditionId) {
if (helper.enabled === true) {
helper.set(false);
fillAgents();
}
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
helper.set(true);
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').resetValue();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
helper.set(false);
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
} }
);
if (!rewardConditionId) { }
fillAgents();
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
}
);
/** /**
* Добавить реакцию на изменение списка в поле selectFinDepartmentRewardCondtion: * Добавить реакцию на изменение списка в поле selectFinDepartmentRewardCondtion:
@ -436,50 +498,61 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
selectCalcBroker заполняется значением из Интереса selectCalcBroker заполняется значением из Интереса
*/ */
reaction( {
() => $calculation.element('selectFinDepartmentRewardCondtion').getValue(), const helper = new Helper();
async (rewardConditionId) => { reaction(
function fillAgents() { () => $calculation.element('selectFinDepartmentRewardCondtion').getValue(),
const leadid = $calculation.element('selectLead').getValue(); async (rewardConditionId) => {
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); function fillAgents() {
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
}
if (!rewardConditionId) {
if (helper.enabled === true) {
helper.set(false);
fillAgents();
}
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
helper.set(true);
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').resetValue();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
} else {
helper.set(false);
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
} }
);
if (!rewardConditionId) { }
fillAgents();
return;
}
const {
data: { evo_reward_condition },
} = await apolloClient.query<
CRMTypes.GetRewardWithoutOtherAgentQuery,
CRMTypes.GetRewardWithoutOtherAgentQueryVariables
>({
query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT,
variables: {
conditionId: rewardConditionId,
},
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
} else {
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
}
);
} }
export function validationReactions({ store, apolloClient }: ReactionsContext) { export function validationReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
createReactions.validateAgentRewardSumm(store, apolloClient, { createReactions.validateAgentRewardSumm(store, apolloClient, {
rewardConditionField: 'selectIndAgentRewardCondition', rewardConditionField: 'selectIndAgentRewardCondition',
rewardSummField: 'tbxIndAgentRewardSumm', rewardSummField: 'tbxIndAgentRewardSumm',
@ -499,4 +572,143 @@ export function validationReactions({ store, apolloClient }: ReactionsContext) {
rewardConditionField: 'selectFinDepartmentRewardCondtion', rewardConditionField: 'selectFinDepartmentRewardCondtion',
rewardSummField: 'tbxFinDepartmentRewardSumm', rewardSummField: 'tbxFinDepartmentRewardSumm',
}); });
/* eslint-disable max-len */
/** * Добавить валидацию на кнопку Рассчитать:
если tbxDealerRewardSumm > 0 и
если selectDealerPerson = selectDealerBroker и tbxDealerBrokerRewardSumm > 0, то ругаться на selectDealerPerson
если selectDealerPerson = selectIndAgent и tbxIndAgentRewardSumm > 0, то ругаться на selectDealerPerson
// eslint-disable-next-line max-len
если selectDealerPerson = selectCalcDoubleAgent и tbxCalcDoubleAgentRewardSumm > 0, то ругаться на selectDealerPerson
если selectDealerPerson = selectCalcBroker tbxCalcBrokerRewardSum > 0, то ругаться на selectDealerPerson
если selectDealerPerson = selectFinDepartment и tbxFinDepartmentRewardSumm > 0, то ругаться на selectDealerPerson
2.если tbxDealerBrokerRewardSumm > 0 и
если selectDealerBroker = selectDealerPerson и tbxDealerRewardSumm > 0, то ругаться на selectDealerBroker
если selectDealerBroker = selectIndAgent и tbxIndAgentRewardSumm > 0, то ругаться на selectDealerBroker
если selectDealerBroker = selectCalcDoubleAgent и tbxCalcDoubleAgentRewardSumm > 0, то ругаться на selectDealerBroker
если selectDealerBroker = selectCalcBroker tbxCalcBrokerRewardSum > 0, то ругаться на selectDealerBroker
если selectDealerBroker = selectFinDepartment и tbxFinDepartmentRewardSumm > 0, то ругаться на selectDealerBroker
3. если tbxIndAgentRewardSumm > 0 и
если selectIndAgent = selectDealerPerson и tbxDealerRewardSumm > 0, то ругаться на selectIndAgent
если selectIndAgent = selectDealerBroker и tbxDealerBrokerRewardSumm > 0, то ругаться на selectIndAgent
если selectIndAgent = selectCalcDoubleAgent и tbxCalcDoubleAgentRewardSumm > 0, то ругаться на selectIndAgent
если selectIndAgent = selectCalcBroker tbxCalcBrokerRewardSum > 0, то ругаться на selectIndAgent
если selectIndAgent = selectFinDepartment и tbxFinDepartmentRewardSumm > 0, то ругаться на selectIndAgent
4. если tbxCalcDoubleAgentRewardSumm > 0 и
если selectCalcDoubleAgent = selectDealerPerson и tbxDealerRewardSumm > 0, то ругаться на selectCalcDoubleAgent
если selectCalcDoubleAgent = selectDealerBroker и tbxDealerBrokerRewardSumm > 0, то ругаться на selectCalcDoubleAgent
если selectCalcDoubleAgent = sselectIndAgent и tbxIndAgentRewardSumm > 0, то ругаться на selectCalcDoubleAgent
если selectCalcDoubleAgent = selectCalcBroker tbxCalcBrokerRewardSum > 0, то ругаться на selectCalcDoubleAgent
если selectCalcDoubleAgent = selectFinDepartment и tbxFinDepartmentRewardSumm > 0, то ругаться на selectCalcDoubleAgent
5. если tbxCalcBrokerRewardSum > 0 и
если selectCalcBroker = selectDealerPerson и tbxDealerRewardSumm > 0, то ругаться на selectCalcBroker
если selectCalcBroker = selectDealerBroker и tbxDealerBrokerRewardSumm > 0, то ругаться на selectCalcBroker
если selectCalcBroker = sselectIndAgent и tbxIndAgentRewardSumm > 0, то ругаться на selectCalcBroker
если selectCalcBroker = selectCalcDoubleAgent и tbxCalcDoubleAgentRewardSumm > 0, то ругаться на selectCalcBroker
если selectCalcBroker = selectFinDepartment и tbxFinDepartmentRewardSumm > 0, то ругаться на selectCalcBroker
6. если tbxFinDepartmentRewardSumm > 0 и
если selectFinDepartment = selectDealerPerson и tbxDealerRewardSumm > 0, то ругаться на selectFinDepartment
если selectFinDepartment = selectDealerBroker и tbxDealerBrokerRewardSumm > 0, то ругаться на selectFinDepartment
если selectFinDepartment = sselectIndAgent и tbxIndAgentRewardSumm > 0, то ругаться на selectFinDepartment
если selectFinDepartment = selectCalcDoubleAgent и tbxCalcDoubleAgentRewardSumm > 0, то ругаться на selectFinDepartment
если selectFinDepartment = selectCalcBroker tbxCalcBrokerRewardSum > 0, то ругаться на selectFinDepartment
*/
/* eslint-enable */
autorun(() => {
const dealerRewardSumm = $calculation.element('tbxDealerRewardSumm').getValue();
const dealerBrokerRewardSumm = $calculation.element('tbxDealerBrokerRewardSumm').getValue();
const indAgentRewardSumm = $calculation.element('tbxIndAgentRewardSumm').getValue();
const calcDoubleAgentRewardSumm = $calculation
.element('tbxCalcDoubleAgentRewardSumm')
.getValue();
const calcBrokerRewardSum = $calculation.element('tbxCalcBrokerRewardSum').getValue();
const finDepartmentRewardSumm = $calculation.element('tbxFinDepartmentRewardSumm').getValue();
const dealerPerson = $calculation.element('selectDealerPerson').getValue();
const dealerBroker = $calculation.element('selectDealerBroker').getValue();
const indAgent = $calculation.element('selectIndAgent').getValue();
const calcDoubleAgent = $calculation.element('selectCalcDoubleAgent').getValue();
const calcBroker = $calculation.element('selectCalcBroker').getValue();
const calcFinDepartment = $calculation.element('selectCalcFinDepartment').getValue();
const message = 'Вы закладываете вознаграждение одному и тому же агенту дважды';
$calculation.element('selectDealerPerson').validate({
invalid:
dealerRewardSumm > 0 &&
!!dealerPerson &&
((dealerPerson === dealerBroker && dealerBrokerRewardSumm > 0) ||
(dealerPerson === indAgent && indAgentRewardSumm > 0) ||
(dealerPerson === calcDoubleAgent && calcDoubleAgentRewardSumm > 0) ||
(dealerPerson === calcBroker && calcBrokerRewardSum > 0) ||
(dealerPerson === calcFinDepartment && finDepartmentRewardSumm > 0)),
message,
});
$calculation.element('selectDealerBroker').validate({
invalid:
dealerBrokerRewardSumm > 0 &&
!!dealerBroker &&
((dealerBroker === dealerPerson && dealerRewardSumm > 0) ||
(dealerBroker === indAgent && indAgentRewardSumm > 0) ||
(dealerBroker === calcDoubleAgent && calcDoubleAgentRewardSumm > 0) ||
(dealerBroker === calcBroker && calcBrokerRewardSum > 0) ||
(dealerBroker === calcFinDepartment && finDepartmentRewardSumm > 0)),
message,
});
$calculation.element('selectIndAgent').validate({
invalid:
indAgentRewardSumm > 0 &&
!!indAgent &&
((indAgent === dealerPerson && dealerRewardSumm > 0) ||
(indAgent === dealerBroker && dealerBrokerRewardSumm > 0) ||
(indAgent === calcDoubleAgent && calcDoubleAgentRewardSumm > 0) ||
(indAgent === calcBroker && calcBrokerRewardSum > 0) ||
(indAgent === calcFinDepartment && finDepartmentRewardSumm > 0)),
message,
});
$calculation.element('selectCalcDoubleAgent').validate({
invalid:
calcDoubleAgentRewardSumm > 0 &&
!!calcDoubleAgent &&
((calcDoubleAgent === dealerPerson && dealerRewardSumm > 0) ||
(calcDoubleAgent === dealerBroker && dealerBrokerRewardSumm > 0) ||
(calcDoubleAgent === indAgent && indAgentRewardSumm > 0) ||
(calcDoubleAgent === calcBroker && calcBrokerRewardSum > 0) ||
(calcDoubleAgent === calcFinDepartment && finDepartmentRewardSumm > 0)),
message,
});
$calculation.element('selectCalcBroker').validate({
invalid:
calcBrokerRewardSum > 0 &&
!!calcBroker &&
((calcBroker === dealerPerson && dealerRewardSumm > 0) ||
(calcBroker === dealerBroker && dealerBrokerRewardSumm > 0) ||
(calcBroker === indAgent && indAgentRewardSumm > 0) ||
(calcBroker === calcDoubleAgent && calcDoubleAgentRewardSumm > 0) ||
(calcBroker === calcFinDepartment && finDepartmentRewardSumm > 0)),
message,
});
$calculation.element('selectCalcFinDepartment').validate({
invalid:
finDepartmentRewardSumm > 0 &&
!!calcFinDepartment &&
((calcFinDepartment === dealerPerson && dealerRewardSumm > 0) ||
(calcFinDepartment === dealerBroker && dealerBrokerRewardSumm > 0) ||
(calcFinDepartment === indAgent && indAgentRewardSumm > 0) ||
(calcFinDepartment === calcDoubleAgent && calcDoubleAgentRewardSumm > 0) ||
(calcFinDepartment === calcBroker && calcBrokerRewardSum > 0)),
message,
});
});
} }

View File

@ -1,7 +1,7 @@
import { gql } from '@apollo/client';
import type * as CRMTypes from 'graphql/crm.types'; import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx'; import { autorun, reaction } from 'mobx';
import type { ReactionsContext } from 'process/types'; import type { ReactionsContext } from 'process/types';
import * as query from '../lib/query';
export default function leasebackReactions({ store, apolloClient }: ReactionsContext) { export default function leasebackReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $tables } = store; const { $calculation, $tables } = store;
@ -20,14 +20,6 @@ export default function leasebackReactions({ store, apolloClient }: ReactionsCon
3) ПЛ БУ cbxLeaseObjectUsed = true 3) ПЛ БУ cbxLeaseObjectUsed = true
*/ */
const QUERY_GET_DEALER_RETURN_LEASING = gql`
query GetDealerReturnLeasing($dealerId: Uuid!) {
dealer: account(accountid: $dealerId) {
evo_return_leasing_dealer
}
}
`;
reaction( reaction(
() => $calculation.element('selectDealer').getValue(), () => $calculation.element('selectDealer').getValue(),
async (dealerId) => { async (dealerId) => {
@ -39,16 +31,18 @@ export default function leasebackReactions({ store, apolloClient }: ReactionsCon
CRMTypes.GetDealerReturnLeasingQuery, CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables CRMTypes.GetDealerReturnLeasingQueryVariables
>({ >({
query: QUERY_GET_DEALER_RETURN_LEASING, query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: { variables: {
dealerId, dealerId,
}, },
}); });
if (dealer?.evo_return_leasing_dealer === true) { if (dealer?.evo_return_leasing_dealer === true) {
$calculation.element('selectDealerPerson').block().resetValue();
$tables.insurance.row('kasko').setValue('insured', 100_000_000).block('insured'); $tables.insurance.row('kasko').setValue('insured', 100_000_000).block('insured');
$calculation.element('cbxLeaseObjectUsed').setValue(true); $calculation.element('cbxLeaseObjectUsed').setValue(true);
} else { } else {
$calculation.element('selectDealerPerson').unblock();
$tables.insurance.row('kasko').resetStatus('insured'); $tables.insurance.row('kasko').resetStatus('insured');
} }
} }
@ -71,7 +65,7 @@ export default function leasebackReactions({ store, apolloClient }: ReactionsCon
CRMTypes.GetDealerReturnLeasingQuery, CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables CRMTypes.GetDealerReturnLeasingQueryVariables
>({ >({
query: QUERY_GET_DEALER_RETURN_LEASING, query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: { variables: {
dealerId, dealerId,
}, },
@ -86,4 +80,42 @@ export default function leasebackReactions({ store, apolloClient }: ReactionsCon
} }
} }
); );
/* eslint-disable max-len */
/**
* В валидацию на кнопку Рассчитать внести изменение:
1) поле selectDealerPerson убрать из списка обязательных для расчета полей
2) добавить валидацию на поле selectDealerPerson :
Если в поле selectDealer указан account, у которого evo_return_leasing_dealer = False (или null)
и поле selectDealerPerson = null, то выводить ошибку и поле selectDealerPerson обводить красной рамкой,
иначе все ок
*/
/* eslint-enable */
autorun(async () => {
const dealerId = $calculation.element('selectDealer').getValue();
const dealerPersonId = $calculation.element('selectDealerPerson').getValue();
let returnLeasing: boolean | null | undefined;
if (dealerId) {
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
returnLeasing = dealer?.evo_return_leasing_dealer;
}
$calculation.element('selectDealerPerson').validate({
invalid: !!dealerId && !dealerPersonId && !returnLeasing,
message: 'Не заполнено поле',
});
});
} }

View File

@ -38,11 +38,26 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
async (dealerId) => { async (dealerId) => {
if (!dealerId) { if (!dealerId) {
$calculation.element('selectDealerPerson').reset(); $calculation.element('selectDealerPerson').reset();
$calculation.element('selectDealerBroker').reset();
return; return;
} }
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
if (dealer?.evo_return_leasing_dealer) {
return;
}
const { const {
data: { salon_providers }, data: { salon_providers },
} = await apolloClient.query< } = await apolloClient.query<
@ -91,6 +106,8 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
() => $calculation.element('selectDealerPerson').getValue(), () => $calculation.element('selectDealerPerson').getValue(),
async (dealerPersonId) => { async (dealerPersonId) => {
if (!dealerPersonId) { if (!dealerPersonId) {
$calculation.element('selectDealerBroker').reset();
return; return;
} }
@ -163,10 +180,10 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
); );
reaction( reaction(
() => $calculation.element('selectDealerBrokerRewardCondition').getValue(), () => $calculation.element('selectDealerBroker').getValue(),
(dealerBrokerRewardConditionId) => { (dealerBroker) => {
if (dealerBrokerRewardConditionId) { if (dealerBroker) {
$calculation.element('selectDealerPerson').resetValue(); $calculation.element('selectDealerRewardCondition').resetValue();
} }
} }
); );

View File

@ -2,5 +2,5 @@ import type { Elements, ElementsTypes } from 'Components/Calculation/config/map/
import type { BaseOption } from 'ui/elements/types'; import type { BaseOption } from 'ui/elements/types';
export type CalculationOptions = { export type CalculationOptions = {
[ElementName in Elements]: BaseOption<ElementsTypes[ElementName]>[]; [ElementName in Elements]: BaseOption<NonNullable<ElementsTypes[ElementName]>>[];
}; };