diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts index 243669b..01d6924 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts @@ -104,6 +104,8 @@ const validatePaymentsTable = () => { const payments = CalculationStore.tables.tablePayments.rows.map( x => x.paymentRelation?.value, ); + const rows = CalculationStore.tables.tablePayments.rows; + const isValidRows = !rows.some(x => x.paymentRelation?.validation === false); switch (graphType) { case 100000001: { @@ -123,11 +125,7 @@ const validatePaymentsTable = () => { ); } - if ( - !CalculationStore.tables.tablePayments.rows.some( - x => x.paymentRelation?.validation === false, - ) - ) { + if (isValidRows) { const target_payments = payments.slice(1, 4); const min = Math.min.apply(Math, target_payments); const max = Math.max.apply(Math, target_payments); @@ -145,11 +143,7 @@ const validatePaymentsTable = () => { ); } - if ( - !CalculationStore.tables.tablePayments.rows.some( - x => x.paymentRelation?.validation === false, - ) - ) { + if (isValidRows) { const target_payments = payments.slice(1, payments.length - 1); let pairs_number = 0; new Set(target_payments).forEach(set_v => { @@ -176,6 +170,22 @@ const validatePaymentsTable = () => { ); } + if (isValidRows) { + rows.forEach((x, i) => { + if (i > 0 && i < rows.length) { + const isInvalidValue = x > rows[i - 1] || x < 3; + CalculationStore.setTableRow( + 'tablePayments', + i, + )({ + paymentRelation: { + validation: !isInvalidValue, + }, + }); + } + }); + } + break; } @@ -228,18 +238,33 @@ const validatePaymentsTable = () => { } case 100000004: { - const areMiddleRowsEqual = new Set(payments.slice(1, 4)).size === 1; - + const targetRows = payments.slice(1, 4); + const areEqual3MiddleRows = new Set(targetRows).size === 1; CalculationStore.setTableRows( 'tablePayments', 1, )( Array.from({ length: 3 }, () => ({ paymentRelation: { - validation: areMiddleRowsEqual ? false : true, + validation: areEqual3MiddleRows ? false : true, }, })), ); + + if (isValidRows) { + const areCorrect3MiddleRows = isEqual( + targetRows.map(x => x.paymentRelation?.value).sort((a, b) => a - b), + targetRows.map(x => x.paymentRelation?.value), + ); + CalculationStore.setTableRow( + 'tablePayments', + 1, + )({ + paymentRelation: { + validation: areCorrect3MiddleRows ? true : false, + }, + }); + } break; } } diff --git a/src/client/stores/CalculationStore/config/initialTables/tablePayments.ts b/src/client/stores/CalculationStore/config/initialTables/tablePayments.ts index 10c27b7..1c70d46 100644 --- a/src/client/stores/CalculationStore/config/initialTables/tablePayments.ts +++ b/src/client/stores/CalculationStore/config/initialTables/tablePayments.ts @@ -1,6 +1,6 @@ import { rotateArrays } from 'core/tools/array'; import { ITable } from 'core/types/Calculation/Store/tables'; -import { inRange, isEqual } from 'lodash'; +import { inRange } from 'lodash'; import valuesConstants from 'core/constants/values'; const { PERIODS_NUMBER } = valuesConstants; @@ -39,17 +39,6 @@ const tablePayments: ITable = { }), ), ); - - const prevRow = calculationStore.tables[tableName].rows[rowIndex - 1]; - const isCurrentValueGreater = value > prevRow.paymentRelation?.value; - calculationStore.setTableRow( - tableName, - rowIndex, - )({ - paymentRelation: { - validation: isCurrentValueGreater || value < 3 ? false : true, - }, - }); } } @@ -119,28 +108,6 @@ const tablePayments: ITable = { } } } - - if (graphType === 100000004) { - if (rowIndex > 0 && rowIndex < 4) { - const isCorrect3MiddleRows = isEqual( - calculationStore.tables[tableName].rows - .slice(1, 4) - .map(x => x.paymentRelation?.value) - .sort((a, b) => a - b), - calculationStore.tables[tableName].rows - .slice(1, 4) - .map(x => x.paymentRelation?.value), - ); - calculationStore.setTableRow( - tableName, - rowIndex, - )({ - paymentRelation: { - validation: isCorrect3MiddleRows ? true : false, - }, - }); - } - } }, }, };