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..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,57 +128,16 @@ const customConditions: TElements = { 'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж', }; }, - // TODO: temp (move to tableInsurance validation) + 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( - 'tableInsurance', - kaskoRowIndex, - 'value', - ); - - const kaskoInsTerm = kaskoValues.insTerm; - - if ( - recalcWithRevision && - quote?.evo_one_year_insurance && - leasingPeriod > 16 && - kaskoInsTerm !== 100000000 - ) { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - false, - )({ - insTerm: { - validation: false, - }, - }); - return { - isValid: false, - message: - 'Невозможно включить страховку на весь срок для однолетнего полиса', - }; - } else { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - false, - )({ - insTerm: { - validation: true, - }, - }); - - return { - isValid: true, - }; - } + const leasingPeriod = calculationStore.getValue('leasingPeriod'); + const tablePaymentsLength = + calculationStore.tables.tablePayments.rows.length; + return { + isValid: leasingPeriod === tablePaymentsLength, + message: + 'Срок лизинга не соответствует таблице платежей. Необходимо изменить срок лизинга', + }; }, }; @@ -208,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; }, {}, ); 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/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/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..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 { @@ -877,31 +841,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/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index 0e60198..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 = { @@ -475,9 +535,9 @@ const elementsToDisable: (ElementsNames | TableNames)[] = [ 'selectClientRisk', 'selectClientType', 'tbxLeasingPeriod', - 'tbxLastPaymentPerc', - 'tbxLastPaymentRub', - 'radioLastPaymentRule', + // 'tbxLastPaymentPerc', + // 'tbxLastPaymentRub', + // 'radioLastPaymentRule', 'radioGraphType', 'tbxParmentsDecreasePercent', 'selectSeasonType', diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index 65b1157..2311674 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,44 +67,92 @@ export default [ }, }), - (calculationStore, calculationProcess) => ({ + // (calculationStore, calculationProcess) => ({ + // 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 }) => { + // 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 => ({ expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const kaskoRow = tableRows[kaskoRowIndex]; const { leasingPeriod } = calculationStore.values; + const insTermValue = calculationStore.getTableRowValue( + 'tableInsurance', + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + 'insTerm', + 'value', + ); + return { - insTerm: kaskoRow.insTerm?.value, + insTerm: insTermValue, leasingPeriod, }; }, effect: ({ insTerm, leasingPeriod }) => { - if (calculationProcess.hasProcess(Process.LoadKp)) { - return; - } - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', + const quote = calculationStore.getOption('selectQuote'); + const recalcWithRevision = calculationStore.getValue( + 'recalcWithRevision', ); - if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { - if (kaskoRowIndex >= 0) + if ( + recalcWithRevision && + quote?.evo_one_year_insurance && + leasingPeriod > 15 && + insTerm === 100000001 + ) { + setTimeout(() => { calculationStore.setTableRow( 'tableInsurance', - kaskoRowIndex, + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + false, )({ - insured: { value: 100000001, status: ElementStatus.Disabled }, + insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); + }); + openNotification({ + type: 'info', + title: 'Внимание!', + description: + 'Срок страхования КАСКО изменен на 12 месяцев, т.к. оформляется Однолетний полис', + })(); } else { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { status: ElementStatus.Default }, - }); + calculationStore.setTableRow( + 'tableInsurance', + rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + false, + )({ + insTerm: { status: ElementStatus.Default }, + }); } }, }), @@ -121,87 +164,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 +243,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 +269,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 +289,8 @@ export default [ description: 'Укажите стоимость КАСКО', })(); } else { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insCost: { validation: true, @@ -287,13 +302,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 +315,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 +334,8 @@ export default [ description: 'Укажите стоимость КАСКО, включаемую в график', })(); } else { - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'КАСКО'), )({ insCost: { validation: true, @@ -359,19 +364,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 +383,8 @@ export default [ description: 'Укажите стоимость ОСАГО, включаемую в график', })(); } else { - calculationStore.setTableRow( - 'tableInsurance', - osagoRowIndex, + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x.policyType?.value === 'ОСАГО'), )({ insCost: { validation: true, @@ -762,15 +761,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 +790,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 {