validation: check leasePeriod = payments.length

This commit is contained in:
vchikalkin 2021-12-29 17:46:27 +03:00
parent aa33605d90
commit 1765925e93

View File

@ -87,10 +87,10 @@ const customConditions: TElements<ValidationCondition> = {
tracker, tracker,
requirementTelematic, requirementTelematic,
} = calculationStore.getValues([ } = calculationStore.getValues([
'telematic', 'telematic',
'tracker', 'tracker',
'requirementTelematic', 'requirementTelematic',
]); ]);
if (requirementTelematic !== 100000004 && !telematic && !tracker) { if (requirementTelematic !== 100000004 && !telematic && !tracker) {
return { return {
@ -128,6 +128,17 @@ const customConditions: TElements<ValidationCondition> = {
'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж', 'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж',
}; };
}, },
tbxLeasingPeriod: calculationStore => {
const leasingPeriod = calculationStore.getValue('leasingPeriod');
const tablePaymentsLength =
calculationStore.tables.tablePayments.rows.length;
return {
isValid: leasingPeriod === tablePaymentsLength,
message:
'Срок лизинга не соответствует таблице платежей. Необходимо изменить срок лизинга',
};
},
}; };
const elementsValidations: TElements<any> = { const elementsValidations: TElements<any> = {
@ -156,32 +167,32 @@ const elementsConditions = (Object.keys(
elementsValidations, elementsValidations,
) as ElementsNames[]).reduce( ) as ElementsNames[]).reduce(
(ac: TElements<ValidationCondition>, elementName) => { (ac: TElements<ValidationCondition>, elementName) => {
ac[elementName] = pipe( ac[elementName] = pipe(
getValue, getValue,
elementsValidations[elementName], elementsValidations[elementName],
convertToValidationResult, convertToValidationResult,
); );
return ac; return ac;
}, },
{}, {},
); );
const entityElementsConditions = ([ const entityElementsConditions = ([
'selectIndAgentRewardCondition', 'selectIndAgentRewardCondition',
'selectCalcBrokerRewardCondition', 'selectCalcBrokerRewardCondition',
'selectFinDepartmentRewardCondtion', 'selectFinDepartmentRewardCondtion',
] as ElementsNames[]).reduce( ] as ElementsNames[]).reduce(
(ac: TElements<ValidationCondition>, elementName) => { (ac: TElements<ValidationCondition>, elementName) => {
const valueName = getValueName(elementName); const valueName = getValueName(elementName);
ac[elementName] = (calculationStore, elementName) => { ac[elementName] = (calculationStore, elementName) => {
if (isNil(calculationStore.getValue(valueName))) { if (isNil(calculationStore.getValue(valueName))) {
return { isValid: true }; return { isValid: true };
} }
return { return {
isValid: calculationStore.getOption(elementName) !== undefined, isValid: calculationStore.getOption(elementName) !== undefined,
};
}; };
return ac; };
return ac;
}, },
{}, {},
); );