merge refactor/store-functions

This commit is contained in:
Chika 2021-04-14 16:00:37 +03:00
parent e36a5e3b52
commit d85e751ec2
15 changed files with 527 additions and 541 deletions

View File

@ -1,8 +1,9 @@
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
import initialFilters from 'client/stores/CalculationStore/config/initialFilters';
import initialOptions from 'client/stores/CalculationStore/config/initialOptions';
import initialStatuses from 'client/stores/CalculationStore/config/initialStatuses';
import initialValues from 'client/stores/CalculationStore/config/initialValues';
import { isNil, mergeWith } from 'lodash';
import { find, isNil, mergeWith } from 'lodash';
const valuesData = {
values: initialValues,
@ -43,8 +44,40 @@ const valuesActions = {
this.validations[elementName] = validation;
},
getOptions(elementName) {
return this.options[elementName];
getOption(elementName, fields) {
if (!this.options.elementName) {
return;
}
if (!fields) {
return this.getCurrentOption(elementName);
}
return this.options[elementName].find(option => {
return Object.keys(fields).every(
fieldName => option[fieldName] === fields[fieldName],
);
});
},
getOptions(elementName, fields) {
if (!this.options.elementName) {
return;
}
if (!fields) return this.options[elementName];
return this.options[elementName].filter(option => {
return Object.keys(fields).every(
fieldName => option[fieldName] === fields[fieldName],
);
});
},
getCurrentOption(elementName) {
const valueName = elementsValues[elementName];
const currentValue = this.values[valueName];
if (!currentValue) {
return;
}
const currentOption = this.options[elementName].find(
x => x.value === currentValue,
);
return currentOption;
},
setOptions(elementName, options) {
this.options[elementName] = options;

View File

@ -4,16 +4,11 @@ export default ({
}: {
calculationStore: ICalculationStore;
}): any => {
const selectedTarifId = calculationStore.values.tarif;
if (selectedTarifId) {
const tarif = calculationStore.options.selectTarif?.find(
x => x.evo_tarifid === selectedTarifId,
);
if (tarif) {
return {
minCashflowMSFONominal: tarif.evo_min_irr,
maxCashflowMSFONominal: tarif.evo_max_irr,
};
}
const tarif = calculationStore.getOption('selectTarif');
if (tarif) {
return {
minCashflowMSFONominal: tarif.evo_min_irr,
maxCashflowMSFONominal: tarif.evo_max_irr,
};
}
};

View File

@ -194,21 +194,16 @@ const validatePaymentsTable = () => {
return;
}
const highSeasonStart = parseInt(
CalculationStore.options.selectHighSeasonStart?.find(
x => x.value === highSeasonStartId,
)?.name || '2',
CalculationStore.getOption('selectHighSeasonStart')?.name || '2',
);
const shiftNumber = highSeasonStart - 2;
const middleRows = payments.slice(1, PERIODS_NUMBER + 1);
const unshiftedMiddleRows = shiftRight(middleRows, shiftNumber);
const { seasonType } = CalculationStore.values;
if (!seasonType) {
const seasonTypeOptions = CalculationStore.getOption('selectSeasonType');
if (!seasonTypeOptions) {
return;
}
const seasonTypeOptions = CalculationStore.options.selectSeasonType?.find(
x => x.value === seasonType,
);
const startPositions =
seasonTypeOptions && seasonTypeOptions.startPositions;

View File

@ -91,7 +91,7 @@ export default async () => {
});
}
CalculationStore.setValue('recalcWithRevision', false);
let quotes = toJS(CalculationStore.options.selectQuote);
let quotes = toJS(CalculationStore.getOptions('selectQuote'));
quotes = [new_quote].concat(quotes);
const { quote: selected_quoteid } = CalculationStore.values;

View File

@ -145,8 +145,11 @@ const autorunEffects: IAutorunEffect[] = [
return;
}
const leaseObjectType = calculationStore.options.selectLeaseObjectType?.find(
x => x.evo_leasingobject_typeid === leaseObjectTypeId,
const leaseObjectType = calculationStore.getOption(
'selectLeaseObjectType',
{
evo_leasingobject_typeid: leaseObjectTypeId,
},
);
if (leaseObjectType) {

View File

@ -8,64 +8,52 @@ const LEASE_OBJECT_RISK = {
const computedEffects = {
// leadName() {
// const leadId = this.values.lead;
// const leadid = this.values.lead;
// if (this.options.selectLead && this.options.selectLead.length) {
// const lead = this.options.selectLead?.find(x => x.leadid === leadId);
// const lead = this.getOption('selectLead', { leadid });
// if (lead) {
// return lead.name;
// }
// }
// },
// opportunityName() {
// const opportunityId = this.values.opportunity;
// const opportunityid = this.values.opportunity;
// if (
// this.options.selectOpportunity &&
// this.options.selectOpportunity.length > 0
// ) {
// const opportunity = this.options.selectOpportunity?.find(
// x => x.opportunityid === opportunityId,
// );
// const opportunity = this.getOption('selectOpportunity', {
// opportunityid,
// });
// if (opportunity) {
// return opportunity.name;
// }
// }
// },
leaseObjectRiskName() {
const configurationId = this.values.configuration;
if (configurationId) {
const configuration = this.options.selectConfiguration?.find(
x => x.evo_equipmentid === configurationId,
);
if (configuration) {
if (configuration.evo_leasingobject_risk) {
const res = LEASE_OBJECT_RISK[configuration.evo_leasingobject_risk];
return res;
}
const configuration = this.getOption('selectConfiguration');
if (configuration) {
if (configuration.evo_leasingobject_risk) {
const res = LEASE_OBJECT_RISK[configuration.evo_leasingobject_risk];
return res;
}
}
const modelId = this.values.model;
if (modelId) {
const model = this.options.selectModel?.find(
x => x.evo_modelid === modelId,
);
if (model) {
const evo_leasingobject_risk = model.evo_leasingobject_risk;
return LEASE_OBJECT_RISK[evo_leasingobject_risk];
}
const model = this.getOption('selectModel');
if (model) {
const evo_leasingobject_risk = model.evo_leasingobject_risk;
return LEASE_OBJECT_RISK[evo_leasingobject_risk];
}
},
insKaskoPriceLeasePeriod() {
return customValues.insKaskoPriceLeasePeriod.call(this).toFixed(2);
},
irrInfo() {
const tarif = this.options.selectTarif?.find(
x => x.evo_tarifid === this.values.tarif,
);
const tarif = this.getOption('selectTarif');
if (tarif) {
return `Min: ${tarif.evo_min_irr}% - Max: ${tarif.evo_max_irr}%`;
}
return '-'
return '-';
},
};

View File

@ -85,17 +85,20 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
let accountidData;
if (lead) {
const selected_lead = calculationStore.options.selectLead?.find(
x => x.value === lead,
);
const selected_lead = calculationStore.getOptions('selectLead', {
value: lead,
});
if (selected_lead && selected_lead.accountidData) {
accountidData = selected_lead.accountidData;
}
}
if (opportunity) {
const selected_opportunity = calculationStore.options.selectOpportunity?.find(
x => x.value === opportunity,
const selected_opportunity = calculationStore.getOption(
'selectOpportunity',
{
value: opportunity,
},
);
if (selected_opportunity && selected_opportunity.accountidData) {
accountidData = selected_opportunity.accountidData;
@ -110,8 +113,11 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
}
if (evo_region_fias_id) {
const region = calculationStore.options.selectRegionRegistration?.find(
x => x.evo_fias_id === evo_region_fias_id,
const region = calculationStore.getOption(
'selectRegionRegistration',
{
evo_fias_id: evo_region_fias_id,
},
);
if (region) {
regionRegistration = region.evo_regionid;
@ -196,9 +202,9 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
]);
if (evo_city_fias_id) {
const city = calculationStore.options.selectTownRegistration?.find(
x => x.evo_fias_id === evo_city_fias_id,
);
const city = calculationStore.getOption('selectTownRegistration', {
evo_fias_id: evo_city_fias_id,
});
if (city) {
townRegistration = city.evo_townid;
}
@ -237,9 +243,9 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
},
]);
const base_product = calculationStore?.options?.selectProduct?.find(
x => x.evo_baseproductid === newValues.product,
);
const base_product = calculationStore.getOption('selectProduct', {
evo_baseproductid: newValues.product,
});
const addProducts = Object.assign(
{},
@ -266,13 +272,16 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
const {
evo_programsolution,
evo_client_riskid,
} = calculationStore.options.selectOpportunity?.find(
x => x.value === opportunity,
);
} = calculationStore.getOption('selectOpportunity', {
value: opportunity,
});
if (evo_programsolution === 100000000) {
const midClientRisk = calculationStore.options.selectClientRisk?.find(
x => x.evo_id === '2',
const midClientRisk = calculationStore.getOption(
'selectClientRisk',
{
evo_id: '2',
},
);
if (midClientRisk) {
clientRisk = midClientRisk.evo_client_riskid;

View File

@ -24,10 +24,10 @@ const reactionEffects: IReactionEffect[] = [
const { opportunity } = calculationStore.values;
return opportunity;
},
effect: opportunityId => {
const opportunity = calculationStore.options.selectOpportunity?.find(
x => x.opportunityid === opportunityId,
);
effect: opportunityid => {
const opportunity = calculationStore.getOption('selectOpportunity', {
opportunityid,
});
if (opportunity) {
calculationStore.setValue('lead', opportunity.evo_leadid);
@ -173,22 +173,20 @@ const reactionEffects: IReactionEffect[] = [
ElementStatus.Disabled,
);
const leadId = calculationStore.values.lead;
if (leadId) {
const lead = calculationStore.options.selectLead?.find(
x => x.leadid === leadId,
const lead = calculationStore.getOption('selectLead');
if (lead && !lead.evo_double_agent_accountid) {
calculationStore.setValue('calcDoubleAgent', null);
calculationStore.setStatus(
'selectCalcDoubleAgent',
ElementStatus.Disabled,
);
if (lead && !lead.evo_double_agent_accountid) {
calculationStore.setValue('calcDoubleAgent', null);
calculationStore.setStatus(
'selectCalcDoubleAgent',
ElementStatus.Disabled,
);
}
}
} else {
const indAgentRewardCondition = calculationStore.options.selectIndAgentRewardCondition?.find(
x => x.evo_reward_conditionid === indAgentRewardConditionId,
const indAgentRewardCondition = calculationStore.getOption(
'selectIndAgentRewardCondition',
{
evo_reward_conditionid: indAgentRewardConditionId,
},
);
if (indAgentRewardCondition) {
if (calculationProcess.process !== Process.LoadKp) {
@ -206,10 +204,12 @@ const reactionEffects: IReactionEffect[] = [
'selectCalcDoubleAgent',
ElementStatus.Default,
);
const doubleAgent = calculationStore.options.selectCalcDoubleAgent?.find(
x =>
x.accountid ===
indAgentRewardCondition?.evo_double_agent_accountid,
const doubleAgent = calculationStore.getOption(
'selectCalcDoubleAgent',
{
accountid: indAgentRewardCondition?.evo_double_agent_accountid,
},
);
if (doubleAgent) {
calculationStore.setOptions('selectCalcDoubleAgent', [
@ -248,22 +248,26 @@ const reactionEffects: IReactionEffect[] = [
ElementStatus.Disabled,
);
} else {
const calcDoubleAgentRewardCondition = calculationStore.options.selectCalcDoubleAgentRewardCondition?.find(
x => x.evo_reward_conditionid === calcDoubleAgentRewardConditionId,
const calcDoubleAgentRewardCondition = calculationStore.getOption(
'selectCalcDoubleAgentRewardCondition',
{
evo_reward_conditionid: calcDoubleAgentRewardConditionId,
},
);
if (calcDoubleAgentRewardCondition) {
if (calcDoubleAgentRewardCondition.evo_reward_summ) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'calcDoubleAgentRewardSumm',
calcDoubleAgentRewardCondition.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxCalcDoubleAgentRewardSumm',
ElementStatus.Default,
if (
calcDoubleAgentRewardCondition &&
calcDoubleAgentRewardCondition.evo_reward_summ
) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'calcDoubleAgentRewardSumm',
calcDoubleAgentRewardCondition.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxCalcDoubleAgentRewardSumm',
ElementStatus.Default,
);
}
}
},
@ -272,6 +276,7 @@ const reactionEffects: IReactionEffect[] = [
},
}),
//TODO: compose
(calculationStore, calculationProcess) => ({
expression: () => {
const { calcBrokerRewardCondition } = calculationStore.values;
@ -285,22 +290,26 @@ const reactionEffects: IReactionEffect[] = [
ElementStatus.Disabled,
);
} else {
const calcBrokerRewardCondition = calculationStore.options.selectCalcBrokerRewardCondition?.find(
x => x.evo_reward_conditionid === calcBrokerRewardConditionId,
const calcBrokerRewardCondition = calculationStore.getOption(
'selectCalcBrokerRewardCondition',
{
evo_reward_conditionid: calcBrokerRewardConditionId,
},
);
if (calcBrokerRewardCondition) {
if (calcBrokerRewardCondition.evo_reward_summ) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'calcBrokerRewardSum',
calcBrokerRewardCondition.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxCalcBrokerRewardSum',
ElementStatus.Default,
if (
calcBrokerRewardCondition &&
calcBrokerRewardCondition.evo_reward_summ
) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'calcBrokerRewardSum',
calcBrokerRewardCondition.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxCalcBrokerRewardSum',
ElementStatus.Default,
);
}
}
},
@ -322,22 +331,24 @@ const reactionEffects: IReactionEffect[] = [
ElementStatus.Disabled,
);
} else {
const finDepartmentRewardCondtion = calculationStore.options.selectFinDepartmentRewardCondtion?.find(
x => x.evo_reward_conditionid === finDepartmentRewardCondtionId,
const finDepartmentRewardCondtion = calculationStore.getOption(
'selectFinDepartmentRewardCondtion',
{ evo_reward_conditionid: finDepartmentRewardCondtionId },
);
if (finDepartmentRewardCondtion) {
if (finDepartmentRewardCondtion.evo_reward_summ) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'finDepartmentRewardSumm',
finDepartmentRewardCondtion.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxFinDepartmentRewardSumm',
ElementStatus.Default,
if (
finDepartmentRewardCondtion &&
finDepartmentRewardCondtion.evo_reward_summ
) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'finDepartmentRewardSumm',
finDepartmentRewardCondtion.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxFinDepartmentRewardSumm',
ElementStatus.Default,
);
}
}
},
@ -352,16 +363,29 @@ const reactionEffects: IReactionEffect[] = [
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) {
const indAgentRewardCondition = calculationStore.getOption(
'selectIndAgentRewardCondition',
);
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) >
parseFloat(indAgentRewardSumm) <
indAgentRewardCondition.evo_reward_summ
) {
calculationStore.setValidation('tbxIndAgentRewardSumm', false);
@ -369,29 +393,12 @@ const reactionEffects: IReactionEffect[] = [
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение агента ФЛ указано больше условия по агентскому договору! \nЗначение установлено по условию договора.',
'Вознаграждение агента ФЛ указано меньше условия по агентскому договору! \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.setValidation('tbxIndAgentRewardSumm', true);
}
}
},
@ -403,16 +410,32 @@ const reactionEffects: IReactionEffect[] = [
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) {
const selectCalcDoubleAgentRewardCondition = calculationStore.getOption(
'selectCalcDoubleAgentRewardCondition',
);
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) >
parseFloat(calcDoubleAgentRewardSumm) <
selectCalcDoubleAgentRewardCondition.evo_reward_summ
) {
calculationStore.setValidation(
@ -423,35 +446,12 @@ const reactionEffects: IReactionEffect[] = [
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение двойного агента указано больше условия по агентскому договору! \nЗначение установлено по условию договора.',
'Вознаграждение двойного агента указано меньше условия по агентскому договору! \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.setValidation('tbxCalcDoubleAgentRewardSumm', true);
}
}
},
@ -463,16 +463,29 @@ const reactionEffects: IReactionEffect[] = [
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) {
const selectCalcBrokerRewardCondition = calculationStore.getOption(
'selectCalcBrokerRewardCondition',
);
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) >
parseFloat(calcBrokerRewardSum) <
selectCalcBrokerRewardCondition.evo_reward_summ
) {
calculationStore.setValidation('tbxCalcBrokerRewardSum', false);
@ -480,29 +493,12 @@ const reactionEffects: IReactionEffect[] = [
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение брокера указано больше условия по агентскому договору! \nЗначение установлено по условию договора.',
'Вознаграждение брокера указано меньше условия по агентскому договору! \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.setValidation('tbxCalcBrokerRewardSum', true);
}
}
},
@ -514,53 +510,44 @@ const reactionEffects: IReactionEffect[] = [
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);
const selectFinDepartmentRewardCondtion = calculationStore.getOption(
'selectFinDepartmentRewardCondtion',
);
if (
selectFinDepartmentRewardCondtion &&
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);
}
},
}),
@ -953,8 +940,9 @@ const reactionEffects: IReactionEffect[] = [
ElementStatus.Disabled,
);
} else {
const dealerRewardContition = calculationStore.options.selectDealerRewardCondition?.find(
x => x.evo_reward_conditionid === dealerRewardConditionId,
const dealerRewardContition = calculationStore.getOption(
'selectDealerRewardCondition',
{ evo_reward_conditionid: dealerRewardConditionId },
);
if (dealerRewardContition) {
if (dealerRewardContition.evo_reward_summ) {
@ -1008,22 +996,24 @@ const reactionEffects: IReactionEffect[] = [
ElementStatus.Disabled,
);
} else {
const dealerBrokerRewardContition = calculationStore.options.selectDealerBrokerRewardCondition?.find(
x => x.evo_reward_conditionid === dealerBrokerRewardConditionId,
const dealerBrokerRewardContition = calculationStore.getOption(
'selectDealerBrokerRewardCondition',
{ evo_reward_conditionid: dealerBrokerRewardConditionId },
);
if (dealerBrokerRewardContition) {
if (dealerBrokerRewardContition.evo_reward_summ) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'dealerBrokerRewardSumm',
dealerBrokerRewardContition.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxDealerBrokerRewardSumm',
ElementStatus.Default,
if (
dealerBrokerRewardContition &&
dealerBrokerRewardContition.evo_reward_summ
) {
if (calculationProcess.process !== Process.LoadKp) {
calculationStore.setValue(
'dealerBrokerRewardSumm',
dealerBrokerRewardContition.evo_reward_summ,
);
}
calculationStore.setStatus(
'tbxDealerBrokerRewardSumm',
ElementStatus.Default,
);
}
}
},
@ -1038,47 +1028,39 @@ const reactionEffects: IReactionEffect[] = [
return dealerRewardSumm;
},
effect: dealerRewardSumm => {
const dealerRewardConditionId =
calculationStore.values.dealerRewardCondition;
if (dealerRewardConditionId) {
const dealerRewardCondition = calculationStore.options.selectDealerRewardCondition?.find(
x => x.evo_reward_conditionid === dealerRewardConditionId,
);
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);
const dealerRewardCondition = calculationStore.getOption(
'selectDealerRewardCondition',
);
if (dealerRewardCondition && 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);
}
},
}),
@ -1089,54 +1071,44 @@ const reactionEffects: IReactionEffect[] = [
return dealerBrokerRewardSumm;
},
effect: dealerBrokerRewardSumm => {
const dealerBrokerRewardConditionId =
calculationStore.values.dealerBrokerRewardCondition;
if (dealerBrokerRewardConditionId) {
const dealerBrokerRewardCondition = calculationStore.options.selectDealerBrokerRewardCondition?.find(
x => x.evo_reward_conditionid === dealerBrokerRewardConditionId,
);
if (dealerBrokerRewardCondition) {
if (dealerBrokerRewardCondition.evo_reward_summ) {
if (
parseFloat(dealerBrokerRewardSumm) >
dealerBrokerRewardCondition.evo_reward_summ
) {
calculationStore.setValidation(
'tbxDealerBrokerRewardSumm',
false,
);
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение брокера поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.',
})();
return;
}
}
const dealerBrokerRewardCondition = calculationStore.getOption(
'selectDealerBrokerRewardCondition',
);
if (dealerBrokerRewardCondition) {
if (dealerBrokerRewardCondition.evo_reward_summ) {
if (
!dealerBrokerRewardCondition.evo_reduce_reward &&
parseFloat(dealerBrokerRewardSumm) >
dealerBrokerRewardCondition.evo_reward_summ
) {
if (
parseFloat(dealerBrokerRewardSumm) <
dealerBrokerRewardCondition.evo_reward_summ
) {
calculationStore.setValidation(
'tbxDealerBrokerRewardSumm',
false,
);
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение брокера поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.',
})();
return;
}
calculationStore.setValidation('tbxDealerBrokerRewardSumm', false);
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение брокера поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.',
})();
return;
}
calculationStore.setValidation('tbxDealerBrokerRewardSumm', true);
}
if (
!dealerBrokerRewardCondition.evo_reduce_reward &&
dealerBrokerRewardCondition.evo_reward_summ
) {
if (
parseFloat(dealerBrokerRewardSumm) <
dealerBrokerRewardCondition.evo_reward_summ
) {
calculationStore.setValidation('tbxDealerBrokerRewardSumm', false);
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Вознаграждение брокера поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.',
})();
return;
}
}
calculationStore.setValidation('tbxDealerBrokerRewardSumm', true);
}
},
}),
@ -1147,18 +1119,20 @@ const reactionEffects: IReactionEffect[] = [
return saleBonus;
},
effect: saleBonus => {
const systemuser = calculationStore?.staticData?.systemuser;
const systemuser = calculationStore.getStaticData('systemuser');
if (systemuser) {
const evo_sot_coefficient_type = calculationStore?.staticData?.evo_sot_coefficient_type?.find(
x => x.evo_id === 'BONUS_LEASING',
);
const evo_coefficient_bonus = calculationStore?.staticData?.evo_coefficient?.find(
x =>
x.evo_job_titleid === systemuser[0].evo_job_titleid &&
x.evo_sot_coefficient_typeid ===
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
);
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'BONUS_LEASING');
const evo_coefficient_bonus = calculationStore
.getStaticData('evo_coefficient')
.find(
x =>
x.evo_job_titleid === systemuser[0].evo_job_titleid &&
x.evo_sot_coefficient_typeid ===
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
);
if (
evo_coefficient_bonus &&
@ -1207,37 +1181,19 @@ const reactionEffects: IReactionEffect[] = [
},
effect: ([modelId, configurationId]) => {
if (configurationId) {
const configuration = calculationStore.options.selectConfiguration?.find(
x => x.evo_equipmentid === configurationId,
const configuration = calculationStore.getOption(
'selectConfiguration',
{
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) {
if (configuration && 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 === model.evo_impairment_groupid,
x =>
x.evo_impairment_groupid === configuration.evo_impairment_groupid,
);
calculationStore.setValue(
'depreciationGroup',
@ -1245,6 +1201,23 @@ const reactionEffects: IReactionEffect[] = [
);
return;
}
}
const model = calculationStore.getOption('selectModel', {
evo_modelid: modelId,
});
if (model && 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);
},
}),
@ -1295,12 +1268,12 @@ const reactionEffects: IReactionEffect[] = [
},
effect: ([brandId, modelId, leaseObjectUsed]) => {
if (leaseObjectUsed === false) {
const model = calculationStore.options.selectModel?.find(
x => x.evo_modelid === modelId,
);
const brand = calculationStore.options.selectBrand?.find(
x => x.evo_brandid === brandId,
);
const model = calculationStore.getOption('selectModel', {
evo_modelid: modelId,
});
const brand = calculationStore.getOption('selectBrand', {
evo_brandid: brandId,
});
if (
model &&
@ -1363,7 +1336,7 @@ const reactionEffects: IReactionEffect[] = [
},
}),
//TODO
// // TODO
// calculationStore => ({
// expression: () => {
// const { product } = calculationStore.values;
@ -1371,9 +1344,9 @@ const reactionEffects: IReactionEffect[] = [
// },
// effect: productId => {
// if (productId) {
// const product = calculationStore.options.selectProduct?.find(
// x => x.evo_id === productId,
// );
// const product = calculationStore.getOption('selectProduct', {
// evo_id: productId,
// });
// if (
// product &&
// product.evo_leasingobject_types &&
@ -1395,12 +1368,15 @@ const reactionEffects: IReactionEffect[] = [
},
effect: productId => {
if (productId) {
const product = calculationStore.options.selectProduct?.find(
x => x.evo_id === productId,
);
const product = calculationStore.getOption('selectProduct', {
evo_id: productId,
});
if (product) {
const registraction_2020_3 = calculationStore.options.selectRegistration?.find(
x => x.evo_id === '2020_3',
const registraction_2020_3 = calculationStore.getOption(
'selectRegionRegistration',
{
evo_id: '2020_3',
},
);
if (registraction_2020_3) {
calculationStore.setValue(
@ -1420,10 +1396,9 @@ const reactionEffects: IReactionEffect[] = [
},
effect: ({ product_evo_id, leasingPeriod }) => {
if (product_evo_id && leasingPeriod) {
const product = calculationStore.options.selectProduct?.find(
x => x.evo_id === product_evo_id,
);
const product = calculationStore.getOption('selectProduct', {
evo_id: product_evo_id,
});
if (product) {
const tarif = calculationStore.options.selectTarif?.find(
x =>
@ -1451,9 +1426,9 @@ const reactionEffects: IReactionEffect[] = [
return;
}
const tarif = calculationStore.options.selectTarif?.find(
x => x.evo_tarifid === tarif_evo_id,
);
const tarif = calculationStore.getOption('selectTarif', {
evo_tarifid: tarif_evo_id,
});
if (tarif) {
calculationStore.setValue('IRR_Perc', tarif.evo_irr);
@ -1509,11 +1484,7 @@ const reactionEffects: IReactionEffect[] = [
return;
}
const { technicalCard: technicalCardId } = calculationStore.values;
const technicalCard = calculationStore.options.selectTechnicalCard?.find(
x => x.evo_addproduct_typeid === technicalCardId,
);
const technicalCard = calculationStore.getOption('selectTechnicalCard');
if (technicalCard) {
const selectTechnicalCard_filter = calculationStore.getFilter(
@ -1542,6 +1513,7 @@ const reactionEffects: IReactionEffect[] = [
},
}),
//TODO: global setFilter => reset Value
calculationStore => ({
expression: () => {
const { selectLeaseObjectCategory } = calculationStore.filters;
@ -1551,7 +1523,7 @@ const reactionEffects: IReactionEffect[] = [
const { leaseObjectCategory } = calculationStore.values;
if (
!selectLeaseObjectCategoryFilter(
calculationStore.options.selectLeaseObjectCategory,
calculationStore.getOptions('selectLeaseObjectCategory'),
).some(x => x.value === leaseObjectCategory)
) {
calculationStore.setValue('leaseObjectCategory', null);
@ -1578,8 +1550,11 @@ const reactionEffects: IReactionEffect[] = [
return;
}
const leaseObjectType = calculationStore.options.selectLeaseObjectType?.find(
x => x.evo_leasingobject_typeid === leaseObjectTypeId,
const leaseObjectType = calculationStore.getOption(
'selectLeaseObjectType',
{
evo_leasingobject_typeid: leaseObjectTypeId,
},
);
if (leaseObjectType) {

View File

@ -244,7 +244,7 @@ export default [
const { supplierCurrency: supplierCurrencyId } = calculationStore.values;
const supplierCurrency = calculationStore
.getOptions('selectSupplierCurrency')
.find(x => x.transactioncurrencyid === supplierCurrencyId);
?.find(x => x.transactioncurrencyid === supplierCurrencyId);
const evo_currencychange = calculationStore
.getStaticData('evo_currencychange')
?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
@ -281,7 +281,7 @@ export default [
const { supplierCurrency: supplierCurrencyId } = calculationStore.values;
const supplierCurrency = calculationStore
.getOptions('selectSupplierCurrency')
.find(x => x.transactioncurrencyid === supplierCurrencyId);
?.find(x => x.transactioncurrencyid === supplierCurrencyId);
const evo_currencychange = calculationStore
.getStaticData('evo_currencychange')
?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);

View File

@ -36,7 +36,7 @@ const reactionEffects: IReactionEffect[] = [
}
const supplierCurrency = calculationStore
.getOptions('selectSupplierCurrency')
.find(x => x.transactioncurrencyid === supplierCurrencyId);
?.find(x => x.transactioncurrencyid === supplierCurrencyId);
const evo_currencychange = calculationStore
.getStaticData('evo_currencychange')
?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
@ -112,7 +112,7 @@ const reactionEffects: IReactionEffect[] = [
const supplierCurrency = calculationStore
.getOptions('selectSupplierCurrency')
.find(x => x.transactioncurrencyid === supplierCurrencyId);
?.find(x => x.transactioncurrencyid === supplierCurrencyId);
const evo_currencychange = calculationStore
.getStaticData('evo_currencychange')
?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
@ -124,11 +124,7 @@ const reactionEffects: IReactionEffect[] = [
evo_currencychangeValue,
);
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
const quote = calculationStore.getOption('selectQuote');
if (quote && quote.evo_max_price_change) {
if (price - supplierDiscountRub > quote.evo_max_price_change) {
calculationStore.setValidation('tbxLeaseObjectPrice', false);
@ -157,10 +153,7 @@ const reactionEffects: IReactionEffect[] = [
return;
}
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.quoteid === quoteId,
);
const quote = calculationStore.getOption('selectQuote');
if (quote && quote.evo_approved_first_payment) {
if (firstPaymentPerc < quote.evo_approved_first_payment) {
calculationStore.setValidation('tbxFirstPaymentPerc', false);
@ -188,11 +181,7 @@ const reactionEffects: IReactionEffect[] = [
return;
}
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.quoteid === quoteId,
);
const quote = calculationStore.getOption('selectQuote');
if (quote && quote.evo_recalc_limit) {
if (leaseObjectCount > quote.evo_recalc_limit) {
calculationStore.setValidation('tbxLeaseObjectCount', false);
@ -214,10 +203,8 @@ const reactionEffects: IReactionEffect[] = [
const { quote, recalcWithRevision } = calculationStore.values;
return [quote, recalcWithRevision];
},
effect: ([quoteId, recalcWithRevision]) => {
const quote = calculationStore.options.selectQuote?.find(
x => x.quoteid === quoteId,
);
effect: ([quoteid, recalcWithRevision]) => {
const quote = calculationStore.getOption('selectQuote', { quoteid });
if (recalcWithRevision) {
if (quote && quote.evo_recalc_limit) {
calculationStore.setValue('leaseObjectCount', quote.evo_recalc_limit);
@ -237,10 +224,7 @@ const reactionEffects: IReactionEffect[] = [
},
effect: ({ maxMass, recalcWithRevision }) => {
if (recalcWithRevision) {
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
const quote = calculationStore.getOption('selectQuote');
if (quote && quote.evo_max_mass)
if (
(maxMass < valuesConstants.MAX_VEHICLE_MASS &&
@ -277,10 +261,7 @@ const reactionEffects: IReactionEffect[] = [
},
effect: ({ countSeats, leaseObjectCategory, recalcWithRevision }) => {
if (recalcWithRevision && leaseObjectCategory === 100000003) {
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
const quote = calculationStore.getOption('selectQuote');
if (quote && quote?.evo_seats)
if (
(countSeats < valuesConstants.MAX_VEHICLE_SEATS &&
@ -327,10 +308,7 @@ const reactionEffects: IReactionEffect[] = [
effect: ({ leaseObjectYear, recalcWithRevision }) => {
const { leaseObjectUsed } = calculationStore.values;
if (recalcWithRevision && !leaseObjectUsed && leaseObjectYear) {
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
const quote = calculationStore.getOption('selectQuote');
if (quote && quote.evo_year)
if (leaseObjectYear >= quote.evo_year) {
calculationStore.setValidation('tbxLeaseObjectYear', undefined);

View File

@ -12,11 +12,11 @@ export default [
const { values } = calculationStore;
return values.lead;
},
effect: async leadId => {
effect: async leadid => {
if (calculationProcess.process === Process.LoadKp) {
return;
}
if (!leadId) {
if (!leadid) {
calculationStore.setValue('opportunity', null);
calculationStore.setFilter('selectOpportunity', undefined);
calculationStore.setValue('quote', null);
@ -31,10 +31,8 @@ export default [
calculationStore.setValue('calcFinDepartment', null);
return;
}
const lead = calculationStore.options.selectLead?.find(
x => x.leadid === leadId,
);
const lead = calculationStore.getOption('selectLead', { leadid });
if (lead) {
if (lead.evo_opportunityid) {
calculationStore.setValue('opportunity', lead.evo_opportunityid);
@ -58,7 +56,7 @@ export default [
}
`,
variables: {
leadid: leadId,
leadid: leadid,
},
toOptions: ['quote'],
}).then(({ entities }) => {
@ -226,9 +224,9 @@ export default [
return;
}
if (opportunityid) {
const opportunity = calculationStore.options.selectOpportunity?.find(
x => x.opportunityid === opportunityid,
);
const opportunity = calculationStore.getOption('selectOpportunity', {
opportunityid,
});
if (opportunity) {
if (opportunity.evo_client_riskid) {
calculationStore.setValue(
@ -260,32 +258,30 @@ export default [
}
}
} else if (leadid && !opportunityid) {
const lead = calculationStore.options.selectLead?.find(
x => x.leadid === leadid,
);
if (lead) {
if (lead.customerid) {
CrmService.crmgqlquery({
query: gql`
query($customerid: Uuid!) {
account(accountid: $customerid) {
evo_client_riskid
}
const lead = calculationStore.getOption('selectLead', {
leadid,
});
if (lead && lead.customerid) {
CrmService.crmgqlquery({
query: gql`
query($customerid: Uuid!) {
account(accountid: $customerid) {
evo_client_riskid
}
`,
variables: { customerid: lead.customerid },
}).then(({ entities }) => {
if (
entities.account &&
!Array.isArray(entities.account) &&
entities.account.evo_client_riskid
)
calculationStore.setValue(
'clientRisk',
entities.account.evo_client_riskid,
);
});
}
}
`,
variables: { customerid: lead.customerid },
}).then(({ entities }) => {
if (
entities.account &&
!Array.isArray(entities.account) &&
entities.account.evo_client_riskid
)
calculationStore.setValue(
'clientRisk',
entities.account.evo_client_riskid,
);
});
}
} else {
calculationStore.setValue('clientRisk', null);
@ -564,9 +560,9 @@ export default [
return;
}
if (dealerId) {
const dealer = calculationStore.options.selectDealer?.find(
x => x.accountid === dealerId,
);
const dealer = calculationStore.getOption('selectDealer', {
accountid: dealerId,
});
if (dealer) {
CrmService.crmgqlquery({
query: gql`
@ -633,9 +629,9 @@ export default [
calculationStore.setValue('dealerBroker', null);
calculationStore.setStatus('selectDealerBroker', ElementStatus.Disabled);
if (dealerPersonId) {
const dealerPerson = calculationStore.options.selectDealerPerson?.find(
x => x.accountid === dealerPersonId,
);
const dealerPerson = calculationStore.getOption('selectDealerPerson', {
accountid: dealerPersonId,
});
if (dealerPerson && dealerPerson.evo_broker_accountid) {
CrmService.crmgqlquery({
query: gql`
@ -680,9 +676,9 @@ export default [
},
effect: dealerBrokerId => {
if (dealerBrokerId) {
const dealerBroker = calculationStore.options.selectDealerBroker?.find(
x => x.accountid === dealerBrokerId,
);
const dealerBroker = calculationStore.getOption('selectDealerBroker', {
accountid: dealerBrokerId,
});
if (dealerBroker) {
calculationStore.setStatus(
'selectDealerBrokerRewardCondition',
@ -860,9 +856,9 @@ export default [
calculationStore.setValue('configuration', null);
if (modelId) {
const model = calculationStore.options.selectModel?.find(
x => x.evo_modelid === modelId,
);
const model = calculationStore.getOptions('selectModel', {
evo_modelid: modelId,
});
if (model) {
CrmService.crmgqlquery({
query: gql`
@ -920,9 +916,9 @@ export default [
calculationStore.setOptions('selectFinDepartment', []);
calculationStore.setValue('finDepartment', null);
if (supplierId) {
const supplier = calculationStore.options.selectSupplier?.find(
x => x.accountid === supplierId,
);
const supplier = calculationStore.getOption('selectSupplier', {
accountid: supplierId,
});
if (supplier && supplier.evo_fin_department_accountid)
CrmService.crmgqlquery({
query: gql`
@ -1031,9 +1027,9 @@ export default [
calculationStore.setValue('GPSModel', null);
if (GPSBrandId) {
const gpsBrand = calculationStore.options.selectGPSBrand?.find(
x => x.evo_gps_brandid === GPSBrandId,
);
const gpsBrand = calculationStore.getOption('selectGPSBrand', {
evo_gps_brandid: GPSBrandId,
});
if (gpsBrand) {
CrmService.crmgqlquery({
query: gql`
@ -1092,8 +1088,11 @@ export default [
calculationStore.setValue('townRegistration', null);
if (regionRegistrationId) {
const regionRegistration = calculationStore.options.selectRegionRegistration?.find(
x => x.evo_regionid === regionRegistrationId,
const regionRegistration = calculationStore.getOption(
'selectRegionRegistration',
{
evo_regionid: regionRegistrationId,
},
);
if (regionRegistration) {
CrmService.crmgqlquery({

View File

@ -1,4 +1,4 @@
import { ElementsNames } from './../../../../../core/types/Calculation/Store/elements';
import { ElementsNames } from 'core/types/Calculation/Store/elements';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { ElementStatus } from 'core/types/statuses';
@ -12,15 +12,14 @@ const elementsNames: ElementsNames[] = [
export default elementsNames.map(elementName => calculationStore => ({
expression: () => {
const { [elementName]: elementOptions } = calculationStore.options;
const elementOptions = calculationStore.getOptions(elementName);
return elementOptions?.length;
},
effect: length => {
if (length === 0) {
calculationStore.setStatus(elementName, ElementStatus.Disabled);
} else {
calculationStore.setStatus(elementName, ElementStatus.Default);
}
calculationStore.setStatus(
elementName,
length ? ElementStatus.Default : ElementStatus.Disabled,
);
},
options: {
fireImmediately: true,

View File

@ -460,11 +460,10 @@ export default [
graphType,
parmentsDecreasePercent,
seasonType,
highSeasonStart: highSeasonStartId,
} = calculationStore.values;
const highSeasonStart = calculationStore.options.selectHighSeasonStart?.find(
x => x.value === highSeasonStartId,
const highSeasonStart = calculationStore.getOption(
'selectHighSeasonStart',
);
return {
@ -519,8 +518,11 @@ export default [
case 100000001: {
if (seasonType) {
const paymentsInStep = Math.ceil((leasingPeriod - 2) / 3);
const targetSeasonType = calculationStore.options?.selectSeasonType?.find(
x => x?.value === seasonType,
const targetSeasonType = calculationStore.getOption(
'selectSeasonType',
{
value: seasonType,
},
);
const stepsValues: number[] =
targetSeasonType && targetSeasonType.stepsValues;
@ -612,8 +614,11 @@ export default [
return;
}
const next_seasonType_option = calculationStore.options.selectSeasonType?.find(
x => x.value === seasonType,
const next_seasonType_option = calculationStore.getOption(
'selectSeasonType',
{
value: seasonType,
},
);
const {
@ -649,8 +654,11 @@ export default [
if (prevShiftNumber > 0)
middleRows = shiftRight(middleRows, prevShiftNumber);
const prev_seasonType_option = calculationStore.options.selectSeasonType?.find(
x => x.value === prevSeasonType,
const prev_seasonType_option = calculationStore.getOption(
'selectSeasonType',
{
value: prevSeasonType,
},
);
const prevStartPositions =
prev_seasonType_option && prev_seasonType_option.startPositions;

View File

@ -45,16 +45,13 @@ const tablePayments: ITable = {
if (graphType === 100000003) {
const { leasingPeriod } = calculationStore.values;
if (rowIndex >= 1 && rowIndex <= PERIODS_NUMBER) {
const { highSeasonStart } = calculationStore.values;
const highSeasonStartValue = parseInt(
calculationStore.options.selectHighSeasonStart?.find(
x => x.value === highSeasonStart,
)?.name || '2',
calculationStore.getOption('selectHighSeasonStart')?.name || '2',
),
shiftNumber = highSeasonStartValue - 2;
const seasonTypeOptions = calculationStore.options.selectSeasonType?.find(
x => x.value === seasonType,
const seasonTypeOptions = calculationStore.getOption(
'selectSeasonType',
);
const startPositions =
seasonTypeOptions && seasonTypeOptions.startPositions,

View File

@ -28,7 +28,14 @@ interface ICalculationValues {
applyStaticData: (data: TStaticData) => void;
options: TElements<(IBaseOption & TCRMEntity)[]>;
getOptions: (elementName: ElementsNames) => (IBaseOption & TCRMEntity)[];
getOption: (
elementName: ElementsNames,
fields?: { [field in keyof (IBaseOption & TCRMEntity)]: any },
) => (IBaseOption & TCRMEntity) | undefined;
getOptions: (
elementName: ElementsNames,
fields?: { [field in keyof (IBaseOption & TCRMEntity)]: any },
) => (IBaseOption & TCRMEntity)[] | undefined;
setOptions: (
elementName: ElementsNames,
options: (IBaseOption & TCRMEntity)[],