From 318a0d64b83c37d625438ba51e9a163b0c07509e Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 29 Dec 2021 16:14:46 +0300 Subject: [PATCH 1/5] merge release/rush-redemption-payment --- .../Calculation/Sections/sectionsList.ts | 5 +- .../Calculation/lib/elements/components.ts | 1 + .../Calculation/lib/elements/elementsProps.ts | 40 ++- .../Calculation/lib/elements/titles.ts | 1 + .../Calculation/lib/elements/values.ts | 1 + .../stores/CalculationStore/Data/tables.js | 19 +- .../actions/calculate/validate/elements.ts | 14 +- .../actions/calculate/validate/tables.ts | 59 +++-- .../Effects/reactions/loadKpReaction/index.ts | 114 ++++++--- .../reactions/loadKpReaction/mapKpToValues.ts | 2 +- .../reactions/loadKpReaction/quoteQuery.js | 1 + .../Effects/reactions/otherReactions.ts | 50 ++-- .../Effects/reactions/tablesReactions.ts | 227 +++++++----------- .../config/initialStatuses.ts | 2 + .../CalculationStore/config/initialValues.ts | 5 +- src/core/types/Calculation/Store/elements.ts | 1 + src/core/types/Calculation/Store/index.ts | 11 +- src/core/types/Calculation/Store/values.ts | 1 + src/core/types/Entities/crmEntities.ts | 1 + 19 files changed, 297 insertions(+), 258 deletions(-) diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index 69ac3a9..d1fdbbd 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -80,7 +80,8 @@ const sections: ISection[] = [ 'tbxLeaseObjectPrice', 'tbxSupplierDiscountRub', 'tbxSupplierDiscountPerc', - 'radioBalanceHolder', + // 'radioBalanceHolder', + 'tbxRedemptionPaymentSum', 'tbxSaleBonus', 'selectSubsidy', ], @@ -407,7 +408,7 @@ const sections: ISection[] = [ }, }, elements: [ - 'cbxLastPaymentRedemption', + // 'cbxLastPaymentRedemption', 'cbxPriceWithDiscount', 'cbxFullPriceWithDiscount', 'cbxCostIncrease', diff --git a/src/client/Containers/Calculation/lib/elements/components.ts b/src/client/Containers/Calculation/lib/elements/components.ts index f68926e..54049f6 100644 --- a/src/client/Containers/Calculation/lib/elements/components.ts +++ b/src/client/Containers/Calculation/lib/elements/components.ts @@ -46,6 +46,7 @@ const elementsComponents: TElements = { radioLastPaymentRule: Radio, tbxLastPaymentPerc: InputNumber, tbxLastPaymentRub: InputNumber, + tbxRedemptionPaymentSum: InputNumber, tbxLeasingPeriod: InputNumber, radioGraphType: Radio, tbxParmentsDecreasePercent: InputNumber, diff --git a/src/client/Containers/Calculation/lib/elements/elementsProps.ts b/src/client/Containers/Calculation/lib/elements/elementsProps.ts index 8a5a28b..e97e844 100644 --- a/src/client/Containers/Calculation/lib/elements/elementsProps.ts +++ b/src/client/Containers/Calculation/lib/elements/elementsProps.ts @@ -137,9 +137,16 @@ const elementsProps: TElements = { precision: 2, formatter: formatNumber, }, + tbxRedemptionPaymentSum: { + min: '1000', + max: '2000', + step: '1000.00', + precision: 2, + formatter: formatNumber, + }, tbxLeasingPeriod: { - min: '7', - max: '90', + min: '13', + max: '60', }, tbxParmentsDecreasePercent: { min: '50', @@ -180,7 +187,7 @@ const elementsProps: TElements = { }, tbxLeaseObjectYear: { min: '1994', - max: currentYear + 1, + max: (currentYear + 1).toString(), }, selectLeaseObjectCategory: { showSearch: false, @@ -266,7 +273,7 @@ const elementsProps: TElements = { }, tbxInsFranchise: { min: '0', - max: MAX_FRANCHISE, + max: MAX_FRANCHISE.toString(), step: '10000.00', precision: 2, formatter: formatNumber, @@ -405,9 +412,9 @@ const elementsProps: TElements = { style: 'button', }, tbxVehicleTaxInYear: { - min: 0, - step: 100, - max: 9999999, + min: '0', + step: '100', + max: '9999999', precision: 2, tooltip: { Component: buildTooltip({ @@ -417,9 +424,9 @@ const elementsProps: TElements = { }, }, tbxVehicleTaxInLeasingPeriod: { - min: 0, - step: 100, - max: 9999999, + min: '0', + step: '100', + max: '9999999', precision: 2, }, selectObjectRegionRegistration: { @@ -452,6 +459,19 @@ const elementsProps: TElements = { }, }; +export const numberElementsProps: TElements = Object.keys( + elementsProps, +).reduce((acc, a) => { + const min = elementsProps[a]?.min, + max = elementsProps[a]?.max; + if (min || max) + return { + ...acc, + [a]: { min, max }, + }; + return acc; +}, {}); + const labelElementsProps: TElements = Object.assign( {}, [ diff --git a/src/client/Containers/Calculation/lib/elements/titles.ts b/src/client/Containers/Calculation/lib/elements/titles.ts index 679814b..cc837a7 100644 --- a/src/client/Containers/Calculation/lib/elements/titles.ts +++ b/src/client/Containers/Calculation/lib/elements/titles.ts @@ -35,6 +35,7 @@ export const elementsTitles: TElements = { tbxLastPaymentPerc: 'Последний платеж, %', tbxLastPaymentRub: 'Последний платеж, руб.', radioLastPaymentRule: 'Последний платеж считается от ', + tbxRedemptionPaymentSum: 'Сумма выкупного платежа, руб', radioBalanceHolder: 'Балансодержатель', radioGraphType: 'Вид графика', tbxParmentsDecreasePercent: 'Процент убывания платежей', diff --git a/src/client/Containers/Calculation/lib/elements/values.ts b/src/client/Containers/Calculation/lib/elements/values.ts index c7e88fc..c925560 100644 --- a/src/client/Containers/Calculation/lib/elements/values.ts +++ b/src/client/Containers/Calculation/lib/elements/values.ts @@ -39,6 +39,7 @@ export const elementsValues: TElements = { tbxLastPaymentPerc: 'lastPaymentPerc', tbxLastPaymentRub: 'lastPaymentRub', radioLastPaymentRule: 'lastPaymentRule', + tbxRedemptionPaymentSum: 'redemptionPaymentSum', radioBalanceHolder: 'balanceHolder', radioGraphType: 'graphType', tbxParmentsDecreasePercent: 'parmentsDecreasePercent', diff --git a/src/client/stores/CalculationStore/Data/tables.js b/src/client/stores/CalculationStore/Data/tables.js index cc879a3..a13bea8 100644 --- a/src/client/stores/CalculationStore/Data/tables.js +++ b/src/client/stores/CalculationStore/Data/tables.js @@ -11,8 +11,13 @@ const tablesActions = { }, getTableRowValues(tableName, rowIndex, paramName) { + let targetIndex = rowIndex; + if (typeof rowIndex === 'function') { + const rows = this.tables[tableName]?.rows; + targetIndex = rowIndex(rows); + } let values = {}; - const row = this?.tables?.[tableName]?.rows?.[rowIndex]; + const row = this?.tables?.[tableName]?.rows?.[targetIndex]; if (!row) { return values; } @@ -32,6 +37,11 @@ const tablesActions = { return values; }, + getTableRowValue(tableName, rowIndex, propName, paramName) { + const values = this.getTableRowValues(tableName, rowIndex, paramName); + return values[propName]; + }, + getTableOptions(tableName, propName) { return this.tables[tableName].options[propName]; }, @@ -65,8 +75,13 @@ const tablesActions = { }, setTableRow(tableName, rowIndex, override) { + let targetIndex = rowIndex; + if (typeof rowIndex === 'function') { + const rows = this.tables[tableName]?.rows; + targetIndex = rowIndex(rows); + } return row => { - this.setTableRows(tableName, rowIndex, override)([row]); + this.setTableRows(tableName, targetIndex, override)([row]); }; }, diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts index 34475c8..b249424 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -132,18 +132,14 @@ const customConditions: TElements = { tbxLeasingPeriod: calculationStore => { const { recalcWithRevision, leasingPeriod } = calculationStore.values; const quote = calculationStore.getOption('selectQuote'); - const kaskoRowIndex = calculationStore.tables.tableInsurance.rows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const kaskoValues = calculationStore.getTableRowValues( + const kaskoInsTerm = calculationStore.getTableRowValue( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + 'insTerm', 'value', ); - const kaskoInsTerm = kaskoValues.insTerm; - if ( recalcWithRevision && quote?.evo_one_year_insurance && @@ -152,7 +148,7 @@ const customConditions: TElements = { ) { calculationStore.setTableRow( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), false, )({ insTerm: { @@ -167,7 +163,7 @@ const customConditions: TElements = { } else { calculationStore.setTableRow( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), false, )({ insTerm: { diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts index 7949f12..4319c17 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts @@ -5,40 +5,37 @@ import { isEqual, isNil } from 'lodash'; const { PERIODS_NUMBER } = valuesConstants; function validateInsuranceTable(this: ICalculationStore) { - const tableInsurance = this.tables.tableInsurance; - - const kaskoRowIndex = tableInsurance.rows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const osagoRowIndex = tableInsurance.rows.findIndex( - x => x.policyType?.value === 'ОСАГО', - ); - - this.setTableRows( + const osagoRow = this.getTableRowValues( 'tableInsurance', - 0, - )([ - { - insuranceCompany: { - validation: !isNil( - tableInsurance.rows[osagoRowIndex].insuranceCompany?.value, - ), - }, - insured: { - validation: !isNil(tableInsurance.rows[osagoRowIndex].insured?.value), - }, + rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + 'value', + ); + this.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + )({ + insuranceCompany: { + validation: !isNil(osagoRow.insuranceCompany), }, - { - insuranceCompany: { - validation: !isNil( - tableInsurance.rows[kaskoRowIndex].insuranceCompany?.value, - ), - }, - insured: { - validation: !isNil(tableInsurance.rows[kaskoRowIndex].insured?.value), - }, + insured: { + validation: !isNil(osagoRow.insured), }, - ]); + }); + + const kaskoRow = this.getTableRowValues( + 'tableInsurance', + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + 'value', + ); + this.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), + )({ + insuranceCompany: { + validation: !isNil(kaskoRow.insuranceCompany), + }, + insured: { + validation: !isNil(kaskoRow.insured), + }, + }); } function validatePaymentsTable(this: ICalculationStore) { diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index 87bffac..375a2b0 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -1,6 +1,11 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import { message } from 'antd'; import { resetIns } from 'client/Components/Calculation/ELT/Content/lib/resetIns'; +import { numberElementsProps } from 'client/Containers/Calculation/lib/elements/elementsProps'; +import { + getTitle, + getValueName +} from 'client/Containers/Calculation/lib/elements/tools'; import { elementsValues } from 'client/Containers/Calculation/lib/elements/values'; import { openNotification } from 'client/Elements/Notification'; import initialValues from 'client/stores/CalculationStore/config/initialValues'; @@ -8,7 +13,10 @@ import CrmService from 'core/services/CrmService'; import { currentISODate } from 'core/tools/date'; import { IGetCRMEntitiesResponse } from 'core/types/Calculation/Responses'; import { IReactionEffect } from 'core/types/Calculation/Store/effect'; -import { TElements } from 'core/types/Calculation/Store/elements'; +import { + ElementsNames, + TElements +} from 'core/types/Calculation/Store/elements'; import { Process } from 'core/types/Calculation/Store/process'; import { ValuesNames } from 'core/types/Calculation/Store/values'; import { IEvoGraph } from 'core/types/Entities/crmEntities'; @@ -66,6 +74,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ infuranceOPF, calcBroker, calcFinDepartment, + balanceHolder, } = calculationStore.values; calculationStore.setStatus('selectQuote', ElementStatus.Disabled); @@ -257,10 +266,8 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ ); if (current_opportunity) { - const { - evo_programsolution, - evo_client_riskid, - } = current_opportunity; + const { evo_programsolution, evo_client_riskid } = + current_opportunity; if (evo_programsolution === 100000000) { const midClientRisk = calculationStore.getOption( @@ -482,36 +489,77 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ //townRegistration } - calculationStore.setValues( - { - ...initialValues, - ...newValues, - product, - ...addProducts, - rate, - lead, - opportunity, - quote: quoteId, - recalcWithRevision, - leaseObjectCount, - clientRisk, - calcType, - totalPayments: evo_graph.evo_sumpay_withnds, - indAgent, - vehicleTaxInYear, - INNForCalc, - creditRate, - infuranceOPF, - legalClientRegion, - regionRegistration, - legalClientTown, - townRegistration, - calcBroker, - calcFinDepartment, - requirementTelematic, + // redemptionPayment + let redemptionPaymentSum = + quote.evo_payment_redemption_sum || + initialValues.redemptionPaymentSum; + // redemptionPayment + + const finalValues = { + ...initialValues, + ...newValues, + product, + ...addProducts, + rate, + lead, + opportunity, + quote: quoteId, + recalcWithRevision, + leaseObjectCount, + clientRisk, + calcType, + totalPayments: evo_graph.evo_sumpay_withnds, + indAgent, + vehicleTaxInYear, + INNForCalc, + creditRate, + infuranceOPF, + legalClientRegion, + regionRegistration, + legalClientTown, + townRegistration, + calcBroker, + calcFinDepartment, + requirementTelematic, + balanceHolder, + redemptionPaymentSum, + }; + + // check min max number values + let fixedElementsNames: ElementsNames[] = []; + (Object.keys(numberElementsProps) as ElementsNames[]).forEach( + elementName => { + if (elementName in numberElementsProps) { + const elementProps = numberElementsProps[elementName]; + + const valueName = getValueName(elementName); + if ( + finalValues[valueName] && + ((elementProps?.min && + finalValues[valueName] < parseFloat(elementProps?.min)) || + (elementProps?.max && + finalValues[valueName] > parseFloat(elementProps?.max))) + ) { + finalValues[valueName] = initialValues[valueName]; + fixedElementsNames.push(elementName); + } + } }, - true, ); + if (fixedElementsNames.length > 0) { + const fieldsTitles = fixedElementsNames + .map(x => getTitle(x)) + .join(', '); + openNotification({ + type: 'warning', + title: 'Внимание', + description: + 'При подгрузке КП были сброшены поля: ' + fieldsTitles, + })(); + } + // check min max number values + + calculationStore.setValues(finalValues, true); message.success({ content: `КП ${quote?.evo_quotename || ''} загружено!`, diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts index 6149ece..7d955bb 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts @@ -12,7 +12,7 @@ const mapKPtoValues: TValues = { lastPaymentRule: 'evo_last_payment_calc', lastPaymentPerc: 'evo_last_payment_perc', lastPaymentRub: 'evo_last_payment_rub', - balanceHolder: 'evo_balance_holder', + // balanceHolder: 'evo_balance_holder', graphType: 'evo_graph_type', parmentsDecreasePercent: 'evo_payments_decrease_perc', seasonType: 'evo_seasons_type', diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js index 9f74281..b006aee 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js @@ -58,6 +58,7 @@ export default gql` evo_req_telematic evo_req_telematic_accept evo_accept_control_addproduct_typeid + evo_payment_redemption_sum } } `; diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index c011395..21c0437 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -877,31 +877,31 @@ const reactionEffects: IReactionEffect[] = [ }, }), - calculationStore => ({ - expression: () => { - const { leasingPeriod } = calculationStore.values; - return leasingPeriod; - }, - effect: leasingPeriod => { - if (leasingPeriod) { - if (parseInt(leasingPeriod) < 13) { - calculationStore.setStatus( - 'radioBalanceHolder', - ElementStatus.Disabled, - ); - calculationStore.setValue('balanceHolder', 100000000); - } else { - calculationStore.setStatus( - 'radioBalanceHolder', - ElementStatus.Default, - ); - } - } - }, - options: { - fireImmediately: true, - }, - }), + // calculationStore => ({ + // expression: () => { + // const { leasingPeriod } = calculationStore.values; + // return leasingPeriod; + // }, + // effect: leasingPeriod => { + // if (leasingPeriod) { + // if (parseInt(leasingPeriod) < 13) { + // calculationStore.setStatus( + // 'radioBalanceHolder', + // ElementStatus.Disabled, + // ); + // calculationStore.setValue('balanceHolder', 100000000); + // } else { + // calculationStore.setStatus( + // 'radioBalanceHolder', + // ElementStatus.Default, + // ); + // } + // } + // }, + // options: { + // fireImmediately: true, + // }, + // }), calculationStore => ({ expression: () => { diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index 65b1157..b526983 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -16,14 +16,9 @@ const { PERIODS_NUMBER } = valuesConstants; export default [ (calculationStore, calculationProcess) => ({ expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const kaskoValues = calculationStore.getTableRowValues( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), 'value', ); @@ -72,47 +67,41 @@ export default [ }, }), - (calculationStore, calculationProcess) => ({ - expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const kaskoRow = tableRows[kaskoRowIndex]; - const { leasingPeriod } = calculationStore.values; + // (calculationStore, calculationProcess) => ({ + // expression: () => { + // const { leasingPeriod } = calculationStore.values; - return { - insTerm: kaskoRow.insTerm?.value, - leasingPeriod, - }; - }, - effect: ({ insTerm, leasingPeriod }) => { - if (calculationProcess.hasProcess(Process.LoadKp)) { - return; - } - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { value: 100000001, status: ElementStatus.Disabled }, - }); - } else { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { status: ElementStatus.Default }, - }); - } - }, - }), + // const insTermValue = calculationStore.getTableRowValue( + // 'tableInsurance', + // rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // 'insTerm', + // 'value', + // ); + + // return { + // insTerm: insTermValue, + // leasingPeriod, + // }; + // }, + // effect: ({ insTerm, leasingPeriod }) => { + // if (calculationProcess.hasProcess(Process.LoadKp)) { + // return; + // } + // if (insTerm === 100000001 && leasingPeriod > 15) { + // calculationStore.setTableRow('tableInsurance', rows => + // rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // )({ + // insured: { value: 100000001, status: ElementStatus.Disabled }, + // }); + // } else { + // calculationStore.setTableRow('tableInsurance', rows => + // rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // )({ + // insured: { status: ElementStatus.Default }, + // }); + // } + // }, + // }), (calculationStore, calculationProcess) => ({ expression: () => { @@ -121,87 +110,74 @@ export default [ }, effect: leasingPeriod => { if (leasingPeriod) { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const osagoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ОСАГО', - ); - if (leasingPeriod < 12) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insured: { value: 100000000, status: ElementStatus.Disabled }, }); - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insured: { value: 100000000, status: ElementStatus.Disabled }, insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); } else if (leasingPeriod === 12) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insured: { status: ElementStatus.Default }, }); - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insured: { status: ElementStatus.Default }, insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); } else if (leasingPeriod > 12 && leasingPeriod < 16) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insured: { status: ElementStatus.Default }, }); - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insured: { status: ElementStatus.Default }, insTerm: { value: 100000001, status: ElementStatus.Disabled }, }); } else if ( - leasingPeriod > 16 && - calculationStore?.tables?.tableInsurance?.rows[kaskoRowIndex]?.insTerm - ?.value === 100000001 + leasingPeriod > 16 + // && + // calculationStore.getTableRowValue( + // 'tableInsurance', + // rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // 'insTerm', + // 'value', + // ) === 100000001 ) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insured: { status: ElementStatus.Default }, }); - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ - insured: { value: 100000001, status: ElementStatus.Disabled }, - insTerm: { status: ElementStatus.Default }, + insured: { status: ElementStatus.Default }, + insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); } else { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insured: { status: ElementStatus.Default }, }); - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insured: { status: ElementStatus.Default }, - insTerm: { status: ElementStatus.Default }, + insTerm: { status: ElementStatus.Disabled }, }); } } @@ -213,28 +189,19 @@ export default [ (calculationStore, calculationProcess) => ({ expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const dgoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ДГО', - ); - const nsRowIndex = tableRows.findIndex(x => x.policyType?.value === 'НС'); - const kaskoValues = calculationStore.getTableRowValues( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), 'value', ); const dgoValues = calculationStore.getTableRowValues( 'tableInsurance', - dgoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'ДГО'), 'value', ); const nsValues = calculationStore.getTableRowValues( 'tableInsurance', - nsRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'НС'), 'value', ); @@ -248,19 +215,14 @@ export default [ if (calculationProcess.hasProcess(Process.LoadKp)) { return; } - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); if ( kaskoRow && kaskoRow.insCost === 0 && ((dgoRow && dgoRow.insCost > 0) || (nsRow && nsRow.insCost > 0)) ) { - calculationStore.setTableRow( - 'tableInsurance', - 1, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insCost: { validation: false, @@ -273,9 +235,8 @@ export default [ description: 'Укажите стоимость КАСКО', })(); } else { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insCost: { validation: true, @@ -287,13 +248,9 @@ export default [ (calculationStore, calculationProcess) => ({ expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); const kaskoValues = calculationStore.getTableRowValues( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), 'value', ); return { @@ -304,19 +261,14 @@ export default [ if (calculationProcess.hasProcess(Process.LoadKp)) { return; } - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); if ( kaskoRow && kaskoRow.insured === 100000001 && kaskoRow.insCost === 0 ) { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insCost: { validation: false, @@ -328,9 +280,8 @@ export default [ description: 'Укажите стоимость КАСКО, включаемую в график', })(); } else { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insCost: { validation: true, @@ -359,19 +310,14 @@ export default [ if (calculationProcess.hasProcess(Process.LoadKp)) { return; } - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const osagoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ОСАГО', - ); if ( osagoRow && osagoRow.insured === 100000001 && osagoRow.insCost === 0 ) { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insCost: { validation: false, @@ -383,9 +329,8 @@ export default [ description: 'Укажите стоимость ОСАГО, включаемую в график', })(); } else { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insCost: { validation: true, @@ -762,15 +707,15 @@ export default [ if (nextIsTrailer) { const otherInsuranceCompany = calculationStore.tables.tableInsurance.options?.insuranceCompany?.find( - x => x.name?.includes('ПРОЧИЕ'), - ); + x => x.name?.includes('ПРОЧИЕ'), + ); if (otherInsuranceCompany) { const insuranceOtherFilter = singleValueFilter( otherInsuranceCompany.value, ); calculationStore.setTableRow( 'tableInsurance', - 0, + rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), true, )({ insuranceCompany: { @@ -791,7 +736,7 @@ export default [ } else { calculationStore.setTableRow( 'tableInsurance', - 0, + rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), true, )({ insuranceCompany: { diff --git a/src/client/stores/CalculationStore/config/initialStatuses.ts b/src/client/stores/CalculationStore/config/initialStatuses.ts index ed53f2f..e65409a 100644 --- a/src/client/stores/CalculationStore/config/initialStatuses.ts +++ b/src/client/stores/CalculationStore/config/initialStatuses.ts @@ -41,6 +41,8 @@ const initialStatuses: TElements = { selectLeaseObjectCategory: ElementStatus.Disabled, tbxINNForCalc: ElementStatus.Disabled, radioInfuranceOPF: ElementStatus.Disabled, + + tbxRedemptionPaymentSum: ElementStatus.Disabled, }; export default initialStatuses; diff --git a/src/client/stores/CalculationStore/config/initialValues.ts b/src/client/stores/CalculationStore/config/initialValues.ts index 5c70f51..9d661db 100644 --- a/src/client/stores/CalculationStore/config/initialValues.ts +++ b/src/client/stores/CalculationStore/config/initialValues.ts @@ -15,12 +15,13 @@ const initialValues: TValues = { supplierCurrency: 'RUB', supplierDiscountRub: 0, supplierDiscountPerc: 0, - leasingPeriod: 12, + leasingPeriod: 13, firstPaymentPerc: 25, firstPaymentRub: 0, lastPaymentPerc: 1, lastPaymentRule: 100000001, - balanceHolder: 100000000, + redemptionPaymentSum: 1000, + balanceHolder: 100000001, graphType: 100000000, parmentsDecreasePercent: 94, seasonType: 100000000, diff --git a/src/core/types/Calculation/Store/elements.ts b/src/core/types/Calculation/Store/elements.ts index 0063a3d..7fa3fd1 100644 --- a/src/core/types/Calculation/Store/elements.ts +++ b/src/core/types/Calculation/Store/elements.ts @@ -36,6 +36,7 @@ export type ElementsNames = | 'tbxLastPaymentPerc' | 'tbxLastPaymentRub' | 'radioLastPaymentRule' + | 'tbxRedemptionPaymentSum' | 'radioBalanceHolder' | 'radioGraphType' | 'tbxParmentsDecreasePercent' diff --git a/src/core/types/Calculation/Store/index.ts b/src/core/types/Calculation/Store/index.ts index 5fd6772..9bd8b42 100644 --- a/src/core/types/Calculation/Store/index.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -81,10 +81,17 @@ interface ICalculationTables { cleanTable: (tableName: TableNames) => void; getTableRowValues: ( tableName: TableNames, - rowIndex: number, + rowIndex: number | ((rows: TableProps[]) => number), paramName: ElementParam, ) => TableProps; + getTableRowValue: ( + tableName: TableNames, + rowIndex: number | ((rows: TableProps[]) => number), + propName: TableValuesNames, + paramName: ElementParam, + ) => any; + getTableOptions: ( tableName: TableNames, propName: TableValuesNames, @@ -102,7 +109,7 @@ interface ICalculationTables { setTableRow: ( tableName: TableNames, - rowIndex: number, + rowIndex: number | ((rows: TableProps[]) => number), override?: boolean, ) => (row: TableProps) => void; diff --git a/src/core/types/Calculation/Store/values.ts b/src/core/types/Calculation/Store/values.ts index 99680c4..d2bbb2d 100644 --- a/src/core/types/Calculation/Store/values.ts +++ b/src/core/types/Calculation/Store/values.ts @@ -33,6 +33,7 @@ export type ValuesNames = | 'lastPaymentPerc' | 'lastPaymentRub' | 'lastPaymentRule' + | 'redemptionPaymentSum' | 'balanceHolder' | 'graphType' | 'parmentsDecreasePercent' diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 8001258..648f62f 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -102,6 +102,7 @@ export interface IQuote { evo_req_telematic?: number; evo_req_telematic_accept?: number; evo_one_year_insurance?: boolean; + evo_payment_redemption_sum?: number; } export interface IEvoGraph { From aa33605d903e60f77f11c39feb8034303b32c4f9 Mon Sep 17 00:00:00 2001 From: Chika Date: Tue, 28 Dec 2021 17:21:53 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B0=20callback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit переписать в реакцию валидацию про однолетний полис: Работает при загрузке КП и изменении значения в поле Срок страхования в строке КАСКО в таблице Страхования и изменении значения в поле tbxLeasingPeriod: ЕСЛИ Пересчет без пересмотра (recalcWthtRevision) = True, ТО Если quote.evo_one_year_insurance = True И tbxLeasingPeriod >15 И Срок страхования в строке КАСКО в таблице Страхования = Срок ДЛ, то 1) Срок страхования в строке КАСКО в таблице Страхования меняем на значение "12 месяцев" 2) Срок страхования в строке КАСКО в таблице Страхования закрываем для редактирования 3) выводим сообщение "Срок страхования КАСКО изменен на 12 месяцев, т.к. оформляется Однолетний полис" иначе Срок страхования в строке КАСКО в таблице Страхования оставляем открытым для редактирования (проверить на другие реакции, которые открывают/закрывают данное поле) ИНАЧЕ ничего не делаем --- .../actions/calculate/validate/elements.ts | 48 ----------------- .../Effects/reactions/tablesReactions.ts | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts index b249424..bbb883f 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -128,54 +128,6 @@ const customConditions: TElements = { 'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж', }; }, - // TODO: temp (move to tableInsurance validation) - tbxLeasingPeriod: calculationStore => { - const { recalcWithRevision, leasingPeriod } = calculationStore.values; - const quote = calculationStore.getOption('selectQuote'); - - const kaskoInsTerm = calculationStore.getTableRowValue( - 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), - 'insTerm', - 'value', - ); - - if ( - recalcWithRevision && - quote?.evo_one_year_insurance && - leasingPeriod > 16 && - kaskoInsTerm !== 100000000 - ) { - calculationStore.setTableRow( - 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), - false, - )({ - insTerm: { - validation: false, - }, - }); - return { - isValid: false, - message: - 'Невозможно включить страховку на весь срок для однолетнего полиса', - }; - } else { - calculationStore.setTableRow( - 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), - false, - )({ - insTerm: { - validation: true, - }, - }); - - return { - isValid: true, - }; - } - }, }; const elementsValidations: TElements = { diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index b526983..2311674 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -103,6 +103,60 @@ export default [ // }, // }), + calculationStore => ({ + expression: () => { + const { leasingPeriod } = calculationStore.values; + + const insTermValue = calculationStore.getTableRowValue( + 'tableInsurance', + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + 'insTerm', + 'value', + ); + + return { + insTerm: insTermValue, + leasingPeriod, + }; + }, + effect: ({ insTerm, leasingPeriod }) => { + const quote = calculationStore.getOption('selectQuote'); + const recalcWithRevision = calculationStore.getValue( + 'recalcWithRevision', + ); + if ( + recalcWithRevision && + quote?.evo_one_year_insurance && + leasingPeriod > 15 && + insTerm === 100000001 + ) { + setTimeout(() => { + calculationStore.setTableRow( + 'tableInsurance', + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + false, + )({ + insTerm: { value: 100000000, status: ElementStatus.Disabled }, + }); + }); + openNotification({ + type: 'info', + title: 'Внимание!', + description: + 'Срок страхования КАСКО изменен на 12 месяцев, т.к. оформляется Однолетний полис', + })(); + } else { + calculationStore.setTableRow( + 'tableInsurance', + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + false, + )({ + insTerm: { status: ElementStatus.Default }, + }); + } + }, + }), + (calculationStore, calculationProcess) => ({ expression: () => { const { leasingPeriod } = calculationStore.values; From 1765925e9327ea2a34b9869b8fcdc76475c8ff5a Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 29 Dec 2021 17:46:27 +0300 Subject: [PATCH 3/5] validation: check leasePeriod = payments.length --- .../actions/calculate/validate/elements.ts | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts index bbb883f..de60b9e 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -87,10 +87,10 @@ const customConditions: TElements = { tracker, requirementTelematic, } = calculationStore.getValues([ - 'telematic', - 'tracker', - 'requirementTelematic', - ]); + 'telematic', + 'tracker', + 'requirementTelematic', + ]); if (requirementTelematic !== 100000004 && !telematic && !tracker) { return { @@ -128,6 +128,17 @@ const customConditions: TElements = { 'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж', }; }, + + tbxLeasingPeriod: calculationStore => { + const leasingPeriod = calculationStore.getValue('leasingPeriod'); + const tablePaymentsLength = + calculationStore.tables.tablePayments.rows.length; + return { + isValid: leasingPeriod === tablePaymentsLength, + message: + 'Срок лизинга не соответствует таблице платежей. Необходимо изменить срок лизинга', + }; + }, }; const elementsValidations: TElements = { @@ -156,32 +167,32 @@ const elementsConditions = (Object.keys( elementsValidations, ) as ElementsNames[]).reduce( (ac: TElements, elementName) => { - ac[elementName] = pipe( - getValue, - elementsValidations[elementName], - convertToValidationResult, - ); - return ac; + ac[elementName] = pipe( + getValue, + elementsValidations[elementName], + convertToValidationResult, + ); + return ac; }, {}, ); const entityElementsConditions = ([ - 'selectIndAgentRewardCondition', - 'selectCalcBrokerRewardCondition', - 'selectFinDepartmentRewardCondtion', + 'selectIndAgentRewardCondition', + 'selectCalcBrokerRewardCondition', + 'selectFinDepartmentRewardCondtion', ] as ElementsNames[]).reduce( (ac: TElements, elementName) => { - const valueName = getValueName(elementName); - ac[elementName] = (calculationStore, elementName) => { - if (isNil(calculationStore.getValue(valueName))) { - return { isValid: true }; - } - return { - isValid: calculationStore.getOption(elementName) !== undefined, - }; + const valueName = getValueName(elementName); + ac[elementName] = (calculationStore, elementName) => { + if (isNil(calculationStore.getValue(valueName))) { + return { isValid: true }; + } + return { + isValid: calculationStore.getOption(elementName) !== undefined, }; - return ac; + }; + return ac; }, {}, ); From f39ae19e77291fd3de135ff38b7835e72ced0674 Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 30 Dec 2021 11:35:35 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9E=D1=82=D0=BA=D1=80=D1=8B=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=BF=D1=80=D0=B8=20=D0=9F=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D1=81=D1=87=D0=B5=D1=82=D0=B5=20=D0=B1=D0=B5=D0=B7?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B0?= =?UTF-8?q?=20(recalcWthtRevision)=20=3D=20true:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Последний платеж считается от radioLastPaymentRule Последний платеж, % tbxLastPaymentPerc Последний платеж, руб. tbxLastPaymentRub --- .../Effects/reactions/recalcWoRevisionReactions.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index 0e60198..c0fd2ef 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -475,9 +475,9 @@ const elementsToDisable: (ElementsNames | TableNames)[] = [ 'selectClientRisk', 'selectClientType', 'tbxLeasingPeriod', - 'tbxLastPaymentPerc', - 'tbxLastPaymentRub', - 'radioLastPaymentRule', + // 'tbxLastPaymentPerc', + // 'tbxLastPaymentRub', + // 'radioLastPaymentRule', 'radioGraphType', 'tbxParmentsDecreasePercent', 'selectSeasonType', From 7125ca8288f567c03e0a51555919b052f670628f Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 30 Dec 2021 12:09:11 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BA=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20=20=D0=9F=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=B9=20=D0=BF=D0=BB=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=B6,=20%=20tbxLastPaymentPerc=20=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=20=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=BF=D0=BB=D0=B0=D1=82=D0=B5=D0=B6,=20=D1=80=D1=83=D0=B1.?= =?UTF-8?q?=20tbxLastPaymentRub=20(=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=BA=D0=B5=20=D0=9A=D0=9F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ЕСЛИ Пересчет без пересмотра (recalcWthtRevision) = true, ТО Если tbxLastPaymentPerc > quote.evo_last_payment_perc из selectQuote И tbxLastPaymentPerc > 1 , то поля tbxLastPaymentPerc и tbxLastPaymentRub обводить красной рамкой и выводить сообщение "При пересчете без пересмотра последний платеж можно уменьшать или увеличивать до 1%" иначе с полей bxLastPaymentPerc и tbxLastPaymentRub убирать красную рамку ИНАЧЕ ничего не делаем --- .../CalculationStore/Effects/lib/queries.js | 1 + .../Effects/reactions/otherReactions.ts | 36 ----------- .../reactions/recalcWoRevisionReactions.ts | 60 +++++++++++++++++++ 3 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/lib/queries.js b/src/client/stores/CalculationStore/Effects/lib/queries.js index 2afc5b0..9b34d81 100644 --- a/src/client/stores/CalculationStore/Effects/lib/queries.js +++ b/src/client/stores/CalculationStore/Effects/lib/queries.js @@ -21,4 +21,5 @@ link evo_req_telematic evo_req_telematic_accept evo_one_year_insurance +evo_last_payment_perc `; diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index 21c0437..c09e4cb 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -655,42 +655,6 @@ const reactionEffects: IReactionEffect[] = [ }, }), - 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 { diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index c0fd2ef..e5c670d 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -460,6 +460,66 @@ const reactionEffects: IReactionEffect[] = [ fireImmediately: true, }, }), + + calculationStore => ({ + expression: () => calculationStore.getValues(['lastPaymentPerc']), + effect: ({ lastPaymentPerc }) => { + if (!calculationStore.getValue('recalcWithRevision')) { + calculationStore.setValidation('tbxLastPaymentPerc', undefined); + return; + } + + const quote = calculationStore.getOption('selectQuote'); + if ( + quote && + quote.evo_last_payment_perc && + lastPaymentPerc > 1 && + lastPaymentPerc > quote.evo_last_payment_perc + ) { + openNotification({ + type: 'error', + title: 'Ошибка', + description: + 'При пересчете без пересмотра последний платеж можно уменьшать или увеличивать до 1%', + })(); + calculationStore.setValidation('tbxLastPaymentPerc', false); + } else { + calculationStore.setValidation('tbxLastPaymentPerc', undefined); + } + }, + }), + + calculationStore => ({ + expression: () => + calculationStore.getValues(['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; + } + } + if (!calculationStore.getValue('recalcWithRevision')) + calculationStore.setValidation('tbxLastPaymentPerc', true); + }, + }), ]; const map_add_product_types_to_values = {