This repository has been archived on 2025-05-09. You can view files and clone it, but cannot push or open issues or pull requests.
2020-09-29 17:08:30 +03:00

1731 lines
56 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { openNotification } from 'client/Elements/Notification';
import CalculationService from 'client/services/CalculationService';
import { IReactionEffect } from 'core/types/effect';
import { Status } from 'core/types/statuses';
import { calculatePerc, calculateRub } from './lib/tools';
const reactionEffects: IReactionEffect[] = [
calculationStore => ({
expression: () => {
const { values } = calculationStore;
return values.lead;
},
effect: async leadId => {
if (!leadId) {
calculationStore.setValue('opportunity', null);
return;
}
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 => {
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({
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 { 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({
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', 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;
}
}
}
},
}),
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({
entityName: 'account',
where: {
accountid: dealer.evo_broker_accountid,
},
})
.then(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({
entityName: 'account',
where: {
statecode: 0,
accountid: dealerPerson.evo_broker_accountid,
},
})
.then(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({
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.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,
);
}
},
}),
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({
entityName: 'evo_model',
where: {
statecode: 0,
evo_brandid: brandId,
},
}).then(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({
entityName: 'evo_equipment',
where: {
statecode: 0,
evo_modelid: modelId,
},
}).then(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.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',
);
},
}),
];
export default reactionEffects;