diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 96292c1..97089e7 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -472,6 +472,9 @@ const reactionEffects: IReactionEffect[] = [ ) { evo_reward_conditionid evo_name + evo_double_agent_accountid + evo_reward_summ + evo_reduce_reward } } `, @@ -490,6 +493,9 @@ const reactionEffects: IReactionEffect[] = [ }); } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -527,6 +533,8 @@ const reactionEffects: IReactionEffect[] = [ ) { evo_reward_conditionid evo_name + evo_reward_summ + evo_reduce_reward } } `, @@ -545,1053 +553,1179 @@ const reactionEffects: IReactionEffect[] = [ }); } }, + options: { + fireImmediately: true, + }, }), - // 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 { 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, + ); + if (calcFinDepartmentId) + CalculationService.crmgqlquery({ + query: gql` + query( + $statecode: Int + $currentDate: DateTime + $evo_agent_accountid: Uuid + ) { + evo_reward_condition: evo_reward_conditions( + evo_agent_accountid: $evo_agent_accountid + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + statecode: $statecode + ) { + evo_reward_conditionid + evo_name + evo_reward_summ + evo_reduce_reward + } + } + `, + variables: { + evo_agent_accountid: calcFinDepartmentId, + currentDate, + statecode: 0, + }, + toOptions: ['evo_reward_condition'], + }).then(({ entities: { evo_reward_condition } }) => { + if (evo_reward_condition && Array.isArray(evo_reward_condition)) + calculationStore.setOptions( + 'selectFinDepartmentRewardCondtion', + evo_reward_condition, + ); + }); + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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, + ); - // calculationStore => ({ - // expression: () => { - // const { indAgentRewardCondition } = calculationStore.values; - // return indAgentRewardCondition; - // }, - // effect: indAgentRewardConditionId => { - // if (!indAgentRewardConditionId) { - // calculationStore.setValue('indAgentRewardSumm', null); - // calculationStore.setStatus('tbxIndAgentRewardSumm', Status.Disabled); + if (calcBrokerId) + CalculationService.crmgqlquery({ + query: gql` + query( + $statecode: Int + $currentDate: DateTime + $evo_agent_accountid: Uuid + ) { + evo_reward_condition: evo_reward_conditions( + evo_agent_accountid: $evo_agent_accountid + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + statecode: $statecode + ) { + evo_reward_conditionid + evo_name + evo_reward_summ + evo_reduce_reward + } + } + `, + variables: { + evo_agent_accountid: calcBrokerId, + currentDate, + statecode: 0, + }, + toOptions: ['evo_reward_condition'], + }).then(({ entities: { evo_reward_condition } }) => { + if (evo_reward_condition && Array.isArray(evo_reward_condition)) + calculationStore.setOptions( + 'selectCalcBrokerRewardCondition', + evo_reward_condition, + ); + }); + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { indAgentRewardCondition } = calculationStore.values; + return indAgentRewardCondition; + }, + effect: indAgentRewardConditionId => { + if (!indAgentRewardConditionId) { + calculationStore.setValue('indAgentRewardSumm', null); + calculationStore.setStatus('tbxIndAgentRewardSumm', 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, - // ); - // } - // } - // } - // }, - // }), + 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 || 0, + ); + calculationStore.setStatus('tbxIndAgentRewardSumm', Status.Default); + if (indAgentRewardCondition?.evo_double_agent_accountid) { + calculationStore.setStatus('selectCalcDoubleAgent', Status.Default); + const doubleAgent = calculationStore.options.selectCalcDoubleAgent?.find( + x => + x.accountid === + indAgentRewardCondition?.evo_double_agent_accountid, + ); + if (doubleAgent) { + calculationStore.setOptions('selectCalcDoubleAgent', [ + doubleAgent, + ]); + calculationStore.setValue( + 'calcDoubleAgent', + doubleAgent.accountid, + ); + } + } else { + calculationStore.setValue('calcDoubleAgent', null); + calculationStore.setStatus( + 'selectCalcDoubleAgent', + Status.Disabled, + ); + } + } + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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, + ); + } + } + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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, + ); + } + } + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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, + ); + } + } + } + }, + options: { + fireImmediately: 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { insUnlimitDrivers } = calculationStore.values; - // return insUnlimitDrivers; - // }, - // effect: insUnlimitDrivers => { - // if (insUnlimitDrivers) { - // calculationStore.setStatus('btnDriversApplication', Status.Disabled); - // } else { - // calculationStore.setStatus('btnDriversApplication', Status.Default); - // } - // }, - // }), + 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 { 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 { insUnlimitDrivers } = calculationStore.values; + return insUnlimitDrivers; + }, + effect: insUnlimitDrivers => { + if (insUnlimitDrivers) { + calculationStore.setStatus('btnDriversApplication', Status.Disabled); + } else { + calculationStore.setStatus('btnDriversApplication', 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 { 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 { 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 { 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 { 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; - // } + 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); + }, + }), - // case 100000003: { - // calculationStore.setStatus('radioSeasonType', Status.Default); - // calculationStore.setStatus( - // 'tbxParmentsDecreasePercent', - // Status.Disabled, - // ); - // calculationStore.setStatus('selectHighSeasonStart', Status.Default); - // break; - // } + 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; + } - // default: { - // calculationStore.setStatus('radioSeasonType', Status.Disabled); - // calculationStore.setStatus( - // 'tbxParmentsDecreasePercent', - // Status.Disabled, - // ); - // calculationStore.setStatus( - // 'selectHighSeasonStart', - // Status.Disabled, - // ); - // break; - // } - // } - // } - // }, - // options: { - // fireImmediately: true, - // }, - // }), + case 100000003: { + calculationStore.setStatus('radioSeasonType', Status.Default); + calculationStore.setStatus( + 'tbxParmentsDecreasePercent', + Status.Disabled, + ); + calculationStore.setStatus('selectHighSeasonStart', Status.Default); + break; + } - // 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; - // } - // } - // }, - // }), + default: { + calculationStore.setStatus('radioSeasonType', Status.Disabled); + calculationStore.setStatus( + 'tbxParmentsDecreasePercent', + Status.Disabled, + ); + calculationStore.setStatus( + 'selectHighSeasonStart', + Status.Disabled, + ); + break; + } + } + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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 { 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, - // ); - // } - // } - // }, - // }), + 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); + } + } + }, + }), - // // 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 => ({ + 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, + ); + } + } + }, + }), - // calculationStore.setOptions('selectDealerPerson', []); - // calculationStore.setValue('dealerPerson', null); - // calculationStore.setStatus('selectDealerPerson', Status.Disabled); - // }, - // }), + calculationStore => ({ + expression: () => { + const { dealer } = calculationStore.values; + return dealer; + }, + effect: dealerId => { + if (dealerId) { + const dealer = calculationStore.options.selectDealer?.find( + x => x.accountid === dealerId, + ); + if (dealer) { + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $salonaccountid: Uuid!) { + account: salon_providers( + statecode: $statecode + salonaccountid: $salonaccountid + ) { + accountid + name + evo_broker_accountid + } + } + `, + toOptions: ['account'], + variables: { + salonaccountid: dealerId, + statecode: 0, + }, + }).then(({ entities }) => { + if ( + entities.account && + Array.isArray(entities.account) && + entities.account.length > 0 + ) { + calculationStore.setOptions( + 'selectDealerPerson', + entities.account, + ); + calculationStore.setValue( + 'dealerPerson', + entities.account[0].accountid, + ); + calculationStore.setStatus('selectDealerPerson', Status.Default); + } + }); + } + } - // 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('selectDealerPerson', []); + calculationStore.setValue('dealerPerson', null); + calculationStore.setStatus('selectDealerPerson', Status.Disabled); + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore.setOptions('selectDealerBroker', []); - // calculationStore.setValue('dealerBroker', null); - // calculationStore.setStatus('selectDealerBroker', Status.Disabled); - // }, - // }), + calculationStore => ({ + expression: () => { + const { dealerPerson } = calculationStore.values; + return dealerPerson; + }, + effect: dealerPersonId => { + calculationStore.setOptions('selectDealerBroker', []); + calculationStore.setValue('dealerBroker', null); + calculationStore.setStatus('selectDealerBroker', Status.Disabled); + if (dealerPersonId) { + const dealerPerson = calculationStore.options.selectDealerPerson?.find( + x => x.accountid === dealerPersonId, + ); + if (dealerPerson && dealerPerson.evo_broker_accountid) { + CalculationService.crmgqlquery({ + query: gql` + query($accountid: Uuid!) { + account(accountid: $accountid) { + accountid + name + } + } + `, + toOptions: ['account'], + variables: { + accountid: dealerPerson.evo_broker_accountid, + }, + }).then(({ entities }) => { + if (entities.account && !Array.isArray(entities.account)) { + calculationStore.setOptions('selectDealerBroker', [ + entities.account, + ]); + calculationStore.setValue( + 'dealerBroker', + entities.account.accountid, + ); + calculationStore.setStatus('selectDealerBroker', Status.Default); + } + }); + } + } + }, + options: { + fireImmediately: true, + }, + }), - // 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, - // ); + 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, - // ); - // } - // }, - // }), + CalculationService.crmgqlquery({ + query: gql` + query( + $statecode: Int + $currentDate: DateTime + $evo_agent_accountid: Uuid + ) { + evo_reward_condition: evo_reward_conditions( + evo_agent_accountid: $evo_agent_accountid + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + statecode: $statecode + ) { + evo_reward_conditionid + evo_name + evo_reward_summ + evo_reduce_reward + } + } + `, + variables: { + evo_agent_accountid: dealerBrokerId, + currentDate, + statecode: 0, + }, + toOptions: ['evo_reward_condition'], + }).then(({ entities: { evo_reward_condition } }) => { + if (evo_reward_condition && Array.isArray(evo_reward_condition)) + calculationStore.setOptions( + 'selectDealerBrokerRewardСondition', + evo_reward_condition, + ); + }); + } + } else { + calculationStore.setValue('dealerBrokerRewardСondition', null); + calculationStore.setStatus( + 'selectDealerBrokerRewardСondition', + Status.Disabled, + ); + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { dealerBroker, dealerPerson } = calculationStore.values; + return [dealerBroker, dealerPerson]; + }, + effect: ([dealerBrokerId, dealerPersonId]) => { + if (dealerPersonId && !dealerBrokerId) { + calculationStore.setStatus( + 'selectDealerRewardСondition', + Status.Default, + ); - // 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); - // } - // } - // } - // }, - // }), + CalculationService.crmgqlquery({ + query: gql` + query( + $statecode: Int + $currentDate: DateTime + $evo_agent_accountid: Uuid + ) { + evo_reward_condition: evo_reward_conditions( + evo_agent_accountid: $evo_agent_accountid + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + statecode: $statecode + ) { + evo_reward_conditionid + evo_name + evo_reward_summ + evo_reduce_reward + } + } + `, + variables: { + evo_agent_accountid: dealerPersonId, + currentDate, + statecode: 0, + }, + toOptions: ['evo_reward_condition'], + }).then(({ entities: { evo_reward_condition } }) => { + if (evo_reward_condition && Array.isArray(evo_reward_condition)) + calculationStore.setOptions( + 'selectDealerRewardСondition', + evo_reward_condition, + ); + }); + } else { + calculationStore.setValue('dealerRewardСondition', null); + calculationStore.setStatus( + 'selectDealerRewardСondition', + Status.Disabled, + ); + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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); + } + } + } + }, + options: { + fireImmediately: true, + }, + }), - // 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 { 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, + ); + } + } + } + }, + options: { + fireImmediately: 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 { 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 { 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 { 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 => { + calculationStore.setStatus('selectModel', Status.Disabled); + calculationStore.setOptions('selectModel', []); + calculationStore.setValue('model', null); + + if (brandId) { + const brand = calculationStore.options.selectBrand?.find( + x => x.evo_brandid === brandId, + ); + if (brand) { + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $evo_brandid: Uuid) { + evo_model: evo_models( + statecode: $statecode + evo_brandid: $evo_brandid + ) { + evo_name + evo_modelid + evo_leasingobject_risk + evo_importer_reward_perc + evo_importer_reward_rub + evo_impairment_groupid + } + } + `, + variables: { + statecode: 0, + evo_brandid: brandId, + }, + toOptions: ['evo_model'], + }).then(({ entities }) => { + if ( + entities.evo_model && + Array.isArray(entities.evo_model) && + entities.evo_model.length > 0 + ) { + calculationStore.setStatus('selectModel', Status.Default); + calculationStore.setOptions('selectModel', entities.evo_model); + calculationStore.setValue('model', null); + } + }); + } + } + }, + options: { fireImmediately: true }, + }), // calculationStore => ({ // expression: () => { diff --git a/src/core/types/Calculation/Store/filters.ts b/src/core/types/Calculation/Store/filters.ts index 8b3ab9d..7218f9b 100644 --- a/src/core/types/Calculation/Store/filters.ts +++ b/src/core/types/Calculation/Store/filters.ts @@ -1,2 +1,5 @@ import { TCRMEntity } from 'core/types/Entities/crmEntities'; -export type TElementFilter = (options: TCRMEntity[]) => TCRMEntity[]; +import { IBaseOption } from 'core/types/Calculation/Store/options'; +export type TElementFilter = ( + options: (TCRMEntity & IBaseOption)[], +) => (TCRMEntity & IBaseOption)[];