577 lines
18 KiB
TypeScript
577 lines
18 KiB
TypeScript
import CalculationService from 'client/services/CalculationService';
|
|
import { IReactionEffect } from 'core/types/effect';
|
|
import { Status } from 'core/types/statuses';
|
|
|
|
const reactionEffects: IReactionEffect[] = [
|
|
calculationStore => ({
|
|
expression: () => {
|
|
const { values } = calculationStore;
|
|
return values.lead;
|
|
},
|
|
effect: async leadId => {
|
|
const lead = calculationStore.options.selectLead?.find(
|
|
x => x.leadid === leadId,
|
|
);
|
|
|
|
if (lead) {
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'opportunity',
|
|
where: { opportunityid: lead.evo_opportunityid || null },
|
|
})
|
|
.then(opportunities => {
|
|
if (opportunities) {
|
|
calculationStore.setOptions('selectOpportunity', opportunities);
|
|
calculationStore.setValue(
|
|
'opportunity',
|
|
opportunities[0] ? opportunities[0].opportunityid : null,
|
|
);
|
|
}
|
|
})
|
|
.catch(err => {
|
|
throw err;
|
|
});
|
|
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'quote',
|
|
where: {
|
|
evo_leadid: leadId || null,
|
|
},
|
|
})
|
|
.then(quotes => {
|
|
calculationStore.setOptions('selectQuote', quotes);
|
|
if (quotes.length === 0) calculationStore.setValue('quote', null);
|
|
})
|
|
.catch(err => {
|
|
throw err;
|
|
});
|
|
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'account',
|
|
where: {
|
|
accountid: lead.evo_agent_accountid || null,
|
|
},
|
|
})
|
|
.then(agents => {
|
|
calculationStore.setOptions('selectIndAgent', agents);
|
|
calculationStore.setValue(
|
|
'indAgent',
|
|
agents[0] ? agents[0].accountid : null,
|
|
);
|
|
})
|
|
.catch(err => {
|
|
throw err;
|
|
});
|
|
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'account',
|
|
where: {
|
|
accountid: lead.evo_double_agent_accountid || null,
|
|
},
|
|
})
|
|
.then(doubleAgents => {
|
|
calculationStore.setOptions('selectCalcDoubleAgent', doubleAgents);
|
|
calculationStore.setValue(
|
|
'calcDoubleAgent',
|
|
doubleAgents[0] ? doubleAgents[0].accountid : null,
|
|
);
|
|
})
|
|
.catch(err => {
|
|
throw err;
|
|
});
|
|
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'account',
|
|
where: {
|
|
accountid: lead.evo_broker_accountid || null,
|
|
},
|
|
})
|
|
.then(brokers => {
|
|
calculationStore.setOptions('selectCalcBroker', brokers);
|
|
calculationStore.setValue(
|
|
'calcBroker',
|
|
brokers[0] ? brokers[0].accountid : null,
|
|
);
|
|
})
|
|
.catch(err => {
|
|
throw err;
|
|
});
|
|
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'account',
|
|
where: {
|
|
accountid: lead.evo_fin_department_accountid || null,
|
|
},
|
|
})
|
|
.then(finDepartments => {
|
|
calculationStore.setOptions(
|
|
'selectCalcFinDepartment',
|
|
finDepartments,
|
|
);
|
|
calculationStore.setValue(
|
|
'calcFinDepartment',
|
|
finDepartments[0] ? finDepartments[0].accountid : null,
|
|
);
|
|
})
|
|
.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,
|
|
);
|
|
} else {
|
|
CalculationService.getEntityOptions({
|
|
entityName: 'account',
|
|
where: { accountid: opportunity.evo_accountid },
|
|
}).then(accounts => {
|
|
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({
|
|
entityName: 'account',
|
|
where: { accountid: lead.account },
|
|
}).then(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 { 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({
|
|
entityName: 'evo_reward_condition',
|
|
where: {
|
|
statecode: 0,
|
|
// TODO < > текущей даты
|
|
// evo_datefrom: new Date(),
|
|
// evo_dateto: new Date(),
|
|
evo_agent_accountid: indAgentId,
|
|
},
|
|
})
|
|
.then(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({
|
|
entityName: 'evo_reward_condition',
|
|
where: {
|
|
statecode: 0,
|
|
// TODO < > текущей даты
|
|
// evo_datefrom: new Date(),
|
|
// evo_dateto: new Date(),
|
|
evo_agent_accountid: doubleAgentId,
|
|
},
|
|
})
|
|
.then(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({
|
|
entityName: 'evo_reward_condition',
|
|
where: {
|
|
statecode: 0,
|
|
// TODO < > текущей даты
|
|
// evo_datefrom: new Date(),
|
|
// evo_dateto: new Date(),
|
|
evo_agent_accountid: calcFinDepartmentId,
|
|
},
|
|
})
|
|
.then(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({
|
|
entityName: 'evo_reward_condition',
|
|
where: {
|
|
statecode: 0,
|
|
// TODO < > текущей даты
|
|
// evo_datefrom: new Date(),
|
|
// evo_dateto: new Date(),
|
|
evo_agent_accountid: calcBrokerId,
|
|
},
|
|
})
|
|
.then(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', null);
|
|
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 { 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;
|
|
}
|
|
},
|
|
}),
|
|
];
|
|
|
|
export default reactionEffects;
|