diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 4f3b14d..f8f113b 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -1,7 +1,6 @@ import CalculationService from 'client/services/CalculationService'; import { IReactionEffect } from 'core/types/effect'; import { Status } from 'core/types/statuses'; -import { parse } from 'path'; const reactionEffects: IReactionEffect[] = [ calculationStore => ({ @@ -1024,19 +1023,21 @@ const reactionEffects: IReactionEffect[] = [ if (brokers && brokers.length > 0) { calculationStore.setOptions('selectDealerPerson', brokers); calculationStore.setValue('dealerPerson', brokers[0].accountid); + calculationStore.setStatus( + 'selectDealerPerson', + Status.Default, + ); } }) .catch(err => { throw err; }); - } else { - calculationStore.setOptions('selectDealerPerson', []); - calculationStore.setValue('dealerPerson', null); } - } else { - calculationStore.setOptions('selectDealerPerson', []); - calculationStore.setValue('dealerPerson', null); } + + calculationStore.setOptions('selectDealerPerson', []); + calculationStore.setValue('dealerPerson', null); + calculationStore.setStatus('selectDealerPerson', Status.Disabled); }, }), @@ -1062,18 +1063,106 @@ const reactionEffects: IReactionEffect[] = [ if (brokers && brokers.length > 0) { calculationStore.setOptions('selectDealerBroker', brokers); calculationStore.setValue('dealerBroker', brokers[0].accountid); + calculationStore.setStatus( + 'selectDealerBroker', + Status.Default, + ); } }) .catch(err => { throw err; }); - } else { - calculationStore.setOptions('selectDealerBroker', []); - calculationStore.setValue('dealerBroker', null); + } + } + + 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({ + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: dealerBrokerId, + }, + }) + .then(reward_conditions => { + calculationStore.setOptions( + 'selectDealerBrokerRewardСondition', + reward_conditions, + ); + }) + .catch(err => { + throw err; + }); } } else { - calculationStore.setOptions('selectDealerBroker', []); - calculationStore.setValue('dealerBroker', null); + 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({ + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: dealerPersonId, + }, + }) + .then(reward_conditions => { + calculationStore.setOptions( + 'selectDealerRewardСondition', + reward_conditions, + ); + }) + .catch(err => { + throw err; + }); + } else { + calculationStore.setValue('dealerRewardСondition', null); + calculationStore.setStatus( + 'selectDealerRewardСondition', + Status.Disabled, + ); } }, }), diff --git a/src/core/config/initialValues.ts b/src/core/config/initialValues.ts index 5538851..f5135e4 100644 --- a/src/core/config/initialValues.ts +++ b/src/core/config/initialValues.ts @@ -40,6 +40,13 @@ const initialValues: TValues = { leaseObjectUseFor: 100000000, dealerRewardSumm: 0, dealerBrokerRewardSumm: 0, + indAgent: null, + calcDoubleAgent: null, + calcBroker: null, + calcFinDepartment: null, + dealerPerson: null, + dealerBroker: null, + dealer: null, indAgentRewardSumm: 0, calcDoubleAgentRewardSumm: 0, calcBrokerRewardSum: 0, diff --git a/src/core/fakeData/entityFakes.ts b/src/core/fakeData/entityFakes.ts index a39da1d..32038d4 100644 --- a/src/core/fakeData/entityFakes.ts +++ b/src/core/fakeData/entityFakes.ts @@ -69,6 +69,8 @@ const REWARD_CONDITION_5_ID = faker.random.uuid(); const REWARD_CONDITION_6_ID = faker.random.uuid(); const REWARD_CONDITION_7_ID = faker.random.uuid(); const REWARD_CONDITION_8_ID = faker.random.uuid(); +const REWARD_CONDITION_9_ID = faker.random.uuid(); +const REWARD_CONDITION_10_ID = faker.random.uuid(); const EVO_CONNECTION_ROLE_1_ID = faker.random.uuid(); const EVO_CONNECTION_ROLE_2_ID = faker.random.uuid(); @@ -436,6 +438,21 @@ const entityFakeData: { evo_reward_summ: 4, evo_reduce_reward: true, }, + { + statecode: 0, + evo_agent_accountid: ACCOUNT_11_ID, + evo_reward_conditionid: REWARD_CONDITION_9_ID, + evo_name: '3%', + evo_reward_summ: 3, + }, + { + statecode: 0, + evo_agent_accountid: ACCOUNT_11_ID, + evo_reward_conditionid: REWARD_CONDITION_10_ID, + evo_name: 'Не более 6%', + evo_reward_summ: 6, + evo_reduce_reward: true, + }, ], connection: [ {