diff --git a/src/client/Containers/Calculation/index.jsx b/src/client/Containers/Calculation/index.jsx index dfc19e4..7a7017d 100644 --- a/src/client/Containers/Calculation/index.jsx +++ b/src/client/Containers/Calculation/index.jsx @@ -43,7 +43,6 @@ const Calculation = () => { { entities: staticEntities }, { entities: insuranceCompanies }, ]) => { - console.log(insuranceCompanies); calculationStore.applyOptions(initialOptions); calculationStore.applyStaticData(staticEntities); calculationStore.setTableColumns('tableInsurance')({ diff --git a/src/client/services/CalculationService.ts b/src/client/services/CalculationService.ts index c2d876e..69033bd 100644 --- a/src/client/services/CalculationService.ts +++ b/src/client/services/CalculationService.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import CalculationStore from 'client/stores/CalculationStore'; import { IGetEntitiesRequest } from 'core/types/Calculation/Requests'; import { IGetEntitiesResponse } from 'core/types/Calculation/Responses'; @@ -14,7 +15,8 @@ class CalculationService { resolve(res.data); }) .catch(err => { - reject(err); + CalculationStore.showModal(err); + // reject(err); }); }); } diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index ce33128..ec7dc2c 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -6,6 +6,7 @@ import { Status } from 'core/types/statuses'; import { ITableCell, TableProps } from 'core/types/Calculation/Store/tables'; import { toJS } from 'mobx'; import { calcPrice, calculatePerc, calculateRub } from './lib/tools'; +import { query } from 'express'; const reactionEffects: IReactionEffect[] = [ calculationStore => ({ @@ -21,2543 +22,2545 @@ const reactionEffects: IReactionEffect[] = [ const lead = calculationStore.options.selectLead?.find( x => x.leadid === leadId, ); + console.log( + 'calculationStore.options.selectLead', + calculationStore.options.selectLead, + ); if (lead) { - CalculationService.getEntityOptions({ - query: { - entityName: 'opportunity', - where: { opportunityid: lead.evo_opportunityid || null }, - }, - }) - .then(({ entityOptions: opportunities }) => { - if (opportunities) { - calculationStore.setOptions('selectOpportunity', opportunities); - calculationStore.setValue( - 'opportunity', - opportunities[0] ? opportunities[0].opportunityid : null, - ); - } - }) - .catch(err => { - throw err; - }); - - CalculationService.getEntityOptions({ - query: { - entityName: 'quote', - where: { - evo_leadid: leadId || null, + CalculationService.getEntities({ + queries: [ + { + entityName: 'opportunity', + where: { opportunityid: lead.evo_opportunityid }, + fields: ['opportunityid', 'name'], }, - }, - }) - .then(({ entityOptions: quotes }) => { - calculationStore.setOptions('selectQuote', quotes); - if (quotes.length === 0) calculationStore.setValue('quote', null); - }) - .catch(err => { - throw err; - }); - - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { - accountid: lead.evo_agent_accountid || null, + { + entityName: 'quote', + where: { evo_leadid: leadId }, + fields: ['quoteid', 'name', 'quotenumber'], + many: true, }, - }, - }) - .then(({ entityOptions: agents }) => { - calculationStore.setOptions('selectIndAgent', agents); - calculationStore.setValue( - 'indAgent', - agents[0] ? agents[0].accountid : null, - ); - }) - .catch(err => { - throw err; - }); - - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { - accountid: lead.evo_double_agent_accountid || null, + { + alias: 'agent', + entityName: 'account', + where: { accountid: lead.evo_agent_accountid }, + fields: ['accountid', 'name'], }, - }, - }) - .then(({ entityOptions: doubleAgents }) => { - calculationStore.setOptions('selectCalcDoubleAgent', doubleAgents); - calculationStore.setValue( - 'calcDoubleAgent', - doubleAgents[0] ? doubleAgents[0].accountid : null, - ); - }) - .catch(err => { - throw err; - }); - - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { - accountid: lead.evo_broker_accountid || null, + { + alias: 'double_agent', + entityName: 'account', + where: { accountid: lead.evo_double_agent_accountid }, + fields: ['accountid', 'name'], }, - }, - }) - .then(({ entityOptions: brokers }) => { - calculationStore.setOptions('selectCalcBroker', brokers); - calculationStore.setValue( - 'calcBroker', - brokers[0] ? brokers[0].accountid : null, - ); - }) - .catch(err => { - throw err; - }); - - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { - accountid: lead.evo_fin_department_accountid || null, + { + alias: 'broker', + entityName: 'account', + where: { accountid: lead.evo_broker_accountid }, + fields: ['accountid', 'name'], }, - }, - }) - .then(({ entityOptions: finDepartments }) => { - calculationStore.setOptions( - 'selectCalcFinDepartment', - finDepartments, - ); + { + alias: 'findepartment', + entityName: 'account', + where: { accountid: lead.evo_fin_department_accountid }, + fields: ['accountid', 'name'], + }, + ], + toOptions: true, + }).then(({ entities }) => { + if (entities.opportunity && !Array.isArray(entities.opportunity)) { + calculationStore.setOptions('selectOpportunity', [ + entities.opportunity, + ]); calculationStore.setValue( - 'calcFinDepartment', - finDepartments[0] ? finDepartments[0].accountid : null, + 'opportunity', + entities.opportunity.opportunityid, ); - }) - .catch(err => { - throw err; - }); - } - }, - }), + } - calculationStore => ({ - expression: () => { - const { options } = calculationStore; - return options.selectQuote; - }, - effect: quotes => { - if (quotes.length > 0) { - calculationStore.setStatus('tbxQuoteName', Status.Disabled); - } else { - calculationStore.setStatus('tbxQuoteName', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { opportunity } = calculationStore.values; - return opportunity; - }, - effect: opportunityId => { - const opportunity = calculationStore.options.selectOpportunity?.find( - x => x.opportunityid === opportunityId, - ); - - if (opportunity) { - calculationStore.setValue('lead', opportunity.evo_leadid); - } - }, - }), - - 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, - ); + if ( + entities.quote && + Array.isArray(entities.quote) && + entities.quote.length > 0 + ) { + calculationStore.setOptions('selectQuote', entities.quote); } else { - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { accountid: opportunity.evo_accountid }, - }, - }).then(({ entityOptions: accounts }) => { - if ( - accounts && - accounts.length > 0 && - accounts[0].evo_client_riskid - ) - calculationStore.setValue( - 'clientRisk', - accounts[0].evo_client_riskid || null, - ); - }); + calculationStore.setOptions('selectQuote', []); + calculationStore.setValue('quote', null); } - } - } else if (leadid && !opportunityid) { - const lead = calculationStore.options.selectLead?.find( - x => x.leadid === leadid, - ); - if (lead) { - if (lead.account) { - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { accountid: lead.account }, - }, - }).then(({ entityOptions: accounts }) => { - if (accounts.length > 0) - calculationStore.setValue( - 'clientRisk', - accounts[0].evo_client_riskid || null, - ); - }); + + if (entities.agent) { + if (!Array.isArray(entities.agent)) { + calculationStore.setOptions('selectIndAgent', [entities.agent]); + calculationStore.setValue('indAgent', entities.agent.accountid); + } + } else { + calculationStore.setValue('indAgent', null); } - } - } else { - calculationStore.setValue('clientRisk', null); - } - }, - }), - calculationStore => ({ - expression: () => { - const { agent } = calculationStore.values; - return agent; - }, - effect: agentid => { - if (!agentid) { - calculationStore.setStatus('selectDoubleAgent', Status.Disabled); - } else { - calculationStore.setStatus('selectDoubleAgent', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { channel } = calculationStore.values; - return channel; - }, - effect: channel => { - switch (channel) { - case 100000000: - calculationStore.setStatus('selectSupplier', Status.Default); - calculationStore.setStatus('selectAgent', Status.Default); - - calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); - - calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); - break; - - case 100000001: - calculationStore.setStatus('selectSupplier', Status.Default); - calculationStore.setStatus('selectAgent', Status.Default); - - calculationStore.setStatus('selectFinDepartment', Status.Default); - - calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); - break; - case 100000002: - calculationStore.setStatus('selectSupplier', Status.Disabled); - calculationStore.setValue('supplier', undefined); - - calculationStore.setStatus('selectAgent', Status.Default); - - calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); - - calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); - break; - case 100000003: - calculationStore.setStatus('selectSupplier', Status.Disabled); - calculationStore.setValue('supplier', undefined); - - calculationStore.setStatus('selectAgent', Status.Default); - calculationStore.setValue('agent', undefined); - - calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); - - calculationStore.setStatus('selectBroker', Status.Default); - break; - case 100000004: - default: - calculationStore.setStatus('selectSupplier', Status.Disabled); - calculationStore.setValue('supplier', undefined); - - calculationStore.setStatus('selectAgent', Status.Disabled); - calculationStore.setValue('agent', undefined); - - calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); - - calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); - break; - } - }, - }), - - calculationStore => ({ - expression: () => { - const { newClient } = calculationStore.values; - return newClient; - }, - effect: newClient => { - if (newClient && newClient.length > 0) { - calculationStore.setValue('account', null); - calculationStore.setValue('contactClient', null); - calculationStore.setStatus('selectAccount', Status.Disabled); - calculationStore.setStatus('selectContactClient', Status.Disabled); - } else { - calculationStore.setStatus('selectAccount', Status.Default); - calculationStore.setStatus('selectContactClient', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { account } = calculationStore.values; - return account; - }, - effect: account => { - if (account && account.length > 0) { - calculationStore.setStatus('tbxNewClient', Status.Disabled); - calculationStore.setValue('newClient', null); - } else { - calculationStore.setStatus('tbxNewClient', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { indAgent } = calculationStore.values; - return indAgent; - }, - effect: indAgentId => { - if (!indAgentId) { - calculationStore.setValue('indAgentRewardCondition', null); - calculationStore.setStatus( - 'selectIndAgentRewardCondition', - Status.Disabled, - ); - } else { - calculationStore.setValue('indAgentRewardCondition', null); - calculationStore.setStatus( - 'selectIndAgentRewardCondition', - Status.Default, - ); - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: indAgentId, - }, - }, - }) - .then(({ entityOptions: reward_conditions }) => { - calculationStore.setOptions( - 'selectIndAgentRewardCondition', - reward_conditions, - ); - }) - .catch(err => { - throw err; - }); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { calcDoubleAgent } = calculationStore.values; - return calcDoubleAgent; - }, - effect: doubleAgentId => { - if (!doubleAgentId) { - calculationStore.setValue('calcDoubleAgentRewardCondition', null); - calculationStore.setStatus( - 'selectCalcDoubleAgentRewardCondition', - Status.Disabled, - ); - } else { - calculationStore.setValue('calcDoubleAgentRewardCondition', null); - calculationStore.setStatus( - 'selectCalcDoubleAgentRewardCondition', - Status.Default, - ); - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: doubleAgentId, - }, - }, - }) - .then(({ entityOptions: reward_conditions }) => { - calculationStore.setOptions( - 'selectCalcDoubleAgentRewardCondition', - reward_conditions, - ); - }) - .catch(err => { - throw err; - }); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { calcFinDepartment } = calculationStore.values; - return calcFinDepartment; - }, - effect: calcFinDepartmentId => { - if (!calcFinDepartmentId) { - calculationStore.setValue('finDepartmentRewardCondtion', null); - calculationStore.setStatus( - 'selectFinDepartmentRewardCondtion', - Status.Disabled, - ); - } else { - calculationStore.setValue('finDepartmentRewardCondtion', null); - calculationStore.setStatus( - 'selectFinDepartmentRewardCondtion', - Status.Default, - ); - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: calcFinDepartmentId, - }, - }, - }) - .then(({ entityOptions: reward_conditions }) => { - calculationStore.setOptions( - 'selectFinDepartmentRewardCondtion', - reward_conditions, - ); - }) - .catch(err => { - throw err; - }); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { calcBroker } = calculationStore.values; - return calcBroker; - }, - effect: calcBrokerId => { - if (!calcBrokerId) { - calculationStore.setValue('calcBrokerRewardCondition', null); - calculationStore.setStatus( - 'selectCalcBrokerRewardCondition', - Status.Disabled, - ); - } else { - calculationStore.setValue('calcBrokerRewardCondition', null); - calculationStore.setStatus( - 'selectCalcBrokerRewardCondition', - Status.Default, - ); - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: calcBrokerId, - }, - }, - }) - .then(({ entityOptions: reward_conditions }) => { - calculationStore.setOptions( - 'selectCalcBrokerRewardCondition', - reward_conditions, - ); - }) - .catch(err => { - throw err; - }); - } - }, - }), - - 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]); + if (entities.double_agent) { + if (!Array.isArray(entities.double_agent)) { + calculationStore.setOptions('selectCalcDoubleAgent', [ + entities.double_agent, + ]); calculationStore.setValue( 'calcDoubleAgent', - doubleAgent.evo_double_agent_accountid, + entities.double_agent.accountid, ); } } else { calculationStore.setValue('calcDoubleAgent', null); - calculationStore.setStatus( - 'selectCalcDoubleAgent', - Status.Disabled, - ); } - } - } - }, - }), - calculationStore => ({ - expression: () => { - const { calcDoubleAgentRewardCondition } = calculationStore.values; - return calcDoubleAgentRewardCondition; - }, - effect: calcDoubleAgentRewardConditionId => { - if (!calcDoubleAgentRewardConditionId) { - calculationStore.setValue('calcDoubleAgentRewardSumm', 0); - calculationStore.setStatus( - 'tbxCalcDoubleAgentRewardSumm', - Status.Disabled, - ); - } else { - const calcDoubleAgentRewardCondition = calculationStore.options.selectCalcDoubleAgentRewardCondition?.find( - x => x.evo_reward_conditionid === calcDoubleAgentRewardConditionId, - ); - if (calcDoubleAgentRewardCondition) { - if (calcDoubleAgentRewardCondition.evo_reward_summ) { - calculationStore.setValue( - 'calcDoubleAgentRewardSumm', - calcDoubleAgentRewardCondition.evo_reward_summ, - ); - calculationStore.setStatus( - 'tbxCalcDoubleAgentRewardSumm', - Status.Default, - ); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { calcBrokerRewardCondition } = calculationStore.values; - return calcBrokerRewardCondition; - }, - effect: calcBrokerRewardConditionId => { - if (!calcBrokerRewardConditionId) { - calculationStore.setValue('calcBrokerRewardSum', 0); - calculationStore.setStatus('tbxCalcBrokerRewardSum', Status.Disabled); - } else { - const calcBrokerRewardCondition = calculationStore.options.selectCalcBrokerRewardCondition?.find( - x => x.evo_reward_conditionid === calcBrokerRewardConditionId, - ); - if (calcBrokerRewardCondition) { - if (calcBrokerRewardCondition.evo_reward_summ) { - calculationStore.setValue( - 'calcBrokerRewardSum', - calcBrokerRewardCondition.evo_reward_summ, - ); - calculationStore.setStatus( - 'tbxCalcBrokerRewardSum', - Status.Default, - ); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { finDepartmentRewardCondtion } = calculationStore.values; - return finDepartmentRewardCondtion; - }, - effect: finDepartmentRewardCondtionId => { - if (!finDepartmentRewardCondtionId) { - calculationStore.setValue('finDepartmentRewardSumm', 0); - calculationStore.setStatus( - 'tbxFinDepartmentRewardSumm', - Status.Disabled, - ); - } else { - const finDepartmentRewardCondtion = calculationStore.options.selectFinDepartmentRewardCondtion?.find( - x => x.evo_reward_conditionid === finDepartmentRewardCondtionId, - ); - if (finDepartmentRewardCondtion) { - if (finDepartmentRewardCondtion.evo_reward_summ) { - calculationStore.setValue( - 'finDepartmentRewardSumm', - finDepartmentRewardCondtion.evo_reward_summ, - ); - calculationStore.setStatus( - 'tbxFinDepartmentRewardSumm', - Status.Default, - ); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { indAgentRewardSumm } = calculationStore.values; - return indAgentRewardSumm; - }, - effect: indAgentRewardSumm => { - const indAgentRewardConditionId = - calculationStore.values.indAgentRewardCondition; - if (indAgentRewardConditionId) { - const indAgentRewardCondition = calculationStore.options.selectIndAgentRewardCondition?.find( - x => x.evo_reward_conditionid === indAgentRewardConditionId, - ); - if (indAgentRewardCondition) { - if (indAgentRewardCondition.evo_reward_summ) { - if ( - parseFloat(indAgentRewardSumm) > - indAgentRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation('tbxIndAgentRewardSumm', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение агента ФЛ указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } else if ( - !indAgentRewardCondition.evo_reduce_reward && - indAgentRewardCondition.evo_reward_summ - ) { - if ( - parseFloat(indAgentRewardSumm) < - indAgentRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation('tbxIndAgentRewardSumm', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение агента ФЛ указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } - } - calculationStore.setValidation('tbxIndAgentRewardSumm', true); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { calcDoubleAgentRewardSumm } = calculationStore.values; - return calcDoubleAgentRewardSumm; - }, - effect: calcDoubleAgentRewardSumm => { - const calcDoubleAgentRewardConditionId = - calculationStore.values.calcDoubleAgentRewardCondition; - if (calcDoubleAgentRewardConditionId) { - const selectCalcDoubleAgentRewardCondition = calculationStore.options.selectCalcDoubleAgentRewardCondition?.find( - x => x.evo_reward_conditionid === calcDoubleAgentRewardConditionId, - ); - if (selectCalcDoubleAgentRewardCondition) { - if (selectCalcDoubleAgentRewardCondition.evo_reward_summ) { - if ( - parseFloat(calcDoubleAgentRewardSumm) > - selectCalcDoubleAgentRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation( - 'tbxCalcDoubleAgentRewardSumm', - false, + if (entities.broker) { + if (!Array.isArray(entities.broker)) { + calculationStore.setOptions('selectCalcBroker', [ + entities.broker, + ]); + calculationStore.setValue( + 'calcBroker', + entities.broker.accountid, ); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение двойного агента указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } else if ( - !selectCalcDoubleAgentRewardCondition.evo_reduce_reward && - selectCalcDoubleAgentRewardCondition.evo_reward_summ - ) { - if ( - parseFloat(calcDoubleAgentRewardSumm) < - selectCalcDoubleAgentRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation( - 'tbxCalcDoubleAgentRewardSumm', - false, - ); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение двойного агента указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } } - calculationStore.setValidation( - 'tbxCalcDoubleAgentRewardSumm', - true, - ); + } else { + calculationStore.setValue('calcFinDepartment', null); } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { calcBrokerRewardSum } = calculationStore.values; - return calcBrokerRewardSum; - }, - effect: calcBrokerRewardSum => { - const calcBrokerRewardConditionId = - calculationStore.values.calcBrokerRewardCondition; - if (calcBrokerRewardConditionId) { - const selectCalcBrokerRewardCondition = calculationStore.options.selectCalcBrokerRewardCondition?.find( - x => x.evo_reward_conditionid === calcBrokerRewardConditionId, - ); - if (selectCalcBrokerRewardCondition) { - if (selectCalcBrokerRewardCondition.evo_reward_summ) { - if ( - parseFloat(calcBrokerRewardSum) > - selectCalcBrokerRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation('tbxCalcBrokerRewardSum', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение брокера указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } else if ( - !selectCalcBrokerRewardCondition.evo_reduce_reward && - selectCalcBrokerRewardCondition.evo_reward_summ - ) { - if ( - parseFloat(calcBrokerRewardSum) < - selectCalcBrokerRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation('tbxCalcBrokerRewardSum', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение брокера указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } - } - calculationStore.setValidation('tbxCalcBrokerRewardSum', true); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { finDepartmentRewardSumm } = calculationStore.values; - return finDepartmentRewardSumm; - }, - effect: finDepartmentRewardSumm => { - const finDepartmentRewardCondtionid = - calculationStore.values.finDepartmentRewardCondtion; - if (finDepartmentRewardCondtionid) { - const selectFinDepartmentRewardCondtion = calculationStore.options.selectFinDepartmentRewardCondtion?.find( - x => x.evo_reward_conditionid === finDepartmentRewardCondtionid, - ); - if (selectFinDepartmentRewardCondtion) { - if (selectFinDepartmentRewardCondtion.evo_reward_summ) { - if ( - parseFloat(finDepartmentRewardSumm) > - selectFinDepartmentRewardCondtion.evo_reward_summ - ) { - calculationStore.setValidation( - 'tbxFinDepartmentRewardSumm', - false, + if (entities.findepartment) { + if (!Array.isArray(entities.findepartment)) { + calculationStore.setOptions('selectCalcFinDepartment', [ + entities.findepartment, + ]); + calculationStore.setValue( + 'calcFinDepartment', + entities.findepartment.accountid, ); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение финотдела указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } else if ( - !selectFinDepartmentRewardCondtion.evo_reduce_reward && - selectFinDepartmentRewardCondtion.evo_reward_summ - ) { - if ( - parseFloat(finDepartmentRewardSumm) < - selectFinDepartmentRewardCondtion.evo_reward_summ - ) { - calculationStore.setValidation( - 'tbxFinDepartmentRewardSumm', - false, - ); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение финотдела указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } } - calculationStore.setValidation('tbxFinDepartmentRewardSumm', true); + } else { + calculationStore.setValue('calcFinDepartment', null); } - } + }); } }, }), - calculationStore => ({ - expression: () => { - const { leaseObjectUsed } = calculationStore.values; - return leaseObjectUsed; - }, - effect: leaseObjectUsed => { - if (leaseObjectUsed) { - calculationStore.setValue('leaseObjectCount', 1); - calculationStore.setStatus('tbxLeaseObjectCount', Status.Disabled); - } else { - calculationStore.setStatus('tbxLeaseObjectCount', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { insUnlimitDrivers } = calculationStore.values; - return insUnlimitDrivers; - }, - effect: insUnlimitDrivers => { - if (insUnlimitDrivers) { - calculationStore.setStatus('btnDriversApplication', Status.Disabled); - } else { - calculationStore.setStatus('btnDriversApplication', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { insFranchise } = calculationStore.values; - return insFranchise; - }, - effect: insFranchise => { - if (!insFranchise || parseInt(insFranchise) === 0) { - calculationStore.setStatus('btnFranschise', Status.Disabled); - } else { - calculationStore.setStatus('btnFranschise', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { lastPaymentRule } = calculationStore.values; - return lastPaymentRule; - }, - effect: lastPaymentRule => { - if (lastPaymentRule) { - if (lastPaymentRule === 100000000) { - calculationStore.setStatus('tbxLastPaymentPerc', Status.Disabled); - calculationStore.setStatus('tbxLastPaymentRub', Status.Default); - } else { - calculationStore.setStatus('tbxLastPaymentPerc', Status.Default); - calculationStore.setStatus('tbxLastPaymentRub', Status.Disabled); - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { lastPaymentPerc, balanceHolder } = calculationStore.values; - return { - lastPaymentPerc, - balanceHolder, - }; - }, - effect: ({ lastPaymentPerc, balanceHolder }) => { - if (balanceHolder && balanceHolder === 100000001) { - if (!lastPaymentPerc || parseFloat(lastPaymentPerc) < 1) { - calculationStore.setValidation('tbxLastPaymentPerc', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'При балансе лизингодатель последний платеж не может быть меньше 1%! Увеличьте значение.', - })(); - return; - } - } else { - if (parseFloat(lastPaymentPerc) === 0) { - calculationStore.setValidation('tbxLastPaymentPerc', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Последний платеж не может быть равен 0. Увеличьте значение', - })(); - return; - } - } - calculationStore.setValidation('tbxLastPaymentPerc', true); - }, - }), - - calculationStore => ({ - expression: () => { - const { graphType } = calculationStore.values; - return graphType; - }, - effect: graphType => { - if (graphType) { - switch (graphType) { - case 100000002: { - calculationStore.setStatus('radioSeasonType', Status.Disabled); - calculationStore.setStatus( - 'tbxParmentsDecreasePercent', - Status.Default, - ); - calculationStore.setStatus( - 'selectHighSeasonStart', - Status.Disabled, - ); - break; - } - - case 100000003: { - calculationStore.setStatus('radioSeasonType', Status.Default); - calculationStore.setStatus( - 'tbxParmentsDecreasePercent', - Status.Disabled, - ); - calculationStore.setStatus('selectHighSeasonStart', Status.Default); - break; - } - - default: { - calculationStore.setStatus('radioSeasonType', Status.Disabled); - calculationStore.setStatus( - 'tbxParmentsDecreasePercent', - Status.Disabled, - ); - calculationStore.setStatus( - 'selectHighSeasonStart', - Status.Disabled, - ); - break; - } - } - } - }, - options: { - fireImmediately: true, - }, - }), - - calculationStore => ({ - expression: () => { - const { seasonType } = calculationStore.values; - return seasonType; - }, - effect: seasonType => { - if (seasonType) { - switch (seasonType) { - case 100000001: - case 100000002: { - calculationStore.setFilter('selectHighSeasonStart', seasons => { - return seasons.filter( - season => season.value && season.value <= 100000004, - ); - }); - break; - } - default: - calculationStore.setFilter('selectHighSeasonStart', undefined); - break; - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { leasingPeriod } = calculationStore.values; - return leasingPeriod; - }, - effect: leasingPeriod => { - if (leasingPeriod) { - if (parseInt(leasingPeriod) < 12) { - calculationStore.setStatus('radioBalanceHolder', Status.Disabled); - calculationStore.setValue('balanceHolder', 100000000); - } else { - calculationStore.setStatus('radioBalanceHolder', Status.Default); - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { balanceHolder } = calculationStore.values; - return balanceHolder; - }, - effect: balanceHolder => { - if (balanceHolder) { - if (balanceHolder === 100000001) { - calculationStore.setStatus( - 'cbxLastPaymentRedemption', - Status.Disabled, - ); - calculationStore.setValue('lastPaymentRedemption', true); - } else { - calculationStore.setStatus( - 'cbxLastPaymentRedemption', - Status.Default, - ); - } - } - }, - }), - - // TODO: Fake fake - calculationStore => ({ - expression: () => { - const { dealer } = calculationStore.values; - return dealer; - }, - effect: dealerId => { - if (dealerId) { - const dealer = calculationStore.options.selectDealer?.find( - x => x.accountid === dealerId, - ); - if (dealer && dealer.evo_broker_accountid) { - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { - accountid: dealer.evo_broker_accountid, - }, - }, - }) - .then(({ entityOptions: brokers }) => { - if (brokers && brokers.length > 0) { - calculationStore.setOptions('selectDealerPerson', brokers); - calculationStore.setValue('dealerPerson', brokers[0].accountid); - calculationStore.setStatus( - 'selectDealerPerson', - Status.Default, - ); - } - }) - .catch(err => { - throw err; - }); - } - } - - calculationStore.setOptions('selectDealerPerson', []); - calculationStore.setValue('dealerPerson', null); - calculationStore.setStatus('selectDealerPerson', Status.Disabled); - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerPerson } = calculationStore.values; - return dealerPerson; - }, - effect: dealerPersonId => { - if (dealerPersonId) { - const dealerPerson = calculationStore.options.selectDealerPerson?.find( - x => x.accountid === dealerPersonId, - ); - if (dealerPerson && dealerPerson.evo_broker_accountid) { - CalculationService.getEntityOptions({ - query: { - entityName: 'account', - where: { - statecode: 0, - accountid: dealerPerson.evo_broker_accountid, - }, - }, - }) - .then(({ entityOptions: brokers }) => { - if (brokers && brokers.length > 0) { - calculationStore.setOptions('selectDealerBroker', brokers); - calculationStore.setValue('dealerBroker', brokers[0].accountid); - calculationStore.setStatus( - 'selectDealerBroker', - Status.Default, - ); - } - }) - .catch(err => { - throw err; - }); - } - } - - calculationStore.setOptions('selectDealerBroker', []); - calculationStore.setValue('dealerBroker', null); - calculationStore.setStatus('selectDealerBroker', Status.Disabled); - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerBroker } = calculationStore.values; - return dealerBroker; - }, - effect: dealerBrokerId => { - if (dealerBrokerId) { - const dealerBroker = calculationStore.options.selectDealerBroker?.find( - x => x.accountid === dealerBrokerId, - ); - if (dealerBroker) { - calculationStore.setStatus( - 'selectDealerBrokerRewardСondition', - Status.Default, - ); - - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: dealerBrokerId, - }, - }, - }) - .then(({ entityOptions: reward_conditions }) => { - calculationStore.setOptions( - 'selectDealerBrokerRewardСondition', - reward_conditions, - ); - }) - .catch(err => { - throw err; - }); - } - } else { - calculationStore.setValue('dealerBrokerRewardСondition', null); - calculationStore.setStatus( - 'selectDealerBrokerRewardСondition', - Status.Disabled, - ); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerBroker, dealerPerson } = calculationStore.values; - return [dealerBroker, dealerPerson]; - }, - effect: ([dealerBrokerId, dealerPersonId]) => { - if (dealerPersonId && !dealerBrokerId) { - calculationStore.setStatus( - 'selectDealerRewardСondition', - Status.Default, - ); - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: dealerPersonId, - }, - }, - }) - .then(({ entityOptions: reward_conditions }) => { - calculationStore.setOptions( - 'selectDealerRewardСondition', - reward_conditions, - ); - }) - .catch(err => { - throw err; - }); - } else { - calculationStore.setValue('dealerRewardСondition', null); - calculationStore.setStatus( - 'selectDealerRewardСondition', - Status.Disabled, - ); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerRewardСondition } = calculationStore.values; - return dealerRewardСondition; - }, - effect: dealerRewardСonditionId => { - if (!dealerRewardСonditionId) { - calculationStore.setValue('dealerRewardSumm', 0); - calculationStore.setStatus('tbxDealerRewardSumm', Status.Disabled); - } else { - const dealerRewardContition = calculationStore.options.selectDealerRewardСondition?.find( - x => x.evo_reward_conditionid === dealerRewardСonditionId, - ); - if (dealerRewardContition) { - if (dealerRewardContition.evo_reward_summ) { - calculationStore.setValue( - 'dealerRewardSumm', - dealerRewardContition.evo_reward_summ, - ); - calculationStore.setStatus('tbxDealerRewardSumm', Status.Default); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerBrokerRewardСondition } = calculationStore.values; - return dealerBrokerRewardСondition; - }, - effect: dealerBrokerRewardСonditionId => { - if (!dealerBrokerRewardСonditionId) { - calculationStore.setValue('dealerBrokerRewardSumm', 0); - calculationStore.setStatus( - 'tbxDealerBrokerRewardSumm', - Status.Disabled, - ); - } else { - const dealerBrokerRewardContition = calculationStore.options.selectDealerBrokerRewardСondition?.find( - x => x.evo_reward_conditionid === dealerBrokerRewardСonditionId, - ); - if (dealerBrokerRewardContition) { - if (dealerBrokerRewardContition.evo_reward_summ) { - calculationStore.setValue( - 'dealerBrokerRewardSumm', - dealerBrokerRewardContition.evo_reward_summ, - ); - calculationStore.setStatus( - 'tbxDealerBrokerRewardSumm', - Status.Default, - ); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerRewardSumm } = calculationStore.values; - return dealerRewardSumm; - }, - effect: dealerRewardSumm => { - const dealerRewardСonditionId = - calculationStore.values.dealerRewardСondition; - if (dealerRewardСonditionId) { - const dealerRewardCondition = calculationStore.options.selectDealerRewardСondition?.find( - x => x.evo_reward_conditionid === dealerRewardСonditionId, - ); - if (dealerRewardCondition) { - if (dealerRewardCondition.evo_reward_summ) { - if ( - parseFloat(dealerRewardSumm) > - dealerRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation('tbxDealerRewardSumm', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение ЮЛ поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } else if ( - !dealerRewardCondition.evo_reduce_reward && - dealerRewardCondition.evo_reward_summ - ) { - if ( - parseFloat(dealerRewardSumm) < - dealerRewardCondition.evo_reward_summ - ) { - calculationStore.setValidation('tbxDealerRewardSumm', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение ЮЛ поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } - } - calculationStore.setValidation('tbxDealerRewardSumm', true); - } - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { dealerBrokerRewardSumm } = calculationStore.values; - return dealerBrokerRewardSumm; - }, - effect: dealerBrokerRewardSumm => { - const dealerBrokerRewardСonditionId = - calculationStore.values.dealerBrokerRewardСondition; - if (dealerBrokerRewardСonditionId) { - const dealerBrokerRewardСondition = calculationStore.options.selectDealerBrokerRewardСondition?.find( - x => x.evo_reward_conditionid === dealerBrokerRewardСonditionId, - ); - if (dealerBrokerRewardСondition) { - if (dealerBrokerRewardСondition.evo_reward_summ) { - if ( - parseFloat(dealerBrokerRewardSumm) > - dealerBrokerRewardСondition.evo_reward_summ - ) { - calculationStore.setValidation( - 'tbxDealerBrokerRewardSumm', - false, - ); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение брокера поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } - } - if ( - !dealerBrokerRewardСondition.evo_reduce_reward && - dealerBrokerRewardСondition.evo_reward_summ - ) { - if ( - parseFloat(dealerBrokerRewardSumm) < - dealerBrokerRewardСondition.evo_reward_summ - ) { - calculationStore.setValidation( - 'tbxDealerBrokerRewardSumm', - false, - ); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Вознаграждение брокера поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); - return; - } - } - calculationStore.setValidation('tbxDealerBrokerRewardSumm', true); - } - } - }, - }), - - calculationStore => ({ - expression: () => { - const { brand } = calculationStore.values; - return brand; - }, - effect: brandId => { - if (brandId) { - const brand = calculationStore.options.selectBrand?.find( - x => x.evo_brandid === brandId, - ); - if (brand) { - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_model', - where: { - statecode: 0, - evo_brandid: brandId, - }, - }, - }).then(({ entityOptions: models }) => { - if (models && models.length > 0) { - calculationStore.setStatus('selectModel', Status.Default); - calculationStore.setOptions('selectModel', models); - calculationStore.setValue('model', null); - return; - } - }); - } - } - calculationStore.setStatus('selectModel', Status.Disabled); - calculationStore.setOptions('selectModel', []); - calculationStore.setValue('model', null); - }, - }), - - calculationStore => ({ - expression: () => { - const { model } = calculationStore.values; - return model; - }, - effect: modelId => { - if (modelId) { - const model = calculationStore.options.selectModel?.find( - x => x.evo_modelid === modelId, - ); - if (model) { - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_equipment', - where: { - statecode: 0, - evo_modelid: modelId, - }, - }, - }).then(({ entityOptions: equipments }) => { - if (equipments && equipments.length > 0) { - calculationStore.setStatus('selectConfiguration', Status.Default); - calculationStore.setOptions('selectConfiguration', equipments); - calculationStore.setValue('configuration', null); - return; - } - }); - } - } - calculationStore.setStatus('selectConfiguration', Status.Disabled); - calculationStore.setOptions('selectConfiguration', []); - calculationStore.setValue('configuration', null); - }, - }), - - calculationStore => ({ - expression: () => { - const { configuration } = calculationStore.values; - const { selectConfiguration } = calculationStore.options; - return [configuration, selectConfiguration]; - }, - effect: ([configurationId, selectConfigurationOptions]) => { - if (selectConfigurationOptions && selectConfigurationOptions.length) { - if (!configurationId) { - calculationStore.setValidation('selectConfiguration', false); - return; - } - } - calculationStore.setValidation('selectConfiguration', true); - }, - }), - - calculationStore => ({ - expression: () => { - const { model, configuration } = calculationStore.values; - return [model, configuration]; - }, - effect: ([modelId, configurationId]) => { - if (configurationId) { - const configuration = calculationStore.options.selectConfiguration?.find( - x => x.evo_equipmentid === configurationId, - ); - if (configuration) { - if (configuration.evo_impairment_groupid) { - const evo_impairment_groups = calculationStore.getStaticData( - 'evo_impairment_group', - ); - const evo_impairment_group = evo_impairment_groups.find( - x => - x.evo_impairment_groupid === - configuration.evo_impairment_groupid, - ); - calculationStore.setValue( - 'depreciationGroup', - evo_impairment_group ? evo_impairment_group.evo_name : '', - ); - return; - } - } - } - const model = calculationStore.options.selectModel?.find( - x => x.evo_modelid === modelId, - ); - if (model) - if (model.evo_impairment_groupid) { - const evo_impairment_groups = calculationStore.getStaticData( - 'evo_impairment_group', - ); - const evo_impairment_group = evo_impairment_groups.find( - x => x.evo_impairment_groupid === model.evo_impairment_groupid, - ); - calculationStore.setValue( - 'depreciationGroup', - evo_impairment_group ? evo_impairment_group.evo_name : '', - ); - return; - } - calculationStore.setValue('depreciationGroup', null); - }, - }), - - calculationStore => ({ - expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - supplierDiscountRub, - } = calculationStore.values; - return [supplierCurrency, leaseObjectPrice, supplierDiscountRub]; - }, - effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountRub]) => { - if (supplierDiscountRub === undefined) { - return; - } - calculatePerc(calculationStore)( - supplierCurrencyId, - leaseObjectPrice, - supplierDiscountRub, - 'supplierDiscountPerc', - ); - }, - }), - calculationStore => ({ - expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - supplierDiscountPerc, - } = calculationStore.values; - return [supplierCurrency, leaseObjectPrice, supplierDiscountPerc]; - }, - effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountPerc]) => { - if (supplierDiscountPerc === undefined) { - return; - } - calculateRub(calculationStore)( - supplierCurrencyId, - leaseObjectPrice, - supplierDiscountPerc, - 'supplierDiscountRub', - ); - }, - }), - - calculationStore => ({ - expression: () => { - const { firstPaymentRub } = calculationStore.values; - return firstPaymentRub; - }, - effect: firstPaymentRub => { - if (firstPaymentRub === undefined) { - return; - } - const { supplierCurrency, leaseObjectPrice } = calculationStore.values; - calculatePerc(calculationStore)( - supplierCurrency, - leaseObjectPrice, - firstPaymentRub, - 'firstPaymentPerc', - ); - }, - }), - calculationStore => ({ - expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - firstPaymentPerc, - } = calculationStore.values; - return [supplierCurrency, leaseObjectPrice, firstPaymentPerc]; - }, - effect: ([supplierCurrencyId, leaseObjectPrice, firstPaymentPerc]) => { - if (firstPaymentPerc === undefined) { - return; - } - calculateRub(calculationStore)( - supplierCurrencyId, - leaseObjectPrice, - firstPaymentPerc, - 'firstPaymentRub', - ); - }, - }), - - calculationStore => ({ - expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - comissionPerc, - } = calculationStore.values; - return [supplierCurrency, leaseObjectPrice, comissionPerc]; - }, - effect: ([supplierCurrencyId, leaseObjectPrice, comissionPerc]) => { - if (comissionPerc === undefined) { - return; - } - calculateRub(calculationStore)( - supplierCurrencyId, - leaseObjectPrice, - comissionPerc, - 'comissionRub', - ); - }, - }), - calculationStore => ({ - expression: () => { - const { comissionRub } = calculationStore.values; - return comissionRub; - }, - effect: comissionRub => { - if (comissionRub === undefined) { - return; - } - const { supplierCurrency, leaseObjectPrice } = calculationStore.values; - calculatePerc(calculationStore)( - supplierCurrency, - leaseObjectPrice, - comissionRub, - 'comissionPerc', - ); - }, - }), - - calculationStore => ({ - expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - lastPaymentPerc, - lastPaymentRule, - } = calculationStore.values; - return [ - supplierCurrency, - leaseObjectPrice, - lastPaymentPerc, - lastPaymentRule, - ]; - }, - effect: ([ - supplierCurrencyId, - leaseObjectPrice, - lastPaymentPerc, - lastPaymentRule, - ]) => { - if (lastPaymentPerc === undefined || lastPaymentRule !== 100000001) { - return; - } - calculateRub(calculationStore)( - supplierCurrencyId, - leaseObjectPrice, - lastPaymentPerc, - 'lastPaymentRub', - ); - }, - }), - calculationStore => ({ - expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - lastPaymentRub, - lastPaymentRule, - } = calculationStore.values; - return [ - supplierCurrency, - leaseObjectPrice, - lastPaymentRub, - lastPaymentRule, - ]; - }, - effect: ([ - supplierCurrencyId, - leaseObjectPrice, - lastPaymentRub, - lastPaymentRule, - ]) => { - if (lastPaymentRub === undefined || lastPaymentRule !== 100000000) { - return; - } - calculatePerc(calculationStore)( - supplierCurrencyId, - leaseObjectPrice, - lastPaymentRub, - 'lastPaymentPerc', - ); - }, - }), - - calculationStore => ({ - expression: () => { - const { - recalcWithRevision, - supplierCurrency, - supplierDiscountRub, - supplierDiscountPerc, - leaseObjectPrice, - } = calculationStore.values; - return [ - recalcWithRevision, - supplierCurrency, - supplierDiscountRub, - supplierDiscountPerc, - leaseObjectPrice, - ]; - }, - effect: ([ - recalcWithRevision, - supplierCurrencyId, - supplierDiscountRub, - supplierDiscountPerc, - leaseObjectPrice, - ]) => { - if (recalcWithRevision === true) { - return; - } - const supplierCurrency = calculationStore - .getOptions('selectSupplierCurrency') - .find(x => x.transactioncurrencyid === supplierCurrencyId); - const evo_currencychange = calculationStore - .getStaticData('evo_currencychange') - ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); - const evo_currencychangeValue = - (evo_currencychange && evo_currencychange.evo_currencychange) || 0; - let price = calcPrice( - supplierCurrency?.isocurrencycode, - leaseObjectPrice, - evo_currencychangeValue, - ); - - let maxPriceChange = - price - supplierDiscountRub < 800000 - ? price - supplierDiscountRub + 50000 - : (price - supplierDiscountRub) * 1.05; - - calculationStore.setValue('maxPriceChange', maxPriceChange); - }, - }), - - calculationStore => ({ - expression: () => { - const { recalcWithRevision } = calculationStore.values; - return recalcWithRevision; - }, - effect: recalcWithRevision => { - if (recalcWithRevision === true) { - calculationStore.setStatus('selectLead', Status.Disabled); - calculationStore.setStatus('selectOpportunity', Status.Disabled); - calculationStore.setStatus('selectQuote', Status.Disabled); - } else { - calculationStore.setStatus('selectLead', Status.Default); - calculationStore.setStatus('selectOpportunity', Status.Default); - calculationStore.setStatus('selectQuote', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { - supplierDiscountRub, - leaseObjectPrice, - supplierCurrency, - } = calculationStore.values; - return [supplierDiscountRub, leaseObjectPrice, supplierCurrency]; - }, - effect: ([supplierDiscountRub, leaseObjectPrice, supplierCurrencyId]) => { - const { recalcWithRevision, maxPriceChange } = calculationStore.values; - if (recalcWithRevision === false) { - return; - } - - const supplierCurrency = calculationStore - .getOptions('selectSupplierCurrency') - .find(x => x.transactioncurrencyid === supplierCurrencyId); - const evo_currencychange = calculationStore - .getStaticData('evo_currencychange') - ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); - const evo_currencychangeValue = - (evo_currencychange && evo_currencychange.evo_currencychange) || 0; - let price = calcPrice( - supplierCurrency?.isocurrencycode, - leaseObjectPrice, - evo_currencychangeValue, - ); - - if (price - supplierDiscountRub > maxPriceChange) { - calculationStore.setValidation('tbxLeaseObjectPrice', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра.' + - 'Уменьшите стоимость предмета лизинга', - })(); - } else { - calculationStore.setValidation('tbxLeaseObjectPrice', true); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { leaseObjectUsed } = calculationStore.values; - return leaseObjectUsed; - }, - effect: leaseObjectUsed => { - if (leaseObjectUsed === true) { - calculationStore.setValue('deliveryTime', 100000000); - calculationStore.setStatus('radioDeliveryTime', Status.Disabled); - } else { - calculationStore.setStatus('radioDeliveryTime', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { leaseObjectCategory } = calculationStore.values; - return leaseObjectCategory; - }, - effect: leaseObjectCategory => { - if ( - leaseObjectCategory === 100000001 || - leaseObjectCategory === 100000001 - ) { - calculationStore.setValue('withTrailer', null); - calculationStore.setStatus('selectWithTrailer', Status.Disabled); - } else { - calculationStore.setStatus('selectWithTrailer', Status.Default); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { quote } = calculationStore.values; - return quote; - }, - effect: quoteId => { - if (quoteId) { - const quote = calculationStore.options.selectQuote?.find( - x => x.quoteid === quoteId, - ); - if (quote) { - if (quote.evo_recalc_limit && quote.evo_recalc_limit > 0) { - if (quote.evo_statuscodeid) { - CalculationService.getEntityOptions({ - query: { - entityName: 'evo_statuscode', - where: { - evo_statuscodeid: quote.evo_statuscodeid, - statecode: 0, - }, - }, - }) - .then(({ entityOptions: evo_statuscodes }) => { - if (evo_statuscodes && evo_statuscodes.length > 0) { - const evo_statuscode = evo_statuscodes[0]; - if (evo_statuscode.evo_id === '2.3') { - calculationStore.setStatus( - 'cbxRecalcWithRevision', - Status.Default, - ); - return; - } - } - }) - .catch(err => { - throw err; - }); - } - } - } - } - calculationStore.setStatus('cbxRecalcWithRevision', Status.Disabled); - }, - }), - - calculationStore => ({ - expression: () => { - const { firstPaymentPerc } = calculationStore.values; - return firstPaymentPerc; - }, - effect: firstPaymentPerc => { - const { recalcWithRevision, quote: quoteId } = calculationStore.values; - if (recalcWithRevision) { - const quote = calculationStore.options.selectQuote?.find( - x => x.quoteid === quoteId, - ); - if (quote && quote.evo_approved_first_payment) { - if (firstPaymentPerc < quote.evo_approved_first_payment) { - calculationStore.setValidation('tbxFirstPaymentPerc', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения', - })(); - return; - } - } - } - calculationStore.setValidation('tbxFirstPaymentPerc', undefined); - }, - }), - - calculationStore => ({ - expression: () => { - const { brand, model, leaseObjectUsed } = calculationStore.values; - return [brand, model, leaseObjectUsed]; - }, - effect: ([brandId, modelId, leaseObjectUsed]) => { - if (leaseObjectUsed === false) { - const model = calculationStore.options.selectModel?.find( - x => x.evo_modelid === modelId, - ); - const brand = calculationStore.options.selectBrand?.find( - x => x.evo_brandid === brandId, - ); - - if ( - model && - model.evo_importer_reward_perc && - model.evo_importer_reward_perc > 0 - ) { - calculationStore.setValue( - 'importerRewardPerc', - model.evo_importer_reward_perc, - ); - return; - } - if ( - brand && - brand.evo_importer_reward_perc && - brand.evo_importer_reward_perc > 0 - ) { - calculationStore.setValue( - 'importerRewardPerc', - brand.evo_importer_reward_perc, - ); - return; - } - } - calculationStore.setValue('importerRewardPerc', 0); - }, - }), - - calculationStore => ({ - expression: () => { - const { brand, model, leaseObjectUsed } = calculationStore.values; - return [brand, model, leaseObjectUsed]; - }, - effect: ([brandId, modelId, leaseObjectUsed]) => { - if (leaseObjectUsed === false) { - const model = calculationStore.options.selectModel?.find( - x => x.evo_modelid === modelId, - ); - const brand = calculationStore.options.selectBrand?.find( - x => x.evo_brandid === brandId, - ); - - if ( - model && - model.evo_importer_reward_rub && - model.evo_importer_reward_rub > 0 - ) { - calculationStore.setValue( - 'importerRewardRub', - model.evo_importer_reward_rub, - ); - return; - } - if ( - brand && - brand.evo_importer_reward_rub && - brand.evo_importer_reward_rub > 0 - ) { - calculationStore.setValue( - 'importerRewardRub', - brand.evo_importer_reward_rub, - ); - return; - } - } - calculationStore.setValue('importerRewardRub', 0); - }, - }), - - calculationStore => ({ - expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - - const kaskoValues = calculationStore.getTableRowValues( - 'tableInsurance', - kaskoRowIndex, - 'value', - ); - - return { - ...kaskoValues, - }; - }, - effect: ({ insuranceCompany, insTerm, insured }) => { - if (insTerm) { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const dgoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ДГО', - ); - if (dgoRowIndex && dgoRowIndex >= 0) - calculationStore.setTableRows( - 'tableInsurance', - dgoRowIndex, - )([ - { - insuranceCompany: { - value: insuranceCompany, - }, - insTerm: { - value: insTerm, - }, - insured: { - value: insured, - }, - }, - { - insuranceCompany: { - value: insuranceCompany, - }, - insTerm: { - value: insTerm, - }, - insured: { - value: insured, - }, - }, - ]); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex(x => x.policyType === 'КАСКО'); - const kaskoRow = tableRows[kaskoRowIndex]; - const { leasingPeriod } = calculationStore.values; - if (kaskoRow) { - return { - insTerm: kaskoRow.insTerm?.value, - kaskoRowIndex, - leasingPeriod, - }; - } - }, - effect: ({ insTerm, kaskoRowIndex, leasingPeriod }) => { - if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { value: 100000001, status: Status.Disabled }, - }); - } else { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { status: Status.Default }, - }); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { leasingPeriod } = calculationStore.values; - return leasingPeriod; - }, - effect: leasingPeriod => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const osagoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ОСАГО', - ); - - if (leasingPeriod) { - if (leasingPeriod < 12) { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { value: 100000000, status: Status.Disabled }, - }); - if (osagoRowIndex >= 0) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, - )({ - insured: { value: 100000000, status: Status.Disabled }, - }); - } - } else { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { value: 100000000, status: Status.Default }, - }); - if (osagoRowIndex >= 0) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, - )({ - insured: { status: Status.Default }, - }); - } - } - - if (leasingPeriod < 13) { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insTerm: { value: 100000000, status: Status.Disabled }, - }); - return; - } else if (leasingPeriod > 12 && leasingPeriod < 16) { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insTerm: { value: 100000001, status: Status.Disabled }, - }); - return; - } else { - if (kaskoRowIndex >= 0) { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { status: Status.Default }, - insTerm: { status: Status.Default }, - }); - } - } - } - }, - options: { - fireImmediately: true, - }, - }), - - calculationStore => ({ - expression: () => { - const { graphType, leasingPeriod } = calculationStore.values; - return { graphType, leasingPeriod }; - }, - effect: ({ graphType, leasingPeriod }) => { - if (graphType === 100000003 && leasingPeriod < 14) { - calculationStore.setValue('leasingPeriod', 14); - openNotification({ - type: 'warning', - title: 'Внимание', - description: - 'При сезонном графике срок лизинга должен быть больше 14 месяцев', - })(); - } - }, - }), - - calculationStore => ({ - expression: () => { - const { - leasingPeriod, - graphType, - parmentsDecreasePercent, - seasonType, - highSeasonStart: highSeasonStartId, - firstPaymentPerc, - lastPaymentPerc, - } = calculationStore.values; - - const highSeasonStart = calculationStore.options.selectHighSeasonStart?.find( - x => x.value === highSeasonStartId, - ); - - return { - leasingPeriod, - graphType, - parmentsDecreasePercent, - seasonType, - highSeasonStart: parseInt(highSeasonStart?.name || '2'), - firstPaymentPerc, - lastPaymentPerc, - }; - }, - effect: async (nextParams, prevParams) => { - const { - leasingPeriod, - graphType, - parmentsDecreasePercent, - seasonType, - highSeasonStart, - firstPaymentPerc, - lastPaymentPerc, - } = nextParams; - - const prevValues = toJS(calculationStore.tables.tablePayments.rows).map( - x => x.paymentRelation?.value, - ); - let payments: TableProps[] = [ - { - paymentRelation: { - value: firstPaymentPerc, - status: Status.Disabled, - }, - }, - ]; - - calculationStore.cleanTable('tablePayments'); - - switch (graphType) { - case 100000000: { - const middleRows = Array.from({ length: leasingPeriod - 2 }, () => ({ - paymentRelation: { - value: 100, - status: Status.Disabled, - }, - })); - payments = [...payments, ...middleRows]; - - break; - } - - case 100000001: { - const middleRows = Array.from({ length: leasingPeriod - 3 }, () => ({ - paymentRelation: { - value: 100, - status: Status.Default, - }, - })); - payments = [ - ...payments, - { - paymentRelation: { - value: 100, - status: Status.Disabled, - }, - }, - ...middleRows, - ]; - - break; - } - - case 100000002: { - const middleRows = Array.from( - { length: leasingPeriod - 3 }, - (v, i) => ({ - paymentRelation: { - value: 100, - status: Status.Disabled, - }, - }), - ); - for (let i in middleRows) { - const currRow = middleRows[parseInt(i)]; - const prevRow = middleRows[parseInt(i) - 1]; - currRow.paymentRelation.value = parseFloat( - ( - ((prevRow ? prevRow.paymentRelation.value : 100) * - parmentsDecreasePercent) / - 100 - ).toFixed(2), - ); - } - payments = [ - ...payments, - { - paymentRelation: { - value: 100, - status: Status.Disabled, - }, - }, - ...middleRows, - ]; - - break; - } - - case 100000003: { - let HIGH = 100, - MIDDLE = 75, - LOW = 50; - - if ( - prevParams.graphType === nextParams.graphType - // && nextParams.graphType === 100000003 - ) { - /** - * FIND PREV HIGH, MIDDLE, LOW - */ - const { - leasingPeriod: prevLeasingPeriod, - seasonType: prevSeasonType, - highSeasonStart: prevHighSeasonStart, - } = prevParams; - - const prevPeriodsNumber = - prevLeasingPeriod <= 14 ? prevLeasingPeriod - 2 : 12; - const prevShiftNumber = prevHighSeasonStart - 2; - - let middleRows = prevValues.slice(1, prevPeriodsNumber + 1); - if (middleRows.length < 12) { - middleRows = [ - ...middleRows, - ...Array.from({ length: 12 - middleRows.length }, v => 0), - ]; - } - if (prevShiftNumber > 0) - middleRows = shiftRight(middleRows, prevShiftNumber); - - switch (prevSeasonType) { - // 6/6 - case 100000000: { - HIGH = middleRows[0]; - LOW = middleRows[6]; - break; - } - // 8/4 - case 100000001: { - HIGH = middleRows[0]; - LOW = middleRows[8]; - - break; - } - // 4/4/4 - case 100000002: { - HIGH = middleRows[0]; - MIDDLE = middleRows[4]; - LOW = middleRows[8]; - break; - } - } - /** */ - } - - /** - * GENERATE PERIODS - */ - - const { - leasingPeriod: nextLeasingPeriod, - seasonType: nextSeasonType, - highSeasonStart: nextHighSeasonStart, - } = nextParams; - - const nextPeriodsNumber = - nextLeasingPeriod <= 14 ? nextLeasingPeriod - 2 : 12; - const nextShiftNumber = nextHighSeasonStart - 2; - - let nextPeriods: number[] = []; - - switch (nextSeasonType) { - // 6/6 - case 100000000: { - nextPeriods = Array.from({ length: 12 }, (v, i) => - i < 6 ? HIGH : LOW, - ); - break; - } - // 8/4 - case 100000001: { - nextPeriods = Array.from({ length: 12 }, (v, i) => - i < 8 ? HIGH : LOW, - ); - break; - } - // 4/4/4 - case 100000002: { - nextPeriods = Array.from( - { length: 12 }, - (v, i) => (i < 4 && HIGH) || (i < 8 && MIDDLE) || LOW, - ); - break; - } - } - if (nextShiftNumber > 0) { - nextPeriods = shift(nextPeriods, nextShiftNumber); - } - nextPeriods.length = nextPeriodsNumber; - - const middleRows = Array.from( - { length: nextLeasingPeriod - 2 }, - (v, i) => { - return { - paymentRelation: { - value: - nextPeriods[ - i - nextPeriodsNumber * Math.floor(i / nextPeriodsNumber) - ], - status: - i < nextPeriodsNumber ? Status.Default : Status.Disabled, - }, - }; - }, - ); - - payments = [...payments, ...middleRows]; - - break; - } - - case 100000004: { - const middleRows = Array.from({ length: leasingPeriod - 5 }, () => ({ - paymentRelation: { - value: 100, - status: Status.Disabled, - }, - })); - - payments = [ - ...payments, - { - paymentRelation: { - value: 25, - status: Status.Default, - }, - }, - { - paymentRelation: { - value: 50, - status: Status.Default, - }, - }, - { - paymentRelation: { - value: 75, - status: Status.Default, - }, - }, - ...middleRows, - ]; - break; - } - - default: { - break; - } - } - - payments = [ - ...payments, - { - paymentRelation: { - value: lastPaymentPerc, - status: Status.Disabled, - }, - }, - ]; - - calculationStore.setTableRows('tablePayments', 0)(payments); - }, - options: { - fireImmediately: true, - }, - }), + // calculationStore => ({ + // expression: () => { + // const { options } = calculationStore; + // return options.selectQuote; + // }, + // effect: quotes => { + // if (quotes.length > 0) { + // calculationStore.setStatus('tbxQuoteName', Status.Disabled); + // } else { + // calculationStore.setStatus('tbxQuoteName', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { opportunity } = calculationStore.values; + // return opportunity; + // }, + // effect: opportunityId => { + // const opportunity = calculationStore.options.selectOpportunity?.find( + // x => x.opportunityid === opportunityId, + // ); + + // if (opportunity) { + // calculationStore.setValue('lead', opportunity.evo_leadid); + // } + // }, + // }), + + // 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({ + // query: { + // entityName: 'account', + // where: { accountid: opportunity.evo_accountid }, + // }, + // }).then(({ entityOptions: accounts }) => { + // if ( + // accounts && + // accounts.length > 0 && + // accounts[0].evo_client_riskid + // ) + // 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({ + // query: { + // entityName: 'account', + // where: { accountid: lead.account }, + // }, + // }).then(({ entityOptions: accounts }) => { + // if (accounts.length > 0) + // calculationStore.setValue( + // 'clientRisk', + // accounts[0].evo_client_riskid || null, + // ); + // }); + // } + // } + // } else { + // calculationStore.setValue('clientRisk', null); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { agent } = calculationStore.values; + // return agent; + // }, + // effect: agentid => { + // if (!agentid) { + // calculationStore.setStatus('selectDoubleAgent', Status.Disabled); + // } else { + // calculationStore.setStatus('selectDoubleAgent', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { channel } = calculationStore.values; + // return channel; + // }, + // effect: channel => { + // switch (channel) { + // case 100000000: + // calculationStore.setStatus('selectSupplier', Status.Default); + // calculationStore.setStatus('selectAgent', Status.Default); + + // calculationStore.setStatus('selectFinDepartment', Status.Disabled); + // calculationStore.setValue('finDepartment', undefined); + + // calculationStore.setStatus('selectBroker', Status.Disabled); + // calculationStore.setValue('broker', undefined); + // break; + + // case 100000001: + // calculationStore.setStatus('selectSupplier', Status.Default); + // calculationStore.setStatus('selectAgent', Status.Default); + + // calculationStore.setStatus('selectFinDepartment', Status.Default); + + // calculationStore.setStatus('selectBroker', Status.Disabled); + // calculationStore.setValue('broker', undefined); + // break; + // case 100000002: + // calculationStore.setStatus('selectSupplier', Status.Disabled); + // calculationStore.setValue('supplier', undefined); + + // calculationStore.setStatus('selectAgent', Status.Default); + + // calculationStore.setStatus('selectFinDepartment', Status.Disabled); + // calculationStore.setValue('finDepartment', undefined); + + // calculationStore.setStatus('selectBroker', Status.Disabled); + // calculationStore.setValue('broker', undefined); + // break; + // case 100000003: + // calculationStore.setStatus('selectSupplier', Status.Disabled); + // calculationStore.setValue('supplier', undefined); + + // calculationStore.setStatus('selectAgent', Status.Default); + // calculationStore.setValue('agent', undefined); + + // calculationStore.setStatus('selectFinDepartment', Status.Disabled); + // calculationStore.setValue('finDepartment', undefined); + + // calculationStore.setStatus('selectBroker', Status.Default); + // break; + // case 100000004: + // default: + // calculationStore.setStatus('selectSupplier', Status.Disabled); + // calculationStore.setValue('supplier', undefined); + + // calculationStore.setStatus('selectAgent', Status.Disabled); + // calculationStore.setValue('agent', undefined); + + // calculationStore.setStatus('selectFinDepartment', Status.Disabled); + // calculationStore.setValue('finDepartment', undefined); + + // calculationStore.setStatus('selectBroker', Status.Disabled); + // calculationStore.setValue('broker', undefined); + // break; + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { newClient } = calculationStore.values; + // return newClient; + // }, + // effect: newClient => { + // if (newClient && newClient.length > 0) { + // calculationStore.setValue('account', null); + // calculationStore.setValue('contactClient', null); + // calculationStore.setStatus('selectAccount', Status.Disabled); + // calculationStore.setStatus('selectContactClient', Status.Disabled); + // } else { + // calculationStore.setStatus('selectAccount', Status.Default); + // calculationStore.setStatus('selectContactClient', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { account } = calculationStore.values; + // return account; + // }, + // effect: account => { + // if (account && account.length > 0) { + // calculationStore.setStatus('tbxNewClient', Status.Disabled); + // calculationStore.setValue('newClient', null); + // } else { + // calculationStore.setStatus('tbxNewClient', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { indAgent } = calculationStore.values; + // return indAgent; + // }, + // effect: indAgentId => { + // if (!indAgentId) { + // calculationStore.setValue('indAgentRewardCondition', null); + // calculationStore.setStatus( + // 'selectIndAgentRewardCondition', + // Status.Disabled, + // ); + // } else { + // calculationStore.setValue('indAgentRewardCondition', null); + // calculationStore.setStatus( + // 'selectIndAgentRewardCondition', + // Status.Default, + // ); + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_reward_condition', + // where: { + // statecode: 0, + // // TODO < > текущей даты + // // evo_datefrom: new Date(), + // // evo_dateto: new Date(), + // evo_agent_accountid: indAgentId, + // }, + // }, + // }) + // .then(({ entityOptions: reward_conditions }) => { + // calculationStore.setOptions( + // 'selectIndAgentRewardCondition', + // reward_conditions, + // ); + // }) + // .catch(err => { + // throw err; + // }); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { calcDoubleAgent } = calculationStore.values; + // return calcDoubleAgent; + // }, + // effect: doubleAgentId => { + // if (!doubleAgentId) { + // calculationStore.setValue('calcDoubleAgentRewardCondition', null); + // calculationStore.setStatus( + // 'selectCalcDoubleAgentRewardCondition', + // Status.Disabled, + // ); + // } else { + // calculationStore.setValue('calcDoubleAgentRewardCondition', null); + // calculationStore.setStatus( + // 'selectCalcDoubleAgentRewardCondition', + // Status.Default, + // ); + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_reward_condition', + // where: { + // statecode: 0, + // // TODO < > текущей даты + // // evo_datefrom: new Date(), + // // evo_dateto: new Date(), + // evo_agent_accountid: doubleAgentId, + // }, + // }, + // }) + // .then(({ entityOptions: reward_conditions }) => { + // calculationStore.setOptions( + // 'selectCalcDoubleAgentRewardCondition', + // reward_conditions, + // ); + // }) + // .catch(err => { + // throw err; + // }); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { calcFinDepartment } = calculationStore.values; + // return calcFinDepartment; + // }, + // effect: calcFinDepartmentId => { + // if (!calcFinDepartmentId) { + // calculationStore.setValue('finDepartmentRewardCondtion', null); + // calculationStore.setStatus( + // 'selectFinDepartmentRewardCondtion', + // Status.Disabled, + // ); + // } else { + // calculationStore.setValue('finDepartmentRewardCondtion', null); + // calculationStore.setStatus( + // 'selectFinDepartmentRewardCondtion', + // Status.Default, + // ); + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_reward_condition', + // where: { + // statecode: 0, + // // TODO < > текущей даты + // // evo_datefrom: new Date(), + // // evo_dateto: new Date(), + // evo_agent_accountid: calcFinDepartmentId, + // }, + // }, + // }) + // .then(({ entityOptions: reward_conditions }) => { + // calculationStore.setOptions( + // 'selectFinDepartmentRewardCondtion', + // reward_conditions, + // ); + // }) + // .catch(err => { + // throw err; + // }); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { calcBroker } = calculationStore.values; + // return calcBroker; + // }, + // effect: calcBrokerId => { + // if (!calcBrokerId) { + // calculationStore.setValue('calcBrokerRewardCondition', null); + // calculationStore.setStatus( + // 'selectCalcBrokerRewardCondition', + // Status.Disabled, + // ); + // } else { + // calculationStore.setValue('calcBrokerRewardCondition', null); + // calculationStore.setStatus( + // 'selectCalcBrokerRewardCondition', + // Status.Default, + // ); + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_reward_condition', + // where: { + // statecode: 0, + // // TODO < > текущей даты + // // evo_datefrom: new Date(), + // // evo_dateto: new Date(), + // evo_agent_accountid: calcBrokerId, + // }, + // }, + // }) + // .then(({ entityOptions: reward_conditions }) => { + // calculationStore.setOptions( + // 'selectCalcBrokerRewardCondition', + // reward_conditions, + // ); + // }) + // .catch(err => { + // throw err; + // }); + // } + // }, + // }), + + // 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 { calcDoubleAgentRewardCondition } = calculationStore.values; + // return calcDoubleAgentRewardCondition; + // }, + // effect: calcDoubleAgentRewardConditionId => { + // if (!calcDoubleAgentRewardConditionId) { + // calculationStore.setValue('calcDoubleAgentRewardSumm', 0); + // calculationStore.setStatus( + // 'tbxCalcDoubleAgentRewardSumm', + // Status.Disabled, + // ); + // } else { + // const calcDoubleAgentRewardCondition = calculationStore.options.selectCalcDoubleAgentRewardCondition?.find( + // x => x.evo_reward_conditionid === calcDoubleAgentRewardConditionId, + // ); + // if (calcDoubleAgentRewardCondition) { + // if (calcDoubleAgentRewardCondition.evo_reward_summ) { + // calculationStore.setValue( + // 'calcDoubleAgentRewardSumm', + // calcDoubleAgentRewardCondition.evo_reward_summ, + // ); + // calculationStore.setStatus( + // 'tbxCalcDoubleAgentRewardSumm', + // Status.Default, + // ); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { calcBrokerRewardCondition } = calculationStore.values; + // return calcBrokerRewardCondition; + // }, + // effect: calcBrokerRewardConditionId => { + // if (!calcBrokerRewardConditionId) { + // calculationStore.setValue('calcBrokerRewardSum', 0); + // calculationStore.setStatus('tbxCalcBrokerRewardSum', Status.Disabled); + // } else { + // const calcBrokerRewardCondition = calculationStore.options.selectCalcBrokerRewardCondition?.find( + // x => x.evo_reward_conditionid === calcBrokerRewardConditionId, + // ); + // if (calcBrokerRewardCondition) { + // if (calcBrokerRewardCondition.evo_reward_summ) { + // calculationStore.setValue( + // 'calcBrokerRewardSum', + // calcBrokerRewardCondition.evo_reward_summ, + // ); + // calculationStore.setStatus( + // 'tbxCalcBrokerRewardSum', + // Status.Default, + // ); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { finDepartmentRewardCondtion } = calculationStore.values; + // return finDepartmentRewardCondtion; + // }, + // effect: finDepartmentRewardCondtionId => { + // if (!finDepartmentRewardCondtionId) { + // calculationStore.setValue('finDepartmentRewardSumm', 0); + // calculationStore.setStatus( + // 'tbxFinDepartmentRewardSumm', + // Status.Disabled, + // ); + // } else { + // const finDepartmentRewardCondtion = calculationStore.options.selectFinDepartmentRewardCondtion?.find( + // x => x.evo_reward_conditionid === finDepartmentRewardCondtionId, + // ); + // if (finDepartmentRewardCondtion) { + // if (finDepartmentRewardCondtion.evo_reward_summ) { + // calculationStore.setValue( + // 'finDepartmentRewardSumm', + // finDepartmentRewardCondtion.evo_reward_summ, + // ); + // calculationStore.setStatus( + // 'tbxFinDepartmentRewardSumm', + // Status.Default, + // ); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { indAgentRewardSumm } = calculationStore.values; + // return indAgentRewardSumm; + // }, + // effect: indAgentRewardSumm => { + // const indAgentRewardConditionId = + // calculationStore.values.indAgentRewardCondition; + // if (indAgentRewardConditionId) { + // const indAgentRewardCondition = calculationStore.options.selectIndAgentRewardCondition?.find( + // x => x.evo_reward_conditionid === indAgentRewardConditionId, + // ); + // if (indAgentRewardCondition) { + // if (indAgentRewardCondition.evo_reward_summ) { + // if ( + // parseFloat(indAgentRewardSumm) > + // indAgentRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation('tbxIndAgentRewardSumm', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение агента ФЛ указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } else if ( + // !indAgentRewardCondition.evo_reduce_reward && + // indAgentRewardCondition.evo_reward_summ + // ) { + // if ( + // parseFloat(indAgentRewardSumm) < + // indAgentRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation('tbxIndAgentRewardSumm', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение агента ФЛ указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // calculationStore.setValidation('tbxIndAgentRewardSumm', true); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { calcDoubleAgentRewardSumm } = calculationStore.values; + // return calcDoubleAgentRewardSumm; + // }, + // effect: calcDoubleAgentRewardSumm => { + // const calcDoubleAgentRewardConditionId = + // calculationStore.values.calcDoubleAgentRewardCondition; + // if (calcDoubleAgentRewardConditionId) { + // const selectCalcDoubleAgentRewardCondition = calculationStore.options.selectCalcDoubleAgentRewardCondition?.find( + // x => x.evo_reward_conditionid === calcDoubleAgentRewardConditionId, + // ); + // if (selectCalcDoubleAgentRewardCondition) { + // if (selectCalcDoubleAgentRewardCondition.evo_reward_summ) { + // if ( + // parseFloat(calcDoubleAgentRewardSumm) > + // selectCalcDoubleAgentRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation( + // 'tbxCalcDoubleAgentRewardSumm', + // false, + // ); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение двойного агента указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } else if ( + // !selectCalcDoubleAgentRewardCondition.evo_reduce_reward && + // selectCalcDoubleAgentRewardCondition.evo_reward_summ + // ) { + // if ( + // parseFloat(calcDoubleAgentRewardSumm) < + // selectCalcDoubleAgentRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation( + // 'tbxCalcDoubleAgentRewardSumm', + // false, + // ); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение двойного агента указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // calculationStore.setValidation( + // 'tbxCalcDoubleAgentRewardSumm', + // true, + // ); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { calcBrokerRewardSum } = calculationStore.values; + // return calcBrokerRewardSum; + // }, + // effect: calcBrokerRewardSum => { + // const calcBrokerRewardConditionId = + // calculationStore.values.calcBrokerRewardCondition; + // if (calcBrokerRewardConditionId) { + // const selectCalcBrokerRewardCondition = calculationStore.options.selectCalcBrokerRewardCondition?.find( + // x => x.evo_reward_conditionid === calcBrokerRewardConditionId, + // ); + // if (selectCalcBrokerRewardCondition) { + // if (selectCalcBrokerRewardCondition.evo_reward_summ) { + // if ( + // parseFloat(calcBrokerRewardSum) > + // selectCalcBrokerRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation('tbxCalcBrokerRewardSum', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение брокера указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } else if ( + // !selectCalcBrokerRewardCondition.evo_reduce_reward && + // selectCalcBrokerRewardCondition.evo_reward_summ + // ) { + // if ( + // parseFloat(calcBrokerRewardSum) < + // selectCalcBrokerRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation('tbxCalcBrokerRewardSum', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение брокера указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // calculationStore.setValidation('tbxCalcBrokerRewardSum', true); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { finDepartmentRewardSumm } = calculationStore.values; + // return finDepartmentRewardSumm; + // }, + // effect: finDepartmentRewardSumm => { + // const finDepartmentRewardCondtionid = + // calculationStore.values.finDepartmentRewardCondtion; + // if (finDepartmentRewardCondtionid) { + // const selectFinDepartmentRewardCondtion = calculationStore.options.selectFinDepartmentRewardCondtion?.find( + // x => x.evo_reward_conditionid === finDepartmentRewardCondtionid, + // ); + // if (selectFinDepartmentRewardCondtion) { + // if (selectFinDepartmentRewardCondtion.evo_reward_summ) { + // if ( + // parseFloat(finDepartmentRewardSumm) > + // selectFinDepartmentRewardCondtion.evo_reward_summ + // ) { + // calculationStore.setValidation( + // 'tbxFinDepartmentRewardSumm', + // false, + // ); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение финотдела указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } else if ( + // !selectFinDepartmentRewardCondtion.evo_reduce_reward && + // selectFinDepartmentRewardCondtion.evo_reward_summ + // ) { + // if ( + // parseFloat(finDepartmentRewardSumm) < + // selectFinDepartmentRewardCondtion.evo_reward_summ + // ) { + // calculationStore.setValidation( + // 'tbxFinDepartmentRewardSumm', + // false, + // ); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение финотдела указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // calculationStore.setValidation('tbxFinDepartmentRewardSumm', true); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { leaseObjectUsed } = calculationStore.values; + // return leaseObjectUsed; + // }, + // effect: leaseObjectUsed => { + // if (leaseObjectUsed) { + // calculationStore.setValue('leaseObjectCount', 1); + // calculationStore.setStatus('tbxLeaseObjectCount', Status.Disabled); + // } else { + // calculationStore.setStatus('tbxLeaseObjectCount', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { insUnlimitDrivers } = calculationStore.values; + // return insUnlimitDrivers; + // }, + // effect: insUnlimitDrivers => { + // if (insUnlimitDrivers) { + // calculationStore.setStatus('btnDriversApplication', Status.Disabled); + // } else { + // calculationStore.setStatus('btnDriversApplication', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { insFranchise } = calculationStore.values; + // return insFranchise; + // }, + // effect: insFranchise => { + // if (!insFranchise || parseInt(insFranchise) === 0) { + // calculationStore.setStatus('btnFranschise', Status.Disabled); + // } else { + // calculationStore.setStatus('btnFranschise', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { lastPaymentRule } = calculationStore.values; + // return lastPaymentRule; + // }, + // effect: lastPaymentRule => { + // if (lastPaymentRule) { + // if (lastPaymentRule === 100000000) { + // calculationStore.setStatus('tbxLastPaymentPerc', Status.Disabled); + // calculationStore.setStatus('tbxLastPaymentRub', Status.Default); + // } else { + // calculationStore.setStatus('tbxLastPaymentPerc', Status.Default); + // calculationStore.setStatus('tbxLastPaymentRub', Status.Disabled); + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { lastPaymentPerc, balanceHolder } = calculationStore.values; + // return { + // lastPaymentPerc, + // balanceHolder, + // }; + // }, + // effect: ({ lastPaymentPerc, balanceHolder }) => { + // if (balanceHolder && balanceHolder === 100000001) { + // if (!lastPaymentPerc || parseFloat(lastPaymentPerc) < 1) { + // calculationStore.setValidation('tbxLastPaymentPerc', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'При балансе лизингодатель последний платеж не может быть меньше 1%! Увеличьте значение.', + // })(); + // return; + // } + // } else { + // if (parseFloat(lastPaymentPerc) === 0) { + // calculationStore.setValidation('tbxLastPaymentPerc', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Последний платеж не может быть равен 0. Увеличьте значение', + // })(); + // return; + // } + // } + // calculationStore.setValidation('tbxLastPaymentPerc', true); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { graphType } = calculationStore.values; + // return graphType; + // }, + // effect: graphType => { + // if (graphType) { + // switch (graphType) { + // case 100000002: { + // calculationStore.setStatus('radioSeasonType', Status.Disabled); + // calculationStore.setStatus( + // 'tbxParmentsDecreasePercent', + // Status.Default, + // ); + // calculationStore.setStatus( + // 'selectHighSeasonStart', + // Status.Disabled, + // ); + // break; + // } + + // case 100000003: { + // calculationStore.setStatus('radioSeasonType', Status.Default); + // calculationStore.setStatus( + // 'tbxParmentsDecreasePercent', + // Status.Disabled, + // ); + // calculationStore.setStatus('selectHighSeasonStart', Status.Default); + // break; + // } + + // default: { + // calculationStore.setStatus('radioSeasonType', Status.Disabled); + // calculationStore.setStatus( + // 'tbxParmentsDecreasePercent', + // Status.Disabled, + // ); + // calculationStore.setStatus( + // 'selectHighSeasonStart', + // Status.Disabled, + // ); + // break; + // } + // } + // } + // }, + // options: { + // fireImmediately: true, + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { seasonType } = calculationStore.values; + // return seasonType; + // }, + // effect: seasonType => { + // if (seasonType) { + // switch (seasonType) { + // case 100000001: + // case 100000002: { + // calculationStore.setFilter('selectHighSeasonStart', seasons => { + // return seasons.filter( + // season => season.value && season.value <= 100000004, + // ); + // }); + // break; + // } + // default: + // calculationStore.setFilter('selectHighSeasonStart', undefined); + // break; + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { leasingPeriod } = calculationStore.values; + // return leasingPeriod; + // }, + // effect: leasingPeriod => { + // if (leasingPeriod) { + // if (parseInt(leasingPeriod) < 12) { + // calculationStore.setStatus('radioBalanceHolder', Status.Disabled); + // calculationStore.setValue('balanceHolder', 100000000); + // } else { + // calculationStore.setStatus('radioBalanceHolder', Status.Default); + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { balanceHolder } = calculationStore.values; + // return balanceHolder; + // }, + // effect: balanceHolder => { + // if (balanceHolder) { + // if (balanceHolder === 100000001) { + // calculationStore.setStatus( + // 'cbxLastPaymentRedemption', + // Status.Disabled, + // ); + // calculationStore.setValue('lastPaymentRedemption', true); + // } else { + // calculationStore.setStatus( + // 'cbxLastPaymentRedemption', + // Status.Default, + // ); + // } + // } + // }, + // }), + + // // TODO: Fake fake + // calculationStore => ({ + // expression: () => { + // const { dealer } = calculationStore.values; + // return dealer; + // }, + // effect: dealerId => { + // if (dealerId) { + // const dealer = calculationStore.options.selectDealer?.find( + // x => x.accountid === dealerId, + // ); + // if (dealer && dealer.evo_broker_accountid) { + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'account', + // where: { + // accountid: dealer.evo_broker_accountid, + // }, + // }, + // }) + // .then(({ entityOptions: brokers }) => { + // if (brokers && brokers.length > 0) { + // calculationStore.setOptions('selectDealerPerson', brokers); + // calculationStore.setValue('dealerPerson', brokers[0].accountid); + // calculationStore.setStatus( + // 'selectDealerPerson', + // Status.Default, + // ); + // } + // }) + // .catch(err => { + // throw err; + // }); + // } + // } + + // calculationStore.setOptions('selectDealerPerson', []); + // calculationStore.setValue('dealerPerson', null); + // calculationStore.setStatus('selectDealerPerson', Status.Disabled); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerPerson } = calculationStore.values; + // return dealerPerson; + // }, + // effect: dealerPersonId => { + // if (dealerPersonId) { + // const dealerPerson = calculationStore.options.selectDealerPerson?.find( + // x => x.accountid === dealerPersonId, + // ); + // if (dealerPerson && dealerPerson.evo_broker_accountid) { + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'account', + // where: { + // statecode: 0, + // accountid: dealerPerson.evo_broker_accountid, + // }, + // }, + // }) + // .then(({ entityOptions: brokers }) => { + // if (brokers && brokers.length > 0) { + // calculationStore.setOptions('selectDealerBroker', brokers); + // calculationStore.setValue('dealerBroker', brokers[0].accountid); + // calculationStore.setStatus( + // 'selectDealerBroker', + // Status.Default, + // ); + // } + // }) + // .catch(err => { + // throw err; + // }); + // } + // } + + // calculationStore.setOptions('selectDealerBroker', []); + // calculationStore.setValue('dealerBroker', null); + // calculationStore.setStatus('selectDealerBroker', Status.Disabled); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerBroker } = calculationStore.values; + // return dealerBroker; + // }, + // effect: dealerBrokerId => { + // if (dealerBrokerId) { + // const dealerBroker = calculationStore.options.selectDealerBroker?.find( + // x => x.accountid === dealerBrokerId, + // ); + // if (dealerBroker) { + // calculationStore.setStatus( + // 'selectDealerBrokerRewardСondition', + // Status.Default, + // ); + + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_reward_condition', + // where: { + // statecode: 0, + // // TODO < > текущей даты + // // evo_datefrom: new Date(), + // // evo_dateto: new Date(), + // evo_agent_accountid: dealerBrokerId, + // }, + // }, + // }) + // .then(({ entityOptions: reward_conditions }) => { + // calculationStore.setOptions( + // 'selectDealerBrokerRewardСondition', + // reward_conditions, + // ); + // }) + // .catch(err => { + // throw err; + // }); + // } + // } else { + // calculationStore.setValue('dealerBrokerRewardСondition', null); + // calculationStore.setStatus( + // 'selectDealerBrokerRewardСondition', + // Status.Disabled, + // ); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerBroker, dealerPerson } = calculationStore.values; + // return [dealerBroker, dealerPerson]; + // }, + // effect: ([dealerBrokerId, dealerPersonId]) => { + // if (dealerPersonId && !dealerBrokerId) { + // calculationStore.setStatus( + // 'selectDealerRewardСondition', + // Status.Default, + // ); + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_reward_condition', + // where: { + // statecode: 0, + // // TODO < > текущей даты + // // evo_datefrom: new Date(), + // // evo_dateto: new Date(), + // evo_agent_accountid: dealerPersonId, + // }, + // }, + // }) + // .then(({ entityOptions: reward_conditions }) => { + // calculationStore.setOptions( + // 'selectDealerRewardСondition', + // reward_conditions, + // ); + // }) + // .catch(err => { + // throw err; + // }); + // } else { + // calculationStore.setValue('dealerRewardСondition', null); + // calculationStore.setStatus( + // 'selectDealerRewardСondition', + // Status.Disabled, + // ); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerRewardСondition } = calculationStore.values; + // return dealerRewardСondition; + // }, + // effect: dealerRewardСonditionId => { + // if (!dealerRewardСonditionId) { + // calculationStore.setValue('dealerRewardSumm', 0); + // calculationStore.setStatus('tbxDealerRewardSumm', Status.Disabled); + // } else { + // const dealerRewardContition = calculationStore.options.selectDealerRewardСondition?.find( + // x => x.evo_reward_conditionid === dealerRewardСonditionId, + // ); + // if (dealerRewardContition) { + // if (dealerRewardContition.evo_reward_summ) { + // calculationStore.setValue( + // 'dealerRewardSumm', + // dealerRewardContition.evo_reward_summ, + // ); + // calculationStore.setStatus('tbxDealerRewardSumm', Status.Default); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerBrokerRewardСondition } = calculationStore.values; + // return dealerBrokerRewardСondition; + // }, + // effect: dealerBrokerRewardСonditionId => { + // if (!dealerBrokerRewardСonditionId) { + // calculationStore.setValue('dealerBrokerRewardSumm', 0); + // calculationStore.setStatus( + // 'tbxDealerBrokerRewardSumm', + // Status.Disabled, + // ); + // } else { + // const dealerBrokerRewardContition = calculationStore.options.selectDealerBrokerRewardСondition?.find( + // x => x.evo_reward_conditionid === dealerBrokerRewardСonditionId, + // ); + // if (dealerBrokerRewardContition) { + // if (dealerBrokerRewardContition.evo_reward_summ) { + // calculationStore.setValue( + // 'dealerBrokerRewardSumm', + // dealerBrokerRewardContition.evo_reward_summ, + // ); + // calculationStore.setStatus( + // 'tbxDealerBrokerRewardSumm', + // Status.Default, + // ); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerRewardSumm } = calculationStore.values; + // return dealerRewardSumm; + // }, + // effect: dealerRewardSumm => { + // const dealerRewardСonditionId = + // calculationStore.values.dealerRewardСondition; + // if (dealerRewardСonditionId) { + // const dealerRewardCondition = calculationStore.options.selectDealerRewardСondition?.find( + // x => x.evo_reward_conditionid === dealerRewardСonditionId, + // ); + // if (dealerRewardCondition) { + // if (dealerRewardCondition.evo_reward_summ) { + // if ( + // parseFloat(dealerRewardSumm) > + // dealerRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation('tbxDealerRewardSumm', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение ЮЛ поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } else if ( + // !dealerRewardCondition.evo_reduce_reward && + // dealerRewardCondition.evo_reward_summ + // ) { + // if ( + // parseFloat(dealerRewardSumm) < + // dealerRewardCondition.evo_reward_summ + // ) { + // calculationStore.setValidation('tbxDealerRewardSumm', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение ЮЛ поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // calculationStore.setValidation('tbxDealerRewardSumm', true); + // } + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { dealerBrokerRewardSumm } = calculationStore.values; + // return dealerBrokerRewardSumm; + // }, + // effect: dealerBrokerRewardSumm => { + // const dealerBrokerRewardСonditionId = + // calculationStore.values.dealerBrokerRewardСondition; + // if (dealerBrokerRewardСonditionId) { + // const dealerBrokerRewardСondition = calculationStore.options.selectDealerBrokerRewardСondition?.find( + // x => x.evo_reward_conditionid === dealerBrokerRewardСonditionId, + // ); + // if (dealerBrokerRewardСondition) { + // if (dealerBrokerRewardСondition.evo_reward_summ) { + // if ( + // parseFloat(dealerBrokerRewardSumm) > + // dealerBrokerRewardСondition.evo_reward_summ + // ) { + // calculationStore.setValidation( + // 'tbxDealerBrokerRewardSumm', + // false, + // ); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение брокера поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // if ( + // !dealerBrokerRewardСondition.evo_reduce_reward && + // dealerBrokerRewardСondition.evo_reward_summ + // ) { + // if ( + // parseFloat(dealerBrokerRewardSumm) < + // dealerBrokerRewardСondition.evo_reward_summ + // ) { + // calculationStore.setValidation( + // 'tbxDealerBrokerRewardSumm', + // false, + // ); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Вознаграждение брокера поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', + // })(); + // return; + // } + // } + // calculationStore.setValidation('tbxDealerBrokerRewardSumm', true); + // } + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { brand } = calculationStore.values; + // return brand; + // }, + // effect: brandId => { + // if (brandId) { + // const brand = calculationStore.options.selectBrand?.find( + // x => x.evo_brandid === brandId, + // ); + // if (brand) { + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_model', + // where: { + // statecode: 0, + // evo_brandid: brandId, + // }, + // }, + // }).then(({ entityOptions: models }) => { + // if (models && models.length > 0) { + // calculationStore.setStatus('selectModel', Status.Default); + // calculationStore.setOptions('selectModel', models); + // calculationStore.setValue('model', null); + // return; + // } + // }); + // } + // } + // calculationStore.setStatus('selectModel', Status.Disabled); + // calculationStore.setOptions('selectModel', []); + // calculationStore.setValue('model', null); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { model } = calculationStore.values; + // return model; + // }, + // effect: modelId => { + // if (modelId) { + // const model = calculationStore.options.selectModel?.find( + // x => x.evo_modelid === modelId, + // ); + // if (model) { + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_equipment', + // where: { + // statecode: 0, + // evo_modelid: modelId, + // }, + // }, + // }).then(({ entityOptions: equipments }) => { + // if (equipments && equipments.length > 0) { + // calculationStore.setStatus('selectConfiguration', Status.Default); + // calculationStore.setOptions('selectConfiguration', equipments); + // calculationStore.setValue('configuration', null); + // return; + // } + // }); + // } + // } + // calculationStore.setStatus('selectConfiguration', Status.Disabled); + // calculationStore.setOptions('selectConfiguration', []); + // calculationStore.setValue('configuration', null); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { configuration } = calculationStore.values; + // const { selectConfiguration } = calculationStore.options; + // return [configuration, selectConfiguration]; + // }, + // effect: ([configurationId, selectConfigurationOptions]) => { + // if (selectConfigurationOptions && selectConfigurationOptions.length) { + // if (!configurationId) { + // calculationStore.setValidation('selectConfiguration', false); + // return; + // } + // } + // calculationStore.setValidation('selectConfiguration', true); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { model, configuration } = calculationStore.values; + // return [model, configuration]; + // }, + // effect: ([modelId, configurationId]) => { + // if (configurationId) { + // const configuration = calculationStore.options.selectConfiguration?.find( + // x => x.evo_equipmentid === configurationId, + // ); + // if (configuration) { + // if (configuration.evo_impairment_groupid) { + // const evo_impairment_groups = calculationStore.getStaticData( + // 'evo_impairment_group', + // ); + // const evo_impairment_group = evo_impairment_groups.find( + // x => + // x.evo_impairment_groupid === + // configuration.evo_impairment_groupid, + // ); + // calculationStore.setValue( + // 'depreciationGroup', + // evo_impairment_group ? evo_impairment_group.evo_name : '', + // ); + // return; + // } + // } + // } + // const model = calculationStore.options.selectModel?.find( + // x => x.evo_modelid === modelId, + // ); + // if (model) + // if (model.evo_impairment_groupid) { + // const evo_impairment_groups = calculationStore.getStaticData( + // 'evo_impairment_group', + // ); + // const evo_impairment_group = evo_impairment_groups.find( + // x => x.evo_impairment_groupid === model.evo_impairment_groupid, + // ); + // calculationStore.setValue( + // 'depreciationGroup', + // evo_impairment_group ? evo_impairment_group.evo_name : '', + // ); + // return; + // } + // calculationStore.setValue('depreciationGroup', null); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { + // supplierCurrency, + // leaseObjectPrice, + // supplierDiscountRub, + // } = calculationStore.values; + // return [supplierCurrency, leaseObjectPrice, supplierDiscountRub]; + // }, + // effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountRub]) => { + // if (supplierDiscountRub === undefined) { + // return; + // } + // calculatePerc(calculationStore)( + // supplierCurrencyId, + // leaseObjectPrice, + // supplierDiscountRub, + // 'supplierDiscountPerc', + // ); + // }, + // }), + // calculationStore => ({ + // expression: () => { + // const { + // supplierCurrency, + // leaseObjectPrice, + // supplierDiscountPerc, + // } = calculationStore.values; + // return [supplierCurrency, leaseObjectPrice, supplierDiscountPerc]; + // }, + // effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountPerc]) => { + // if (supplierDiscountPerc === undefined) { + // return; + // } + // calculateRub(calculationStore)( + // supplierCurrencyId, + // leaseObjectPrice, + // supplierDiscountPerc, + // 'supplierDiscountRub', + // ); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { firstPaymentRub } = calculationStore.values; + // return firstPaymentRub; + // }, + // effect: firstPaymentRub => { + // if (firstPaymentRub === undefined) { + // return; + // } + // const { supplierCurrency, leaseObjectPrice } = calculationStore.values; + // calculatePerc(calculationStore)( + // supplierCurrency, + // leaseObjectPrice, + // firstPaymentRub, + // 'firstPaymentPerc', + // ); + // }, + // }), + // calculationStore => ({ + // expression: () => { + // const { + // supplierCurrency, + // leaseObjectPrice, + // firstPaymentPerc, + // } = calculationStore.values; + // return [supplierCurrency, leaseObjectPrice, firstPaymentPerc]; + // }, + // effect: ([supplierCurrencyId, leaseObjectPrice, firstPaymentPerc]) => { + // if (firstPaymentPerc === undefined) { + // return; + // } + // calculateRub(calculationStore)( + // supplierCurrencyId, + // leaseObjectPrice, + // firstPaymentPerc, + // 'firstPaymentRub', + // ); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { + // supplierCurrency, + // leaseObjectPrice, + // comissionPerc, + // } = calculationStore.values; + // return [supplierCurrency, leaseObjectPrice, comissionPerc]; + // }, + // effect: ([supplierCurrencyId, leaseObjectPrice, comissionPerc]) => { + // if (comissionPerc === undefined) { + // return; + // } + // calculateRub(calculationStore)( + // supplierCurrencyId, + // leaseObjectPrice, + // comissionPerc, + // 'comissionRub', + // ); + // }, + // }), + // calculationStore => ({ + // expression: () => { + // const { comissionRub } = calculationStore.values; + // return comissionRub; + // }, + // effect: comissionRub => { + // if (comissionRub === undefined) { + // return; + // } + // const { supplierCurrency, leaseObjectPrice } = calculationStore.values; + // calculatePerc(calculationStore)( + // supplierCurrency, + // leaseObjectPrice, + // comissionRub, + // 'comissionPerc', + // ); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { + // supplierCurrency, + // leaseObjectPrice, + // lastPaymentPerc, + // lastPaymentRule, + // } = calculationStore.values; + // return [ + // supplierCurrency, + // leaseObjectPrice, + // lastPaymentPerc, + // lastPaymentRule, + // ]; + // }, + // effect: ([ + // supplierCurrencyId, + // leaseObjectPrice, + // lastPaymentPerc, + // lastPaymentRule, + // ]) => { + // if (lastPaymentPerc === undefined || lastPaymentRule !== 100000001) { + // return; + // } + // calculateRub(calculationStore)( + // supplierCurrencyId, + // leaseObjectPrice, + // lastPaymentPerc, + // 'lastPaymentRub', + // ); + // }, + // }), + // calculationStore => ({ + // expression: () => { + // const { + // supplierCurrency, + // leaseObjectPrice, + // lastPaymentRub, + // lastPaymentRule, + // } = calculationStore.values; + // return [ + // supplierCurrency, + // leaseObjectPrice, + // lastPaymentRub, + // lastPaymentRule, + // ]; + // }, + // effect: ([ + // supplierCurrencyId, + // leaseObjectPrice, + // lastPaymentRub, + // lastPaymentRule, + // ]) => { + // if (lastPaymentRub === undefined || lastPaymentRule !== 100000000) { + // return; + // } + // calculatePerc(calculationStore)( + // supplierCurrencyId, + // leaseObjectPrice, + // lastPaymentRub, + // 'lastPaymentPerc', + // ); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { + // recalcWithRevision, + // supplierCurrency, + // supplierDiscountRub, + // supplierDiscountPerc, + // leaseObjectPrice, + // } = calculationStore.values; + // return [ + // recalcWithRevision, + // supplierCurrency, + // supplierDiscountRub, + // supplierDiscountPerc, + // leaseObjectPrice, + // ]; + // }, + // effect: ([ + // recalcWithRevision, + // supplierCurrencyId, + // supplierDiscountRub, + // supplierDiscountPerc, + // leaseObjectPrice, + // ]) => { + // if (recalcWithRevision === true) { + // return; + // } + // const supplierCurrency = calculationStore + // .getOptions('selectSupplierCurrency') + // .find(x => x.transactioncurrencyid === supplierCurrencyId); + // const evo_currencychange = calculationStore + // .getStaticData('evo_currencychange') + // ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + // const evo_currencychangeValue = + // (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + // let price = calcPrice( + // supplierCurrency?.isocurrencycode, + // leaseObjectPrice, + // evo_currencychangeValue, + // ); + + // let maxPriceChange = + // price - supplierDiscountRub < 800000 + // ? price - supplierDiscountRub + 50000 + // : (price - supplierDiscountRub) * 1.05; + + // calculationStore.setValue('maxPriceChange', maxPriceChange); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { recalcWithRevision } = calculationStore.values; + // return recalcWithRevision; + // }, + // effect: recalcWithRevision => { + // if (recalcWithRevision === true) { + // calculationStore.setStatus('selectLead', Status.Disabled); + // calculationStore.setStatus('selectOpportunity', Status.Disabled); + // calculationStore.setStatus('selectQuote', Status.Disabled); + // } else { + // calculationStore.setStatus('selectLead', Status.Default); + // calculationStore.setStatus('selectOpportunity', Status.Default); + // calculationStore.setStatus('selectQuote', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { + // supplierDiscountRub, + // leaseObjectPrice, + // supplierCurrency, + // } = calculationStore.values; + // return [supplierDiscountRub, leaseObjectPrice, supplierCurrency]; + // }, + // effect: ([supplierDiscountRub, leaseObjectPrice, supplierCurrencyId]) => { + // const { recalcWithRevision, maxPriceChange } = calculationStore.values; + // if (recalcWithRevision === false) { + // return; + // } + + // const supplierCurrency = calculationStore + // .getOptions('selectSupplierCurrency') + // .find(x => x.transactioncurrencyid === supplierCurrencyId); + // const evo_currencychange = calculationStore + // .getStaticData('evo_currencychange') + // ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + // const evo_currencychangeValue = + // (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + // let price = calcPrice( + // supplierCurrency?.isocurrencycode, + // leaseObjectPrice, + // evo_currencychangeValue, + // ); + + // if (price - supplierDiscountRub > maxPriceChange) { + // calculationStore.setValidation('tbxLeaseObjectPrice', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра.' + + // 'Уменьшите стоимость предмета лизинга', + // })(); + // } else { + // calculationStore.setValidation('tbxLeaseObjectPrice', true); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { leaseObjectUsed } = calculationStore.values; + // return leaseObjectUsed; + // }, + // effect: leaseObjectUsed => { + // if (leaseObjectUsed === true) { + // calculationStore.setValue('deliveryTime', 100000000); + // calculationStore.setStatus('radioDeliveryTime', Status.Disabled); + // } else { + // calculationStore.setStatus('radioDeliveryTime', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { leaseObjectCategory } = calculationStore.values; + // return leaseObjectCategory; + // }, + // effect: leaseObjectCategory => { + // if ( + // leaseObjectCategory === 100000001 || + // leaseObjectCategory === 100000001 + // ) { + // calculationStore.setValue('withTrailer', null); + // calculationStore.setStatus('selectWithTrailer', Status.Disabled); + // } else { + // calculationStore.setStatus('selectWithTrailer', Status.Default); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { quote } = calculationStore.values; + // return quote; + // }, + // effect: quoteId => { + // if (quoteId) { + // const quote = calculationStore.options.selectQuote?.find( + // x => x.quoteid === quoteId, + // ); + // if (quote) { + // if (quote.evo_recalc_limit && quote.evo_recalc_limit > 0) { + // if (quote.evo_statuscodeid) { + // CalculationService.getEntityOptions({ + // query: { + // entityName: 'evo_statuscode', + // where: { + // evo_statuscodeid: quote.evo_statuscodeid, + // statecode: 0, + // }, + // }, + // }) + // .then(({ entityOptions: evo_statuscodes }) => { + // if (evo_statuscodes && evo_statuscodes.length > 0) { + // const evo_statuscode = evo_statuscodes[0]; + // if (evo_statuscode.evo_id === '2.3') { + // calculationStore.setStatus( + // 'cbxRecalcWithRevision', + // Status.Default, + // ); + // return; + // } + // } + // }) + // .catch(err => { + // throw err; + // }); + // } + // } + // } + // } + // calculationStore.setStatus('cbxRecalcWithRevision', Status.Disabled); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { firstPaymentPerc } = calculationStore.values; + // return firstPaymentPerc; + // }, + // effect: firstPaymentPerc => { + // const { recalcWithRevision, quote: quoteId } = calculationStore.values; + // if (recalcWithRevision) { + // const quote = calculationStore.options.selectQuote?.find( + // x => x.quoteid === quoteId, + // ); + // if (quote && quote.evo_approved_first_payment) { + // if (firstPaymentPerc < quote.evo_approved_first_payment) { + // calculationStore.setValidation('tbxFirstPaymentPerc', false); + // openNotification({ + // type: 'error', + // title: 'Ошибка', + // description: + // 'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения', + // })(); + // return; + // } + // } + // } + // calculationStore.setValidation('tbxFirstPaymentPerc', undefined); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { brand, model, leaseObjectUsed } = calculationStore.values; + // return [brand, model, leaseObjectUsed]; + // }, + // effect: ([brandId, modelId, leaseObjectUsed]) => { + // if (leaseObjectUsed === false) { + // const model = calculationStore.options.selectModel?.find( + // x => x.evo_modelid === modelId, + // ); + // const brand = calculationStore.options.selectBrand?.find( + // x => x.evo_brandid === brandId, + // ); + + // if ( + // model && + // model.evo_importer_reward_perc && + // model.evo_importer_reward_perc > 0 + // ) { + // calculationStore.setValue( + // 'importerRewardPerc', + // model.evo_importer_reward_perc, + // ); + // return; + // } + // if ( + // brand && + // brand.evo_importer_reward_perc && + // brand.evo_importer_reward_perc > 0 + // ) { + // calculationStore.setValue( + // 'importerRewardPerc', + // brand.evo_importer_reward_perc, + // ); + // return; + // } + // } + // calculationStore.setValue('importerRewardPerc', 0); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { brand, model, leaseObjectUsed } = calculationStore.values; + // return [brand, model, leaseObjectUsed]; + // }, + // effect: ([brandId, modelId, leaseObjectUsed]) => { + // if (leaseObjectUsed === false) { + // const model = calculationStore.options.selectModel?.find( + // x => x.evo_modelid === modelId, + // ); + // const brand = calculationStore.options.selectBrand?.find( + // x => x.evo_brandid === brandId, + // ); + + // if ( + // model && + // model.evo_importer_reward_rub && + // model.evo_importer_reward_rub > 0 + // ) { + // calculationStore.setValue( + // 'importerRewardRub', + // model.evo_importer_reward_rub, + // ); + // return; + // } + // if ( + // brand && + // brand.evo_importer_reward_rub && + // brand.evo_importer_reward_rub > 0 + // ) { + // calculationStore.setValue( + // 'importerRewardRub', + // brand.evo_importer_reward_rub, + // ); + // return; + // } + // } + // calculationStore.setValue('importerRewardRub', 0); + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { rows: tableRows } = calculationStore.tables.tableInsurance; + // const kaskoRowIndex = tableRows.findIndex( + // x => x.policyType?.value === 'КАСКО', + // ); + + // const kaskoValues = calculationStore.getTableRowValues( + // 'tableInsurance', + // kaskoRowIndex, + // 'value', + // ); + + // return { + // ...kaskoValues, + // }; + // }, + // effect: ({ insuranceCompany, insTerm, insured }) => { + // if (insTerm) { + // const { rows: tableRows } = calculationStore.tables.tableInsurance; + // const dgoRowIndex = tableRows.findIndex( + // x => x.policyType?.value === 'ДГО', + // ); + // if (dgoRowIndex && dgoRowIndex >= 0) + // calculationStore.setTableRows( + // 'tableInsurance', + // dgoRowIndex, + // )([ + // { + // insuranceCompany: { + // value: insuranceCompany, + // }, + // insTerm: { + // value: insTerm, + // }, + // insured: { + // value: insured, + // }, + // }, + // { + // insuranceCompany: { + // value: insuranceCompany, + // }, + // insTerm: { + // value: insTerm, + // }, + // insured: { + // value: insured, + // }, + // }, + // ]); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { rows: tableRows } = calculationStore.tables.tableInsurance; + // const kaskoRowIndex = tableRows.findIndex(x => x.policyType === 'КАСКО'); + // const kaskoRow = tableRows[kaskoRowIndex]; + // const { leasingPeriod } = calculationStore.values; + // if (kaskoRow) { + // return { + // insTerm: kaskoRow.insTerm?.value, + // kaskoRowIndex, + // leasingPeriod, + // }; + // } + // }, + // effect: ({ insTerm, kaskoRowIndex, leasingPeriod }) => { + // if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { + // if (kaskoRowIndex >= 0) + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insured: { value: 100000001, status: Status.Disabled }, + // }); + // } else { + // if (kaskoRowIndex >= 0) + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insured: { status: Status.Default }, + // }); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { leasingPeriod } = calculationStore.values; + // return leasingPeriod; + // }, + // effect: leasingPeriod => { + // const { rows: tableRows } = calculationStore.tables.tableInsurance; + // const kaskoRowIndex = tableRows.findIndex( + // x => x.policyType?.value === 'КАСКО', + // ); + // const osagoRowIndex = tableRows.findIndex( + // x => x.policyType?.value === 'ОСАГО', + // ); + + // if (leasingPeriod) { + // if (leasingPeriod < 12) { + // if (kaskoRowIndex >= 0) + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insured: { value: 100000000, status: Status.Disabled }, + // }); + // if (osagoRowIndex >= 0) { + // calculationStore.setTableRow( + // 'tableInsurance', + // osagoRowIndex, + // )({ + // insured: { value: 100000000, status: Status.Disabled }, + // }); + // } + // } else { + // if (kaskoRowIndex >= 0) + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insured: { value: 100000000, status: Status.Default }, + // }); + // if (osagoRowIndex >= 0) { + // calculationStore.setTableRow( + // 'tableInsurance', + // osagoRowIndex, + // )({ + // insured: { status: Status.Default }, + // }); + // } + // } + + // if (leasingPeriod < 13) { + // if (kaskoRowIndex >= 0) + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insTerm: { value: 100000000, status: Status.Disabled }, + // }); + // return; + // } else if (leasingPeriod > 12 && leasingPeriod < 16) { + // if (kaskoRowIndex >= 0) + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insTerm: { value: 100000001, status: Status.Disabled }, + // }); + // return; + // } else { + // if (kaskoRowIndex >= 0) { + // calculationStore.setTableRow( + // 'tableInsurance', + // kaskoRowIndex, + // )({ + // insured: { status: Status.Default }, + // insTerm: { status: Status.Default }, + // }); + // } + // } + // } + // }, + // options: { + // fireImmediately: true, + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { graphType, leasingPeriod } = calculationStore.values; + // return { graphType, leasingPeriod }; + // }, + // effect: ({ graphType, leasingPeriod }) => { + // if (graphType === 100000003 && leasingPeriod < 14) { + // calculationStore.setValue('leasingPeriod', 14); + // openNotification({ + // type: 'warning', + // title: 'Внимание', + // description: + // 'При сезонном графике срок лизинга должен быть больше 14 месяцев', + // })(); + // } + // }, + // }), + + // calculationStore => ({ + // expression: () => { + // const { + // leasingPeriod, + // graphType, + // parmentsDecreasePercent, + // seasonType, + // highSeasonStart: highSeasonStartId, + // firstPaymentPerc, + // lastPaymentPerc, + // } = calculationStore.values; + + // const highSeasonStart = calculationStore.options.selectHighSeasonStart?.find( + // x => x.value === highSeasonStartId, + // ); + + // return { + // leasingPeriod, + // graphType, + // parmentsDecreasePercent, + // seasonType, + // highSeasonStart: parseInt(highSeasonStart?.name || '2'), + // firstPaymentPerc, + // lastPaymentPerc, + // }; + // }, + // effect: async (nextParams, prevParams) => { + // const { + // leasingPeriod, + // graphType, + // parmentsDecreasePercent, + // seasonType, + // highSeasonStart, + // firstPaymentPerc, + // lastPaymentPerc, + // } = nextParams; + + // const prevValues = toJS(calculationStore.tables.tablePayments.rows).map( + // x => x.paymentRelation?.value, + // ); + // let payments: TableProps[] = [ + // { + // paymentRelation: { + // value: firstPaymentPerc, + // status: Status.Disabled, + // }, + // }, + // ]; + + // calculationStore.cleanTable('tablePayments'); + + // switch (graphType) { + // case 100000000: { + // const middleRows = Array.from({ length: leasingPeriod - 2 }, () => ({ + // paymentRelation: { + // value: 100, + // status: Status.Disabled, + // }, + // })); + // payments = [...payments, ...middleRows]; + + // break; + // } + + // case 100000001: { + // const middleRows = Array.from({ length: leasingPeriod - 3 }, () => ({ + // paymentRelation: { + // value: 100, + // status: Status.Default, + // }, + // })); + // payments = [ + // ...payments, + // { + // paymentRelation: { + // value: 100, + // status: Status.Disabled, + // }, + // }, + // ...middleRows, + // ]; + + // break; + // } + + // case 100000002: { + // const middleRows = Array.from( + // { length: leasingPeriod - 3 }, + // (v, i) => ({ + // paymentRelation: { + // value: 100, + // status: Status.Disabled, + // }, + // }), + // ); + // for (let i in middleRows) { + // const currRow = middleRows[parseInt(i)]; + // const prevRow = middleRows[parseInt(i) - 1]; + // currRow.paymentRelation.value = parseFloat( + // ( + // ((prevRow ? prevRow.paymentRelation.value : 100) * + // parmentsDecreasePercent) / + // 100 + // ).toFixed(2), + // ); + // } + // payments = [ + // ...payments, + // { + // paymentRelation: { + // value: 100, + // status: Status.Disabled, + // }, + // }, + // ...middleRows, + // ]; + + // break; + // } + + // case 100000003: { + // let HIGH = 100, + // MIDDLE = 75, + // LOW = 50; + + // if ( + // prevParams.graphType === nextParams.graphType + // // && nextParams.graphType === 100000003 + // ) { + // /** + // * FIND PREV HIGH, MIDDLE, LOW + // */ + // const { + // leasingPeriod: prevLeasingPeriod, + // seasonType: prevSeasonType, + // highSeasonStart: prevHighSeasonStart, + // } = prevParams; + + // const prevPeriodsNumber = + // prevLeasingPeriod <= 14 ? prevLeasingPeriod - 2 : 12; + // const prevShiftNumber = prevHighSeasonStart - 2; + + // let middleRows = prevValues.slice(1, prevPeriodsNumber + 1); + // if (middleRows.length < 12) { + // middleRows = [ + // ...middleRows, + // ...Array.from({ length: 12 - middleRows.length }, v => 0), + // ]; + // } + // if (prevShiftNumber > 0) + // middleRows = shiftRight(middleRows, prevShiftNumber); + + // switch (prevSeasonType) { + // // 6/6 + // case 100000000: { + // HIGH = middleRows[0]; + // LOW = middleRows[6]; + // break; + // } + // // 8/4 + // case 100000001: { + // HIGH = middleRows[0]; + // LOW = middleRows[8]; + + // break; + // } + // // 4/4/4 + // case 100000002: { + // HIGH = middleRows[0]; + // MIDDLE = middleRows[4]; + // LOW = middleRows[8]; + // break; + // } + // } + // /** */ + // } + + // /** + // * GENERATE PERIODS + // */ + + // const { + // leasingPeriod: nextLeasingPeriod, + // seasonType: nextSeasonType, + // highSeasonStart: nextHighSeasonStart, + // } = nextParams; + + // const nextPeriodsNumber = + // nextLeasingPeriod <= 14 ? nextLeasingPeriod - 2 : 12; + // const nextShiftNumber = nextHighSeasonStart - 2; + + // let nextPeriods: number[] = []; + + // switch (nextSeasonType) { + // // 6/6 + // case 100000000: { + // nextPeriods = Array.from({ length: 12 }, (v, i) => + // i < 6 ? HIGH : LOW, + // ); + // break; + // } + // // 8/4 + // case 100000001: { + // nextPeriods = Array.from({ length: 12 }, (v, i) => + // i < 8 ? HIGH : LOW, + // ); + // break; + // } + // // 4/4/4 + // case 100000002: { + // nextPeriods = Array.from( + // { length: 12 }, + // (v, i) => (i < 4 && HIGH) || (i < 8 && MIDDLE) || LOW, + // ); + // break; + // } + // } + // if (nextShiftNumber > 0) { + // nextPeriods = shift(nextPeriods, nextShiftNumber); + // } + // nextPeriods.length = nextPeriodsNumber; + + // const middleRows = Array.from( + // { length: nextLeasingPeriod - 2 }, + // (v, i) => { + // return { + // paymentRelation: { + // value: + // nextPeriods[ + // i - nextPeriodsNumber * Math.floor(i / nextPeriodsNumber) + // ], + // status: + // i < nextPeriodsNumber ? Status.Default : Status.Disabled, + // }, + // }; + // }, + // ); + + // payments = [...payments, ...middleRows]; + + // break; + // } + + // case 100000004: { + // const middleRows = Array.from({ length: leasingPeriod - 5 }, () => ({ + // paymentRelation: { + // value: 100, + // status: Status.Disabled, + // }, + // })); + + // payments = [ + // ...payments, + // { + // paymentRelation: { + // value: 25, + // status: Status.Default, + // }, + // }, + // { + // paymentRelation: { + // value: 50, + // status: Status.Default, + // }, + // }, + // { + // paymentRelation: { + // value: 75, + // status: Status.Default, + // }, + // }, + // ...middleRows, + // ]; + // break; + // } + + // default: { + // break; + // } + // } + + // payments = [ + // ...payments, + // { + // paymentRelation: { + // value: lastPaymentPerc, + // status: Status.Disabled, + // }, + // }, + // ]; + + // calculationStore.setTableRows('tablePayments', 0)(payments); + // }, + // options: { + // fireImmediately: true, + // }, + // }), ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts index 1210fb2..30ace45 100644 --- a/src/client/stores/CalculationStore/index.ts +++ b/src/client/stores/CalculationStore/index.ts @@ -17,7 +17,7 @@ import { import { staticData, staticDataAction } from './Data/staticEntities'; import autorunEffects from './Effects/autorun'; import computedEffects from './Effects/computed'; -// import reactionEffects from './Effects/reaction'; +import reactionEffects from './Effects/reaction'; import whenEffects from './Effects/when'; const CalculationStore: ICalculationStore = makeAutoObservable( @@ -42,15 +42,15 @@ autorunEffects.map(autorunEffect => autorun(autorunEffect(CalculationStore, CommonStore)), ); -// reactionEffects.map(reactionEffectBuilder => { -// const reactionEffect = reactionEffectBuilder(CalculationStore); -// return reaction(reactionEffect.expression, reactionEffect.effect, { -// ...reactionEffect.options, -// equals: (nextParams, prevParams) => { -// return isEqual(nextParams, prevParams); -// }, -// }); -// }); +reactionEffects.map(reactionEffectBuilder => { + const reactionEffect = reactionEffectBuilder(CalculationStore); + return reaction(reactionEffect.expression, reactionEffect.effect, { + ...reactionEffect.options, + equals: (nextParams, prevParams) => { + return isEqual(nextParams, prevParams); + }, + }); +}); whenEffects.map(whenEffectBuilder => { const whenEffect = whenEffectBuilder(CalculationStore); diff --git a/src/core/Data/initialOptions.ts b/src/core/Data/initialOptions.ts index c9f1e91..aed7063 100644 --- a/src/core/Data/initialOptions.ts +++ b/src/core/Data/initialOptions.ts @@ -7,7 +7,15 @@ const initialOptions: TEntityQuery[] = [ { alias: 'selectLead', entityName: 'lead', - fields: ['leadid', 'fullname', 'evo_opportunityid'], + fields: [ + 'leadid', + 'fullname', + 'evo_opportunityid', + 'evo_agent_accountid', + 'evo_double_agent_accountid', + 'evo_broker_accountid', + 'evo_fin_department_accountid', + ], where: { statecode: 0 }, many: true, }, diff --git a/src/core/tools/query.ts b/src/core/tools/query.ts index 9dc1e8b..ef97a17 100644 --- a/src/core/tools/query.ts +++ b/src/core/tools/query.ts @@ -28,7 +28,6 @@ const convert = { return res_related.toString().replace(/"/, ''); }, where: (where: TWhere): string => { - // return JSON.stringify(whereIn || {}).replace(/[^\w\s,[\]:!?]/g, ''); return stringifyObject(where); }, whereCmp: (whereCmp?: TWhere) => { @@ -44,7 +43,8 @@ const convert = { function convertNestedEntity(query: TBaseEntityQuery) { let entityQuery: string = `${ - query.many ? plural(query.entityName) : query.entityName}{ + query.many ? plural(query.entityName) : query.entityName + }{ ${convert.fields(query.fields)} ${convert.relatedEntities(query.relatedEntities)} }`; diff --git a/src/core/types/Calculation/Requests.ts b/src/core/types/Calculation/Requests.ts index 583230e..c6617a6 100644 --- a/src/core/types/Calculation/Requests.ts +++ b/src/core/types/Calculation/Requests.ts @@ -4,7 +4,7 @@ import { TValue, TValues } from './Store/values'; export interface IGetEntitiesRequest { queries: TEntityQuery[]; - toOptions: boolean; + toOptions?: boolean; } export interface IGetCalculationRequest { diff --git a/src/core/types/Calculation/Responses.ts b/src/core/types/Calculation/Responses.ts index 0a396f8..effeca5 100644 --- a/src/core/types/Calculation/Responses.ts +++ b/src/core/types/Calculation/Responses.ts @@ -2,7 +2,7 @@ import { TCRMEntity } from '../Entities/crmEntities'; import { TEntities } from '../Entities/crmEntityNames'; export interface IGetEntitiesResponse { - entities: TEntities; + entities: TEntities; } export interface IGetCalculationResponse { diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index b21759a..b9a8f62 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -1,7 +1,5 @@ import { CRMEntityNames } from './crmEntityNames'; -interface AccountData {} - export interface IAccount { name?: string; accountid?: string; @@ -14,7 +12,6 @@ export interface IAccount { ownerid?: string; evo_broker_accountid?: string; evo_client_riskid?: string; - accountidData?: AccountData; evo_type_ins_policy?: number[]; } @@ -25,6 +22,11 @@ export interface ILead { account?: string; ownerid?: string; statecode?: number; + evo_fin_department_accountid?: string; + evo_broker_accountid?: string; + evo_double_agent_accountid?: string; + evo_agent_accountid?: string; + accountidData?: IAccount; } export interface IOpportunity { @@ -34,6 +36,7 @@ export interface IOpportunity { evo_client_riskid?: string; ownerid?: string; statecode?: number; + accountidData?: IAccount; } export interface IQuote { diff --git a/src/core/types/Entities/crmEntityNames.ts b/src/core/types/Entities/crmEntityNames.ts index be07889..0bad4ef 100644 --- a/src/core/types/Entities/crmEntityNames.ts +++ b/src/core/types/Entities/crmEntityNames.ts @@ -30,7 +30,16 @@ export type CRMEntityNames = | 'systemuser' | 'evo_sot_coefficient_type'; +export const CRMEntityAliases = [ + 'agent', + 'double_agent', + 'broker', + 'findepartment', +] as const; +type CRMEntityAliasesType = typeof CRMEntityAliases; +export type CRMEntityAliasesUnion = CRMEntityAliasesType[number]; + //TODO: or string export type TEntities = { - [entityName in CRMEntityNames]?: T; + [entityName in CRMEntityNames | CRMEntityAliasesUnion]?: T; }; diff --git a/src/core/types/Entities/query.ts b/src/core/types/Entities/query.ts index 822cf17..94bfb58 100644 --- a/src/core/types/Entities/query.ts +++ b/src/core/types/Entities/query.ts @@ -1,6 +1,7 @@ // import { ElementsNames } from 'core/types/Calculation/Store/elements'; import { TCRMEntity } from './crmEntities'; -import { CRMEntityNames } from './crmEntityNames'; +import { CRMEntityNames, CRMEntityAliasesUnion } from './crmEntityNames'; +import { ElementsNames } from 'core/types/Calculation/Store/elements'; export type ComparisonOperators = { eq?: any; @@ -15,8 +16,7 @@ export type TEntitiesKeys = keyof TCRMEntity; export type TWhere = { [prop in TEntitiesKeys]?: T }; export type TBaseEntityQuery = { - //TODO: alias: ElementsNames - alias?: string; + alias?: CRMEntityAliasesUnion | ElementsNames; entityName: CRMEntityNames; fields: [TEntitiesKeys, ...TEntitiesKeys[]]; relatedEntities?: TBaseEntityQuery[]; diff --git a/src/server/controllers/CalculationController/index.ts b/src/server/controllers/CalculationController/index.ts index 3e10b37..0b7cf98 100644 --- a/src/server/controllers/CalculationController/index.ts +++ b/src/server/controllers/CalculationController/index.ts @@ -13,8 +13,10 @@ import { import { CRMEntityNames, TEntities, + CRMEntityAliases, } from '../../../core/types/Entities/crmEntityNames'; import { getEntities } from './crmManager'; +import { singular, isPlural } from 'pluralize'; class CalculationController { static getCRMEntities = async ( @@ -22,7 +24,13 @@ class CalculationController { res: Response, next: NextFunction, ): Promise => { - const { queries, toOptions } = req.body as IGetEntitiesRequest; + let { queries, toOptions } = req.body as IGetEntitiesRequest; + + queries = queries.filter(query => { + return Object.values(query.where).some( + x => x !== null && x !== undefined, + ); + }); let resEntities = await getEntities(queries); if (toOptions) { let entitiesWithOptions: TEntities = {}; @@ -37,7 +45,12 @@ class CalculationController { convertEntityToOption(entity, entity.__typename), ); } - entitiesWithOptions[name] = optionatedOptions; + entitiesWithOptions[ + //@ts-ignore + !CRMEntityAliases.includes(name) && isPlural(name) + ? singular(name) + : name + ] = optionatedOptions; }); res.send({ entities: entitiesWithOptions }); return; diff --git a/src/server/routes/calculation.ts b/src/server/routes/calculation.ts index 0100779..fc1f6a2 100644 --- a/src/server/routes/calculation.ts +++ b/src/server/routes/calculation.ts @@ -3,7 +3,6 @@ import { Router } from 'express'; const router = Router(); -//TODO: use router.post('/getCRMEntities', CalculationController.getCRMEntities); router.post('/calculate', CalculationController.calculate);