diff --git a/src/client/Containers/Calculation/Components/FinGAP/Table.jsx b/src/client/Containers/Calculation/Components/FinGAP/Table.jsx new file mode 100644 index 0000000..7e8860f --- /dev/null +++ b/src/client/Containers/Calculation/Components/FinGAP/Table.jsx @@ -0,0 +1,33 @@ +import { Table as AntTable } from 'antd'; +import { useStores } from 'client/hooks/useStores'; +import { toJS } from 'mobx'; +import { observer } from 'mobx-react-lite'; +import config from './config'; + +export default observer(() => { + const { calculationStore } = useStores(); + const { $finGAP } = calculationStore.stores; + + const dataSource = toJS($finGAP.risks); + const selectedRowKeys = Array.from(toJS($finGAP.selectedKeys)); + + return ( + { + const selectedKeys = selectedRows.reduce((acc, row) => { + acc.push(row.key); + if (row.keys) return acc.concat(row.keys); + return acc; + }, []); + + $finGAP.setSelectedKeys(selectedKeys); + }, + selectedRowKeys, + }} + /> + ); +}); diff --git a/src/client/Containers/Calculation/Components/FinGAP/Table.stories.jsx b/src/client/Containers/Calculation/Components/FinGAP/Table.stories.jsx new file mode 100644 index 0000000..51e577f --- /dev/null +++ b/src/client/Containers/Calculation/Components/FinGAP/Table.stories.jsx @@ -0,0 +1,31 @@ +import { Table as AntTable } from 'antd'; +import config from './config'; + +export default { + title: 'FinGAP', +}; + +const dataSource = [ + { + key: '1', + riskName: 'Риск 1', + sum: 1000, + premium: 10000, + }, + { + key: '1', + riskName: 'Риск 2', + sum: 5000, + premium: 50000, + }, + { + key: '3', + riskName: 'Риск 3', + sum: 10000, + premium: 100000, + }, +]; + +export const Table = () => { + return ; +}; diff --git a/src/client/Containers/Calculation/Components/FinGAP/config.ts b/src/client/Containers/Calculation/Components/FinGAP/config.ts new file mode 100644 index 0000000..458717d --- /dev/null +++ b/src/client/Containers/Calculation/Components/FinGAP/config.ts @@ -0,0 +1,30 @@ +import { TableProps } from 'antd'; +import { formatMoney } from 'core/tools/format'; +import { Risk } from './types'; + +const columns: TableProps['columns'] = [ + { + title: 'Риск', + dataIndex: 'riskName', + width: '55%', + }, + { + title: 'Страховая сумма', + dataIndex: 'sum', + render: value => formatMoney(value, 'RUB'), + }, + { + title: 'Страховая премия по риску', + dataIndex: 'premium', + render: value => formatMoney(value, 'RUB'), + }, +]; + +const config: TableProps = { + columns, + rowSelection: { type: 'checkbox' }, + pagination: false, + size: 'small', +}; + +export default config; diff --git a/src/client/Containers/Calculation/Components/FinGAP/index.js b/src/client/Containers/Calculation/Components/FinGAP/index.js new file mode 100644 index 0000000..de4c7d5 --- /dev/null +++ b/src/client/Containers/Calculation/Components/FinGAP/index.js @@ -0,0 +1,3 @@ +import Table from './Table'; + +export default Table; diff --git a/src/client/Containers/Calculation/Components/FinGAP/types.ts b/src/client/Containers/Calculation/Components/FinGAP/types.ts new file mode 100644 index 0000000..b7c2efd --- /dev/null +++ b/src/client/Containers/Calculation/Components/FinGAP/types.ts @@ -0,0 +1,10 @@ +export type Risk = { + key: string; + riskId: string; + riskName: string; + calcType: number; + premiumPerc: number; + sum: number; + premium: number; + keys?: string[]; +}; diff --git a/src/client/Containers/Calculation/Components/Results/resultsList.ts b/src/client/Containers/Calculation/Components/Results/resultsList.ts index 5dc8fa1..17ded19 100644 --- a/src/client/Containers/Calculation/Components/Results/resultsList.ts +++ b/src/client/Containers/Calculation/Components/Results/resultsList.ts @@ -44,6 +44,7 @@ export const calculationResults: ISection[] = [ 'labelResultBonusMPL', 'labelResultDopMPLLeasing', 'labelResultBonusDopProd', + 'labelResultBonusSafeFinance', ], }, ], diff --git a/src/client/Containers/Calculation/Components/Sections/sectionsList.ts b/src/client/Containers/Calculation/Components/Sections/sectionsList.ts index 402f4ab..19e9452 100644 --- a/src/client/Containers/Calculation/Components/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Components/Sections/sectionsList.ts @@ -209,48 +209,22 @@ const sections: ISection[] = [ { style: { columnsNumber: 3 }, blocks: [ - { - elements: ['selectBrand', 'selectModel', 'selectConfiguration'], - }, { elements: [ 'tbxLeaseObjectYear', 'selectEngineType', 'selectLeaseObjectCategory', - ], - }, - { - elements: [ 'tbxLeaseObjectMotorPower', 'tbxEngineVolume', - 'selectLeaseObjectUseFor', ], }, - ], - }, - { - style: { columnsNumber: 3 }, - blocks: [ { elements: [ - 'cbxInsDecentral', - // 'radioInsKaskoType', + 'selectLeaseObjectUseFor', 'tbxInsFranchise', 'tbxMileage', - 'radioInfuranceOPF', - // 'selectInsPeriod', - // 'btnFranschise', - ], - }, - { - elements: [ - // 'cbxInsUnlimitDrivers', - // 'tbxInsAgeDrivers', - // 'tbxInsExpDrivers', - 'selectGPSBrand', - 'selectGPSModel', - 'tbxInsKaskoPriceLeasePeriod', 'cbxWithTrailer', + 'cbxInsDecentral', ], }, { @@ -258,6 +232,8 @@ const sections: ISection[] = [ 'selectLegalClientRegion', 'selectLegalClientTown', 'tbxINNForCalc', + 'selectGPSBrand', + 'selectGPSModel', ], }, ], @@ -270,6 +246,15 @@ const sections: ISection[] = [ }, ], }, + { + title: 'Риски Safe Finance', + style: { columnsNumber: 1 }, + blocks: [ + { + elements: ['componentfinGAP'], + }, + ], + }, ], }, { @@ -346,7 +331,7 @@ const sections: ISection[] = [ style: { columnsNumber: 1 }, blocks: [ { - style: { columnsNumber: 2 }, + style: { columnsNumber: 3 }, elements: [ // 'cbxLastPaymentRedemption', 'cbxPriceWithDiscount', @@ -357,6 +342,7 @@ const sections: ISection[] = [ 'cbxTechnicalCardQuote', 'cbxNSIB', 'cbxQuoteRedemptionGraph', + 'cbxShowFinGAP', ], }, ], diff --git a/src/client/Containers/Calculation/Elements/builders/index.ts b/src/client/Containers/Calculation/Elements/builders/index.ts index 2a200ed..74f2c19 100644 --- a/src/client/Containers/Calculation/Elements/builders/index.ts +++ b/src/client/Containers/Calculation/Elements/builders/index.ts @@ -1,4 +1,5 @@ import ELT from '../../Components/ELT'; +import finGAP from '../../Components/FinGAP'; import { CustomComponents, NonValueElementsNames } from '../../types/elements'; import { TableNames } from '../../types/tables'; import components from '../components'; @@ -29,6 +30,7 @@ const overrideBuilders: Record< btnCalculate: buildAction, linkDownloadKp: buildLink, componentElt: () => ELT, + componentfinGAP: () => finGAP, tablePayments: ({ name, Component }) => buildTable({ name, Component, ...tables[name] }), tableInsurance: ({ name, Component }) => diff --git a/src/client/Containers/Calculation/Elements/components.ts b/src/client/Containers/Calculation/Elements/components.ts index d5fb139..863e5f4 100644 --- a/src/client/Containers/Calculation/Elements/components.ts +++ b/src/client/Containers/Calculation/Elements/components.ts @@ -99,6 +99,7 @@ export default { cbxTechnicalCardQuote: Switch, cbxNSIB: Switch, cbxQuoteRedemptionGraph: Switch, + cbxShowFinGAP: Switch, tbxQuoteName: Input, radioQuoteContactGender: Radio, cbxDisableChecks: Switch, @@ -153,6 +154,7 @@ export default { labelResultBonusMPL: Label, labelResultDopMPLLeasing: Label, labelResultBonusDopProd: Label, + labelResultBonusSafeFinance: Label, /** Button Elements */ btnCreateKP: Button, diff --git a/src/client/Containers/Calculation/Elements/props/common.ts b/src/client/Containers/Calculation/Elements/props/common.ts index 13aba13..4247037 100644 --- a/src/client/Containers/Calculation/Elements/props/common.ts +++ b/src/client/Containers/Calculation/Elements/props/common.ts @@ -365,6 +365,7 @@ const moneyResultElementsProps = ( 'labelResultDopMPLLeasing', 'labelResultBonusDopProd', 'labelSubsidySum', + 'labelResultBonusSafeFinance', ] as ElementsNames[] ).reduce( (ac, a) => ({ diff --git a/src/client/Containers/Calculation/Elements/tables/insurance.ts b/src/client/Containers/Calculation/Elements/tables/insurance.ts index 415ce89..addfdb0 100644 --- a/src/client/Containers/Calculation/Elements/tables/insurance.ts +++ b/src/client/Containers/Calculation/Elements/tables/insurance.ts @@ -2,10 +2,7 @@ import InputNumber from 'client/Elements/InputNumber'; import Label from 'client/Elements/Label'; import { openNotification } from 'client/Elements/Notification'; import Select from 'client/Elements/Select'; -import { - insuranceKaskoDefaultFilter, - insuranceOsagoDefaultFilter, -} from 'core/constants/stores/Calculation/filters'; +import * as filters from 'core/constants/stores/Calculation/filters'; import { MAX_INSURANCE } from 'core/constants/stores/Calculation/limits'; import { formatNumber } from 'core/tools/format'; import { ElementStatus } from 'types/elements'; @@ -57,12 +54,13 @@ const columns: Column[] = [ const rows: Table['rows'] = [ { + key: 'osago', policyType: { value: 'ОСАГО', }, insuranceCompany: { value: null, - filter: insuranceOsagoDefaultFilter, + filter: filters.insuranceOsagoDefaultFilter, }, insured: { value: 100000000, @@ -76,12 +74,13 @@ const rows: Table['rows'] = [ }, }, { + key: 'kasko', policyType: { value: 'КАСКО', }, insuranceCompany: { value: null, - filter: insuranceKaskoDefaultFilter, + filter: filters.insuranceKaskoDefaultFilter, }, insured: { value: 100000000, @@ -95,13 +94,14 @@ const rows: Table['rows'] = [ }, }, { + key: 'dgo', policyType: { value: 'ДГО', }, insuranceCompany: { value: null, status: ElementStatus.Disabled, - filter: insuranceKaskoDefaultFilter, + filter: filters.insuranceKaskoDefaultFilter, }, insured: { value: null, @@ -116,13 +116,14 @@ const rows: Table['rows'] = [ }, }, { + key: 'ns', policyType: { value: 'НС', }, insuranceCompany: { value: null, status: ElementStatus.Disabled, - filter: insuranceKaskoDefaultFilter, + filter: filters.insuranceKaskoDefaultFilter, }, insured: { value: null, @@ -136,6 +137,26 @@ const rows: Table['rows'] = [ status: ElementStatus.Disabled, }, }, + { + key: 'finGAP', + policyType: { + value: 'Safe Finance', + }, + insuranceCompany: { + value: null, + filter: filters.insurancefinGAPDefaultFilter, + }, + insured: { + value: 100000000, + }, + insCost: { + value: 0, + status: ElementStatus.Disabled, + }, + insTerm: { + value: null, + }, + }, ]; const callbacks: Table['callbacks'] = { diff --git a/src/client/Containers/Calculation/Elements/titles.ts b/src/client/Containers/Calculation/Elements/titles.ts index 9cec879..6b9237d 100644 --- a/src/client/Containers/Calculation/Elements/titles.ts +++ b/src/client/Containers/Calculation/Elements/titles.ts @@ -79,6 +79,7 @@ export const elementsTitles: Partial> = { tbxInsAgeDrivers: 'Наименьший возраст водителей', tbxInsExpDrivers: 'Наименьший стаж водителей', cbxLastPaymentRedemption: 'Последний платеж считать выкупным', + cbxShowFinGAP: 'Отображать EVO-Safe Finance', cbxPriceWithDiscount: 'Отображать стоимость ПЛ со скидкой', cbxFullPriceWithDiscount: 'Отображать полную стоимость ПЛ (без скидки)', cbxCostIncrease: 'Отображать удорожание', @@ -139,6 +140,7 @@ export const elementsTitles: Partial> = { labelResultBonusMPL: 'Бонус МПЛ за лизинг, без НДФЛ', labelResultDopMPLLeasing: 'Доп.бонус МПЛ за лизинг, без НДФЛ', labelResultBonusDopProd: 'Бонус МПЛ за доп.продукты, без НДФЛ', + labelResultBonusSafeFinance: 'Бонус за Safe Finance без НДФЛ', }; export const tablesTitles: Record = { diff --git a/src/client/Containers/Calculation/Elements/values.ts b/src/client/Containers/Calculation/Elements/values.ts index ac868ed..ec85204 100644 --- a/src/client/Containers/Calculation/Elements/values.ts +++ b/src/client/Containers/Calculation/Elements/values.ts @@ -99,6 +99,7 @@ const elementsValues: Record = { tbxQuoteName: 'quoteName', radioQuoteContactGender: 'quoteContactGender', cbxQuoteRedemptionGraph: 'quoteRedemptionGraph', + cbxShowFinGAP: 'showFinGAP', selectTarif: 'tarif', tbxCreditRate: 'creditRate', selectRate: 'rate', @@ -146,6 +147,7 @@ const elementsValues: Record = { labelResultBonusMPL: 'resultBonusMPL', labelResultDopMPLLeasing: 'resultDopMPLLeasing', labelResultBonusDopProd: 'resultBonusDopProd', + labelResultBonusSafeFinance: 'resultBonusSafeFinance', }; const elementsComputedValues: Record< diff --git a/src/client/Containers/Calculation/types/elements.ts b/src/client/Containers/Calculation/types/elements.ts index 9143c85..2ed54d7 100644 --- a/src/client/Containers/Calculation/types/elements.ts +++ b/src/client/Containers/Calculation/types/elements.ts @@ -86,6 +86,7 @@ export type ElementsNames = | 'tbxQuoteName' | 'radioQuoteContactGender' | 'cbxQuoteRedemptionGraph' + | 'cbxShowFinGAP' | 'selectTarif' | 'tbxCreditRate' | 'selectRate' @@ -131,7 +132,9 @@ export type ElementsNames = | 'labelResultAB_UL' | 'labelResultBonusMPL' | 'labelResultDopMPLLeasing' - | 'labelResultBonusDopProd'; + | 'labelResultBonusDopProd' + | 'labelResultBonusSafeFinance'; + export type ButtonElementsNames = 'btnCreateKP' | 'btnCalculate'; export type LinkElementsNames = 'linkDownloadKp'; export type ComputedElementsNames = @@ -140,7 +143,7 @@ export type ComputedElementsNames = | 'labelIrrInfo' | 'labelRegistrationDescription'; -export type CustomComponents = 'componentElt'; +export type CustomComponents = 'componentElt' | 'componentfinGAP'; /** GROUPS */ export type InteractionElementsNames = diff --git a/src/client/Containers/Calculation/types/tables.ts b/src/client/Containers/Calculation/types/tables.ts index 25d0031..72a2bdb 100644 --- a/src/client/Containers/Calculation/types/tables.ts +++ b/src/client/Containers/Calculation/types/tables.ts @@ -42,7 +42,7 @@ export type Column = { export type Table = { columns: Column[]; - rows: Partial>[]; + rows: (Partial> & { key?: string })[]; options?: Partial>; params?: { features?: Record }; callbacks?: Partial>; diff --git a/src/client/Elements/Table.jsx b/src/client/Elements/Table.jsx index 47be296..c84d7d3 100644 --- a/src/client/Elements/Table.jsx +++ b/src/client/Elements/Table.jsx @@ -95,9 +95,10 @@ function buildBody( {rows.map((row, rowIndex) => { const partRowIndex = rowIndex + partNumber * rowsNumber; return ( - + {features?.numerize && {partRowIndex + 1}} {Object.keys(row).map(propName => { + if (propName === 'key') return null; const CellComponent = columnsProps[propName].Component; const Cell = withTableValue(CellComponent)({ tableName, diff --git a/src/client/process/fingap/reactions/common.ts b/src/client/process/fingap/reactions/common.ts new file mode 100644 index 0000000..fae5a32 --- /dev/null +++ b/src/client/process/fingap/reactions/common.ts @@ -0,0 +1,191 @@ +import { Risk } from 'client/Containers/Calculation/Components/FinGAP/types'; +import CoreService from 'core/services/CoreService'; +import * as FinGAP from 'core/services/CoreService/types/Cerebellum/finGAP'; +import { ICalculationStore } from 'core/types/Calculation/Store'; +import { comparer, reaction } from 'mobx'; +import { ElementStatus } from 'types/elements'; + +export function commonReactions(calculationStore: ICalculationStore) { + // Расчет итоговой суммы ФинГАП и запись в таблицу страхования + reaction( + () => { + const { $finGAP } = calculationStore.stores; + return $finGAP.totalSum(); + }, + totalSum => { + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x?.key === 'finGAP'), + )({ + insCost: { value: totalSum }, + }); + }, + ); + + /** +Реакция на изменение Страховой компании у ФинГАП и Срока лизинга: + +Если Страхованя компания = Не выбрано, то + +Плательщик insuredFinGAP = ЛП (100 000 000) и закрыто для редактирования, +Стоимость за первый период inscostFinGAP = 0 +Срок страхования insTermFinGAP = 12 мес (100 000 000) и закрыто для редактирования +иначе + +Плательщик insuredFinGAP = открыто для редактирования, +Стоимость за первый период inscostFinGAP = 0 +Срок страхования insTermFinGAP = Если срок лизинга tbxLeasingPeriod < 13, то указываем Срок страхования insTermFinGAP =12 мес и закрываем для редактирования, иначе открыто для редактирования + */ + reaction( + () => { + const { rows: insuranceRows } = calculationStore.tables.tableInsurance; + const finGAPRow = insuranceRows.find(x => x.key === 'finGAP'); + const insuranceCompany = finGAPRow?.insuranceCompany?.value; + + const { leasingPeriod } = calculationStore.values; + + return { + insuranceCompany, + leasingPeriod, + }; + }, + ({ insuranceCompany, leasingPeriod }) => { + if (!insuranceCompany) { + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x?.key === 'finGAP'), + )({ + insured: { value: 100000000, status: ElementStatus.Disabled }, + insCost: { value: 0 }, + insTerm: { value: 100000000, status: ElementStatus.Disabled }, + }); + } else { + calculationStore.setTableRow('tableInsurance', rows => + rows.findIndex(x => x?.key === 'finGAP'), + )({ + insured: { status: ElementStatus.Default }, + // insCost: { value: 0 }, + insTerm: + leasingPeriod < 13 + ? { value: 100000000, status: ElementStatus.Disabled } + : { status: ElementStatus.Default }, + }); + } + }, + { + equals: comparer.shallow, + }, + ); + + // Заполнение таблицы рисков ФинГАП + reaction( + () => { + const { rows: insuranceRows } = calculationStore.tables.tableInsurance; + const finGAPRow = insuranceRows.find(x => x.key === 'finGAP'); + const insuranceCompany = finGAPRow?.insuranceCompany?.value; + return insuranceCompany; + }, + insuranceCompany => { + const { $finGAP } = calculationStore.stores; + + if (!insuranceCompany) { + $finGAP.clear(); + return; + } + + const add_product_types = calculationStore.getStaticData( + 'evo_addproduct_type', + ); + + const risks = add_product_types + .filter( + x => + x.evo_accountid === insuranceCompany && + x.evo_product_type === 100_000_006, + ) + .map( + x => + ({ + key: x.evo_addproduct_typeid, + riskId: x.evo_addproduct_typeid, + riskName: x.evo_name, + calcType: x.evo_type_calc_cerebellum, + premiumPerc: x.evo_cost_service_provider_withoutnds, + sum: 0, + premium: 0, + keys: x.evo_addproduct_types?.map(x => x.evo_addproduct_typeid), + } as Risk), + ); + + $finGAP.setRisks(risks); + }, + ); + + // Запрос расчета финГАП в мозжечок + reaction( + () => { + const { rows: insuranceRows } = calculationStore.tables.tableInsurance; + const finGAPRow = insuranceRows.find(x => x.key === 'finGAP'); + const insuranceCompany = finGAPRow?.insuranceCompany?.value; + + const paymentsRows = calculationStore.tables.tablePayments.rows; + const payments: FinGAP.PaymentRow[] = paymentsRows.map(x => ({ + percentPayment: x.paymentRelation?.value, + })); + + // TODO: types for CalculationStore ComputedValues + //@ts-ignore + const plPrice = calculationStore.plPriceRub(); + //@ts-ignore + const discount = calculationStore.discountRub(); + const { firstPaymentRub, leasingPeriod } = calculationStore.values; + + return { + payments, + insuranceCompany, + plPrice, + discount, + leasingPeriod, + firstPaymentRub, + }; + }, + ({ + payments, + insuranceCompany, + plPrice, + discount, + leasingPeriod, + firstPaymentRub, + }) => { + if (!insuranceCompany) return; + + const requestValues: FinGAP.RequestFinGAP['values'] = { + plPrice, + discount, + firstPayment: firstPaymentRub, + leasingPeriod, + premiumPerc: 0, + }; + + const { $finGAP } = calculationStore.stores; + const requests = $finGAP.risks.map(x => + CoreService.finGAP({ + calcType: x.calcType, + payments, + values: { ...requestValues, premiumPerc: x.premiumPerc }, + }), + ); + Promise.all(requests).then(results => { + const risks = $finGAP.risks.map((x, i) => ({ + ...x, + sum: results[i].sum, + premium: results[i].premium, + })); + $finGAP.setRisks(risks); + }); + }, + { + equals: comparer.structural, + // Important: delay prohibits multiple reaction invocation + delay: 100, + }, + ); +} diff --git a/src/client/process/fingap/reactions/index.js b/src/client/process/fingap/reactions/index.js new file mode 100644 index 0000000..b4c1022 --- /dev/null +++ b/src/client/process/fingap/reactions/index.js @@ -0,0 +1,5 @@ +import { commonReactions } from './common'; + +const finGapReactions = [commonReactions]; +export const injectFinGapReactions = calculationStore => + finGapReactions.map(injector => injector(calculationStore)); diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts index c961457..fafb3c4 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts @@ -1,6 +1,6 @@ import { message } from 'antd'; import { openNotification } from 'client/Elements/Notification'; -import CalculationService from 'core/services/CalculationService'; +import CoreService from 'core/services/CoreService'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { ValuesNames } from 'core/types/Calculation/Store/values'; import { ElementStatus } from 'types/elements'; @@ -96,9 +96,7 @@ export default function (this: ICalculationStore) { this.cleanTable('tableResults'); cleanResults(); - return CalculationService.calculate( - Object.assign(preparedData, { additionalData }), - ) + return CoreService.calculate(Object.assign(preparedData, { additionalData })) .then(res => { console.log('calculation res', res); diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts index 2b26685..a347581 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts @@ -2,8 +2,8 @@ import valuesConstants from 'core/constants/values'; import { PaymentRow, PreparedValues, -} from 'core/services/CalculationService/types/prepared'; -import { PreparedData } from 'core/services/CalculationService/types/request'; +} from 'core/services/CoreService/types/Calculation/prepared'; +import { PreparedData } from 'core/services/CoreService/types/Calculation/request'; import { currentDate } from 'core/tools/date'; import { NIL } from 'core/tools/uuid'; import { ICalculationStore } from 'core/types/Calculation/Store'; @@ -140,19 +140,21 @@ export default function (this: ICalculationStore): PreparedData { preparedValues.transportTaxGr = values.vehicleTaxInLeasingPeriod; const insuranceKaskoRow = tables.tableInsurance.rows.find( - x => x.policyType?.value === 'КАСКО', + x => x?.key === 'kasko', ); - const insuranceNSRow = tables.tableInsurance.rows.find( - x => x.policyType?.value === 'НС', - ); + const insuranceNSRow = tables.tableInsurance.rows.find(x => x?.key === 'ns'); const insuranceDGORow = tables.tableInsurance.rows.find( - x => x.policyType?.value === 'ДГО', + x => x?.key === 'dgo', ); const insuranceOSAGORow = tables.tableInsurance.rows.find( - x => x.policyType?.value === 'ОСАГО', + x => x?.key === 'osago', + ); + + const insuranceFinGAPRow = tables.tableInsurance.rows.find( + x => x?.key === 'finGAP', ); if (insuranceKaskoRow?.insured?.value === 100000001) { @@ -172,6 +174,16 @@ export default function (this: ICalculationStore): PreparedData { ? insuranceOSAGORow?.insCost?.value : 0; + preparedValues.insuranceFinGAP = + insuranceFinGAPRow?.insured?.value === 100000001 + ? insuranceFinGAPRow.insCost?.value + : 0; + + preparedValues.nmperFinGAP = + insuranceFinGAPRow?.insTerm?.value === 100000001 + ? values.leasingPeriod + : 12; + preparedValues.insuranceKaskoNmper = (preparedValues.nmperInsurance || 0) >= 16 ? ((preparedValues.insuranceKasko || 0) * @@ -594,6 +606,52 @@ export default function (this: ICalculationStore): PreparedData { } } + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser && + !Array.isArray(systemuser) + ) { + const evo_sot_coefficient_type = this.getStaticData( + 'evo_sot_coefficient_type', + ).find(x => x.evo_id === 'BONUS_FINGAP_PR'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_job_titleid === systemuser.evo_job_titleid && + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.bonusFinGAP = + (evo_coefficient.evo_sot_coefficient || 0) * + (insuranceFinGAPRow?.insCost?.value || 0); + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = this.getStaticData( + 'evo_sot_coefficient_type', + ).find(x => x.evo_id === 'DIRECTOR_BONUS_FINGAP'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.directorBonusFinGAP = + (evo_coefficient.evo_sot_coefficient || 0) * + (insuranceFinGAPRow?.insCost?.value || 0); + } + } + preparedValues.insuranceBonus = 0; preparedValues.cityc = values.townRegistration || values.regionRegistration; diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts index 2cd5880..4ae4566 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts @@ -3,7 +3,7 @@ import valuesConstants from 'core/constants/values'; import { GetCalculationResponse, PreparedData, -} from 'core/services/CalculationService/types/request'; +} from 'core/services/CoreService/types/Calculation/request'; import { ICalculationStore } from 'core/types/Calculation/Store'; export default { @@ -89,7 +89,8 @@ export default { (preparedData?.preparedValues?.registration || 0) + (preparedData?.preparedValues?.trackerCost || 0) + (preparedData?.preparedValues?.tLMCost || 0) + - (preparedData?.preparedValues?.nsibBrutto || 0), + (preparedData?.preparedValues?.nsibBrutto || 0) + + (preparedData?.preparedValues?.insuranceFinGAPNmper || 0), ); this.setValue( 'resultFirstPayment', @@ -143,6 +144,11 @@ export default { (1 - valuesConstants.NDFL), ), ); + this.setValue( + 'resultBonusSafeFinance', + (preparedData?.preparedValues?.bonusFinGAP || 0) * + (1 - valuesConstants.NDFL), + ); }, setResValues: function ( this: ICalculationStore, 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 4319c17..3255687 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts @@ -7,11 +7,11 @@ const { PERIODS_NUMBER } = valuesConstants; function validateInsuranceTable(this: ICalculationStore) { const osagoRow = this.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows => rows.findIndex(x => x?.key === 'osago'), 'value', ); this.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insuranceCompany: { validation: !isNil(osagoRow.insuranceCompany), @@ -23,11 +23,11 @@ function validateInsuranceTable(this: ICalculationStore) { const kaskoRow = this.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows => rows.findIndex(x => x?.key === 'kasko'), 'value', ); this.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insuranceCompany: { validation: !isNil(kaskoRow.insuranceCompany), diff --git a/src/client/stores/CalculationStore/Effects/actions/createKP.ts b/src/client/stores/CalculationStore/Effects/actions/createKP.ts index f86a29c..133517e 100644 --- a/src/client/stores/CalculationStore/Effects/actions/createKP.ts +++ b/src/client/stores/CalculationStore/Effects/actions/createKP.ts @@ -16,14 +16,17 @@ async function composeRequest(this: ICalculationStore) { if (!calculationRes) return; - const insurances = this.tables.tableInsurance.rows.map( - insuranceRow => - Object.keys(insuranceRow).reduce((acc, v) => { - acc[v] = toJS(insuranceRow[v].value); - return acc; - }, {}), - {}, - ); + const insurance = this.tables.tableInsurance.rows.map(insuranceRow => { + const values = Object.keys(insuranceRow).reduce((row, propName) => { + row[propName] = toJS(insuranceRow[propName].value); + return row; + }, {}); + + return { + ...values, + key: insuranceRow.key, + }; + }, {}); const elt = Object.assign( {}, @@ -32,6 +35,8 @@ async function composeRequest(this: ICalculationStore) { })), ); + const finGAP = this.stores.$finGAP.getSelectedRisks(); + const insKaskoPriceLeasePeriodValue = insKaskoPriceLeasePeriod.call(this); const calculationValues = Object.assign({}, toJS(this.values), { insKaskoPriceLeasePeriod: insKaskoPriceLeasePeriodValue, @@ -41,10 +46,11 @@ async function composeRequest(this: ICalculationStore) { const payload = { domainName: domainname, calculation: { - insurances, calculationValues, ...calculationRes, }, + insurance, + finGAP, elt, }; return payload; diff --git a/src/client/stores/CalculationStore/Effects/computed.ts b/src/client/stores/CalculationStore/Effects/computed.ts index be48a1d..8b41861 100644 --- a/src/client/stores/CalculationStore/Effects/computed.ts +++ b/src/client/stores/CalculationStore/Effects/computed.ts @@ -1,5 +1,6 @@ import { ICalculationStore } from 'core/types/Calculation/Store'; import { ComputedValuesNames } from 'core/types/Calculation/Store/values'; +import { convertPrice } from './lib/tools'; const LEASE_OBJECT_RISK = { 100000000: 'Низкий', @@ -59,6 +60,42 @@ const computedEffects: Record = { const registration = this.getOption('selectRegistration'); return registration?.evo_description; }, + + plPriceRub: function () { + const supplierCurrency = this.getOption('selectSupplierCurrency'); + const { leaseObjectPrice } = this.values; + + const evo_currencychanges = this.getStaticData('evo_currencychange'); + const evo_currencychange = evo_currencychanges.find( + x => + x.evo_ref_transactioncurrency === + supplierCurrency?.transactioncurrencyid, + ); + + return convertPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice, + evo_currencychange?.evo_currencychange || 1, + ); + }, + + discountRub: function () { + const supplierCurrency = this.getOption('selectSupplierCurrency'); + const { supplierDiscountRub } = this.values; + + const evo_currencychanges = this.getStaticData('evo_currencychange'); + const evo_currencychange = evo_currencychanges.find( + x => + x.evo_ref_transactioncurrency === + supplierCurrency?.transactioncurrencyid, + ); + + return convertPrice( + supplierCurrency?.isocurrencycode, + supplierDiscountRub, + evo_currencychange?.evo_currencychange || 1, + ); + }, }; export default computedEffects; diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index 13eeb73..97461e0 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -221,9 +221,25 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ insCost: { value: quote.evo_ns_price }, insTerm: { value: quote.evo_insurance_period }, }, + { + insuranceCompany: { + value: quote.evo_fingap_accountid, + }, + insured: { value: quote.evo_fingap_payer }, + // insCost: { value: quote.evo_fingap_price }, + insTerm: { value: quote.evo_fingap_period }, + }, ]); // fill insurance table + // fill finGAP + const selectedRisks = quote.evo_product_risks?.map( + x => x.evo_addproduct_typeid, + ); + const { $finGAP } = calculationStore.stores; + if (selectedRisks) $finGAP.setSelectedKeys(selectedRisks); + // fill finGAP + // fill payments table let evo_graph: IEvoGraph = {}; if (quote.evo_graphs) { diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index e23d999..9cd8fc6 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -19,7 +19,7 @@ export default [ expression: () => { const kaskoValues = calculationStore.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows => rows.findIndex(x => x?.key === 'kasko'), 'value', ); @@ -33,9 +33,7 @@ export default [ } if (insTerm) { const { rows: tableRows } = calculationStore.tables.tableInsurance; - const dgoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ДГО', - ); + const dgoRowIndex = tableRows.findIndex(x => x?.key === 'dgo'); if (dgoRowIndex && dgoRowIndex >= 0) calculationStore.setTableRows( 'tableInsurance', @@ -74,7 +72,7 @@ export default [ // const insTermValue = calculationStore.getTableRowValue( // 'tableInsurance', - // rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // rows => rows.findIndex(x => x?.key === 'kasko'), // 'insTerm', // 'value', // ); @@ -90,13 +88,13 @@ export default [ // } // if (insTerm === 100000001 && leasingPeriod > 15) { // calculationStore.setTableRow('tableInsurance', rows => - // rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // rows.findIndex(x => x?.key === 'kasko'), // )({ // insured: { value: 100000001, status: ElementStatus.Disabled }, // }); // } else { // calculationStore.setTableRow('tableInsurance', rows => - // rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // rows.findIndex(x => x?.key === 'kasko'), // )({ // insured: { status: ElementStatus.Default }, // }); @@ -110,7 +108,7 @@ export default [ const insTermValue = calculationStore.getTableRowValue( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows => rows.findIndex(x => x?.key === 'kasko'), 'insTerm', 'value', ); @@ -133,7 +131,7 @@ export default [ setTimeout(() => { calculationStore.setTableRow( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows => rows.findIndex(x => x?.key === 'kasko'), false, )({ insTerm: { value: 100000000, status: ElementStatus.Disabled }, @@ -158,36 +156,36 @@ export default [ if (leasingPeriod) { if (leasingPeriod < 12) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insured: { value: 100000000, status: ElementStatus.Disabled }, }); calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insured: { value: 100000000, status: ElementStatus.Disabled }, insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); } else if (leasingPeriod === 12) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insured: { status: ElementStatus.Default }, }); calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insured: { status: ElementStatus.Default }, insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); } else if (leasingPeriod > 12 && leasingPeriod < 16) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insured: { status: ElementStatus.Default }, }); calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insured: { status: ElementStatus.Default }, insTerm: { value: 100000001, status: ElementStatus.Disabled }, @@ -197,30 +195,30 @@ export default [ // && // calculationStore.getTableRowValue( // 'tableInsurance', - // rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + // rows => rows.findIndex(x => x?.key === 'kasko'), // 'insTerm', // 'value', // ) === 100000001 ) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insured: { status: ElementStatus.Default }, }); calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insured: { status: ElementStatus.Default }, insTerm: { value: 100000000, status: ElementStatus.Disabled }, }); } else { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insured: { status: ElementStatus.Default }, }); calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insured: { status: ElementStatus.Default }, insTerm: { status: ElementStatus.Disabled }, @@ -237,17 +235,17 @@ export default [ expression: () => { const kaskoValues = calculationStore.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows => rows.findIndex(x => x?.key === 'kasko'), 'value', ); const dgoValues = calculationStore.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'ДГО'), + rows => rows.findIndex(x => x?.key === 'dgo'), 'value', ); const nsValues = calculationStore.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'НС'), + rows => rows.findIndex(x => x?.key === 'ns'), 'value', ); @@ -268,7 +266,7 @@ export default [ ((dgoRow && dgoRow.insCost > 0) || (nsRow && nsRow.insCost > 0)) ) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insCost: { validation: false, @@ -282,7 +280,7 @@ export default [ }); } else { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insCost: { validation: true, @@ -296,7 +294,7 @@ export default [ expression: () => { const kaskoValues = calculationStore.getTableRowValues( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows => rows.findIndex(x => x?.key === 'kasko'), 'value', ); return { @@ -314,7 +312,7 @@ export default [ kaskoRow.insCost === 0 ) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insCost: { validation: false, @@ -327,7 +325,7 @@ export default [ }); } else { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insCost: { validation: true, @@ -340,9 +338,7 @@ export default [ (calculationStore, calculationProcess) => ({ expression: () => { const { rows: tableRows } = calculationStore.tables.tableInsurance; - const osagoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'ОСАГО', - ); + const osagoRowIndex = tableRows.findIndex(x => x?.key === 'osago'); const osagoValues = calculationStore.getTableRowValues( 'tableInsurance', osagoRowIndex, @@ -363,7 +359,7 @@ export default [ osagoRow.insCost === 0 ) { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insCost: { validation: false, @@ -376,7 +372,7 @@ export default [ }); } else { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows.findIndex(x => x?.key === 'osago'), )({ insCost: { validation: true, @@ -758,7 +754,7 @@ export default [ ); calculationStore.setTableRow( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows => rows.findIndex(x => x?.key === 'osago'), true, )({ insuranceCompany: { @@ -779,7 +775,7 @@ export default [ } else { calculationStore.setTableRow( 'tableInsurance', - rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), + rows => rows.findIndex(x => x?.key === 'osago'), true, )({ insuranceCompany: { @@ -815,7 +811,7 @@ export default [ targetInsuranceCompany.value, ); calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insuranceCompany: { filter: targetInsuranceFilter, @@ -826,7 +822,7 @@ export default [ } } else { calculationStore.setTableRow('tableInsurance', rows => - rows.findIndex(x => x.policyType?.value === 'КАСКО'), + rows.findIndex(x => x?.key === 'kasko'), )({ insuranceCompany: { filter: insuranceKaskoDefaultFilter, diff --git a/src/client/stores/CalculationStore/config/initialValues.ts b/src/client/stores/CalculationStore/config/initialValues.ts index 0b130d3..cbb0488 100644 --- a/src/client/stores/CalculationStore/config/initialValues.ts +++ b/src/client/stores/CalculationStore/config/initialValues.ts @@ -69,6 +69,7 @@ const initialValues: Partial> = { NSIB: true, quoteContactGender: 100000000, quoteRedemptionGraph: true, + showFinGAP: true, creditRate: valuesConstants.RATE, requirementTelematic: 100000000, maxPriceChange: 0, diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts index d0d0017..6643467 100644 --- a/src/client/stores/CalculationStore/index.ts +++ b/src/client/stores/CalculationStore/index.ts @@ -1,3 +1,4 @@ +import { injectFinGapReactions } from 'client/process/fingap/reactions'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { isEqual } from 'lodash'; import { autorun, makeAutoObservable, reaction, when } from 'mobx'; @@ -33,6 +34,7 @@ reactionEffects.map(reactionEffectBuilder => { ((nextParams, prevParams) => isEqual(nextParams, prevParams)), }); }); +injectFinGapReactions(CalculationStore); whenEffects.map(whenEffectBuilder => { const whenEffect = whenEffectBuilder(CalculationStore); diff --git a/src/client/stores/CalculationStore/subStores/finGAP.ts b/src/client/stores/CalculationStore/subStores/finGAP.ts new file mode 100644 index 0000000..62d5827 --- /dev/null +++ b/src/client/stores/CalculationStore/subStores/finGAP.ts @@ -0,0 +1,32 @@ +import { Risk } from 'client/Containers/Calculation/Components/FinGAP/types'; +import { makeAutoObservable, observable, toJS } from 'mobx'; + +const finGAP = makeAutoObservable({ + risks: observable([]), + setRisks(risks: Risk[]) { + this.risks.replace(risks); + }, + getSelectedRisks() { + return toJS(this.risks.filter(x => this.selectedKeys.has(x.key))); + }, + + selectedKeys: new Set() as Set, + setSelectedKeys(keys: string[]) { + this.selectedKeys = new Set(keys); + }, + + totalSum() { + return this.risks + .filter(risk => this.selectedKeys.has(risk.key)) + .reduce((sum, row) => sum + row.premium, 0); + }, + + clear() { + this.risks.clear(); + this.selectedKeys.clear(); + }, +}); + +export default finGAP; + +export type TFinGAP = typeof finGAP; diff --git a/src/client/stores/CalculationStore/subStores/index.js b/src/client/stores/CalculationStore/subStores/index.js index 080e880..d33b8f6 100644 --- a/src/client/stores/CalculationStore/subStores/index.js +++ b/src/client/stores/CalculationStore/subStores/index.js @@ -1,9 +1,11 @@ import calculationProcess from './calculationProcess'; import calculationUrls from './calculationUrls'; import ELTStore from './eltStore'; +import $finGAP from './finGAP'; export default { calculationProcess, calculationUrls, ELTStore, + $finGAP, }; diff --git a/src/core/constants/stores/Calculation/filters.js b/src/core/constants/stores/Calculation/filters.js index ee492de..ab5ad8a 100644 --- a/src/core/constants/stores/Calculation/filters.js +++ b/src/core/constants/stores/Calculation/filters.js @@ -8,3 +8,7 @@ export const insuranceKaskoDefaultFilter = options => options.filter( x => x.evo_type_ins_policy && x.evo_type_ins_policy.includes(100000000), ); +export const insurancefinGAPDefaultFilter = options => + options.filter( + x => x.evo_type_ins_policy && x.evo_type_ins_policy.includes(100000002), + ); diff --git a/src/core/services/CalculationService/index.ts b/src/core/services/CalculationService/index.ts deleted file mode 100644 index 9732d57..0000000 --- a/src/core/services/CalculationService/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import axios from 'axios'; -import { CORE_PROXY_URL } from 'core/constants/urls'; -import { GetCalculationResponse, PreparedData } from './types/request'; - -export default class { - static calculate = (preparedData: PreparedData) => - axios - .post( - String.prototype.concat( - CORE_PROXY_URL, - '/api', - '/calculation', - '/calculate', - ), - preparedData, - ) - .then(res => res.data); -} diff --git a/src/core/services/CoreService/index.ts b/src/core/services/CoreService/index.ts new file mode 100644 index 0000000..393bc71 --- /dev/null +++ b/src/core/services/CoreService/index.ts @@ -0,0 +1,35 @@ +import axios from 'axios'; +import { CORE_PROXY_URL } from 'core/constants/urls'; +import { + GetCalculationResponse, + PreparedData, +} from './types/Calculation/request'; +import { RequestFinGAP, ResponseFinGAP } from './types/Cerebellum/finGAP'; + +export default class { + static calculate = (preparedData: PreparedData) => + axios + .post( + String.prototype.concat( + CORE_PROXY_URL, + '/api', + '/calculation', + '/calculate', + ), + preparedData, + ) + .then(res => res.data); + + static finGAP = (requestFinGAP: RequestFinGAP) => + axios + .post( + String.prototype.concat( + CORE_PROXY_URL, + '/api', + '/cerebellum', + '/finGAP', + ), + requestFinGAP, + ) + .then(res => res.data); +} diff --git a/src/core/services/CalculationService/types/columns.ts b/src/core/services/CoreService/types/Calculation/columns.ts similarity index 100% rename from src/core/services/CalculationService/types/columns.ts rename to src/core/services/CoreService/types/Calculation/columns.ts diff --git a/src/core/services/CalculationService/types/post.ts b/src/core/services/CoreService/types/Calculation/post.ts similarity index 100% rename from src/core/services/CalculationService/types/post.ts rename to src/core/services/CoreService/types/Calculation/post.ts diff --git a/src/core/services/CalculationService/types/prepared.ts b/src/core/services/CoreService/types/Calculation/prepared.ts similarity index 95% rename from src/core/services/CalculationService/types/prepared.ts rename to src/core/services/CoreService/types/Calculation/prepared.ts index a6ea2bb..7709447 100644 --- a/src/core/services/CalculationService/types/prepared.ts +++ b/src/core/services/CoreService/types/Calculation/prepared.ts @@ -98,6 +98,12 @@ export interface PreparedValues { subsidySum?: number; subsidyPaymentNumber?: number; fuelCardSum?: number; + + insuranceFinGAP?: number; + nmperFinGAP?: number; + insuranceFinGAPNmper?: number; + bonusFinGAP?: number; + directorBonusFinGAP?: number; } export interface PaymentRow { diff --git a/src/core/services/CalculationService/types/request.ts b/src/core/services/CoreService/types/Calculation/request.ts similarity index 76% rename from src/core/services/CalculationService/types/request.ts rename to src/core/services/CoreService/types/Calculation/request.ts index ff0ba6e..df9544e 100644 --- a/src/core/services/CalculationService/types/request.ts +++ b/src/core/services/CoreService/types/Calculation/request.ts @@ -1,9 +1,6 @@ -import { - PreparedPayments, - PreparedValues, -} from 'core/services/CalculationService/types/prepared'; import { Column, ColumnsNames } from './columns'; import { PostValues } from './post'; +import { PreparedPayments, PreparedValues } from './prepared'; export interface PreparedData { preparedPayments: PreparedPayments; diff --git a/src/core/services/CoreService/types/Cerebellum/finGAP.ts b/src/core/services/CoreService/types/Cerebellum/finGAP.ts new file mode 100644 index 0000000..ca07c2a --- /dev/null +++ b/src/core/services/CoreService/types/Cerebellum/finGAP.ts @@ -0,0 +1,21 @@ +export type PaymentRow = { + numberPayment?: number; + percentPayment: number; +}; + +export type RequestFinGAP = { + calcType: number; + payments: PaymentRow[]; + values: { + plPrice: number; + discount: number; + firstPayment: number; + leasingPeriod: number; + premiumPerc: number; + }; +}; + +export type ResponseFinGAP = { + sum: number; + premium: number; +}; diff --git a/src/core/services/CrmService/graphql/query/fragments/evo_addproduct_types_fields.graphql b/src/core/services/CrmService/graphql/query/fragments/evo_addproduct_types_fields.graphql index f74bfec..27fcbfb 100644 --- a/src/core/services/CrmService/graphql/query/fragments/evo_addproduct_types_fields.graphql +++ b/src/core/services/CrmService/graphql/query/fragments/evo_addproduct_types_fields.graphql @@ -12,4 +12,8 @@ fragment evo_addproduct_types_fields on evo_addproduct_type { evo_max_period evo_min_period evo_controls_program + evo_type_calc_cerebellum + evo_addproduct_types { + evo_addproduct_typeid + } } diff --git a/src/core/services/CrmService/graphql/query/quote/fragments/quoteFields.graphql b/src/core/services/CrmService/graphql/query/quote/fragments/quoteFields.graphql index 699b606..253d802 100644 --- a/src/core/services/CrmService/graphql/query/quote/fragments/quoteFields.graphql +++ b/src/core/services/CrmService/graphql/query/quote/fragments/quoteFields.graphql @@ -125,4 +125,12 @@ fragment quoteFields on quote { evo_pts_type evo_subsidyid evo_subsidy_summ + + evo_fingap_accountid + evo_fingap_payer + evo_fingap_price + evo_fingap_period + evo_product_risks { + evo_addproduct_typeid + } } diff --git a/src/core/services/CrmService/graphql/schema.graphql b/src/core/services/CrmService/graphql/schema.graphql index 4aba9cd..af0eac3 100644 --- a/src/core/services/CrmService/graphql/schema.graphql +++ b/src/core/services/CrmService/graphql/schema.graphql @@ -97,6 +97,8 @@ type Query { evo_orglegalforms(statecode: Int = 0): [evo_orglegalform] evo_paymentorders(evo_dds_1c: String, evo_name: String, evo_paydate_param: DateParamInput, evo_payment_number_1c: String, evo_paysum: Decimal, statecode: Int, statuscode: Int): [evo_paymentorder] evo_planpayments(evo_addproduct_typeid: Uuid, statecode: Int): [evo_planpayment] + evo_product_risk(evo_product_riskid: Uuid!): evo_product_risk + evo_product_risks(statecode: Int): [evo_product_risk] evo_rate(evo_rateid: Uuid!): evo_rate evo_rates(evo_datefrom_param: DateParamInput, evo_dateto_param: DateParamInput, statecode: Int): [evo_rate] @@ -185,6 +187,9 @@ type account { evo_employee_count: Int evo_fin_department_accountid: Uuid evo_fin_department_accountidData: account + evo_fuel_card_code: String + evo_fuel_card_login: String + evo_fuel_card_pass: String evo_fullname: String evo_group_sales_network: Uuid evo_id_elt: String @@ -226,6 +231,7 @@ type account { name: String ownerid: Uuid owneridsystemuserData: systemuser + owneridteamData: team owneridtype: Int ownerid_systemuser: Uuid ownerid_team: Uuid @@ -280,6 +286,7 @@ type contact { emailaddress3: String evo_consent_date: DateTime evo_fact_addressid: Uuid + evo_fact_addressidname: String evo_fullname: String evo_functiontype: [Int!] evo_inn: String @@ -307,10 +314,29 @@ type contact { toObjectString: String } +type evo_product_risk { + createdon: DateTime + evo_addproduct_typeid: Uuid + evo_addproduct_typeidData: evo_addproduct_type + evo_contractid: Uuid + evo_contractidData: evo_contract + evo_insurance_periodid: Uuid + evo_insurance_policyid: Uuid + evo_insurance_policyidData: evo_insurance_policy + evo_ins_price: Decimal + evo_ins_sum: Decimal + evo_name: String + evo_product_riskid: Uuid + evo_quoteid: Uuid + modifiedon: DateTime + toObjectString: String +} + type evo_addproduct_type { createdon: DateTime evo_accountid: Uuid evo_addproduct_typeid: Uuid + evo_addproduct_types: [evo_addproduct_type] evo_controls_program: [Int!] evo_cost_service_provider: Decimal evo_cost_service_provider_withoutnds: Decimal @@ -337,6 +363,7 @@ type evo_addproduct_type { evo_retro_bonus: Decimal evo_retro_bonus_withoutnds: Decimal evo_towtruck: Boolean + evo_type_calc_cerebellum: Int evo_visible_calc: Boolean evo_whom_register: Int evo_who_register: Int @@ -390,6 +417,7 @@ type evo_insurance_period { evo_age_drivers: Int evo_base_reward_factor: Decimal evo_base_reward_rub: Decimal + evo_close: Boolean evo_comment: String evo_contractid: Uuid evo_datefrom: DateTime @@ -414,6 +442,7 @@ type evo_insurance_period { evo_insurer_accountid: Uuid evo_insurer_accountidData: account evo_ins_risk: [Int!] + evo_invoice_date: DateTime evo_kasko_price: Decimal evo_leasingobjectid: Uuid evo_mobile_discount: Boolean @@ -462,6 +491,9 @@ type evo_addproduct { evo_addproduct_typeid: Uuid evo_addproduct_typeidData: evo_addproduct_type evo_deactivation_date: DateTime + evo_fuel_card_currency_limit_check: Boolean + evo_fuel_card_limit_check: Boolean + evo_fuel_card_limit_used: Decimal evo_leasingobjectid: Uuid evo_name: String evo_provider_accountid: Uuid @@ -469,6 +501,7 @@ type evo_addproduct { evo_request_instal_message: String evo_service_contactid: Uuid evo_telematics_number: String + evo_validity_from: DateTime modifiedon: DateTime toObjectString: String } @@ -509,6 +542,7 @@ type evo_statuscode { type evo_leasingobject { createdon: DateTime + evo_3_person_sale_date: DateTime evo_addequipment_list: String evo_base: String evo_brandid: Uuid @@ -521,6 +555,7 @@ type evo_leasingobject { evo_chassis: String evo_color: String evo_contractid: Uuid + evo_create_contract_purchase: Boolean evo_delivery_time: Int evo_driving_axle: String evo_ecological_class: Int @@ -563,6 +598,7 @@ type evo_leasingobject { evo_regionid: Uuid evo_registration: Int evo_registration_regionid: Uuid + evo_reg_date: DateTime evo_seats: Int evo_sts_number: String evo_townid: Uuid @@ -800,6 +836,7 @@ type quote { evo_delivery_time: Int evo_dgo_price: Decimal evo_director_bonus: Decimal + evo_director_fingap_bonus: Decimal evo_director_nsib_bonus: Decimal evo_discount_perc: Decimal evo_discount_rub: Decimal @@ -815,6 +852,11 @@ type quote { evo_equipmentid: Uuid evo_equity_capital: Decimal evo_exp_drivers: Int + evo_fingap_accountid: Uuid + evo_fingap_bonus_sum: Decimal + evo_fingap_payer: Int + evo_fingap_period: Int + evo_fingap_price: Decimal evo_fin_department_accountid: Uuid evo_fin_department_reward_conditionid: Uuid evo_fin_department_reward_summ: Decimal @@ -929,8 +971,10 @@ type quote { evo_price_without_nds_supplier_currency: Decimal evo_price_with_discount: Boolean evo_price_wthout_discount_nds_sup_currency: Decimal + evo_product_risks: [evo_product_risk] evo_programsolution: Int evo_pts_type: Int + evo_purchases_participation: Boolean evo_quotename: String evo_quotenumber: String evo_rate: Decimal @@ -1223,6 +1267,10 @@ type evo_request_payment { evo_payment_date: DateTime evo_payment_recipient: Uuid evo_payment_recipientData: account + evo_payment_recipient_account: Uuid + evo_payment_recipient_accountData: account + evo_payment_recipient_contact: Uuid + evo_payment_recipient_contactData: contact evo_payorder_date: DateTime evo_purpose_pay: String evo_region_director_systemuserid: Uuid @@ -1232,8 +1280,10 @@ type evo_request_payment { evo_storage: String evo_supplier_payment_type: Int evo_transactioncurrencyid: Uuid + evo_transfer_contact: Boolean evo_vat: Decimal modifiedon: DateTime + statecode: Int toObjectString: String } @@ -1250,12 +1300,14 @@ type evo_contract { evo_add_bonus_summ: Decimal evo_agent_accountid: Uuid evo_agent_reward: Decimal + evo_agent_reward_conditionid: Uuid evo_agent_reward_summ: Decimal evo_approvallogs: [evo_approvallog] evo_balance_holder: Int evo_bank_detailsid: Uuid evo_bank_detailsidData: evo_bank_details evo_base_calc_pay: Decimal + evo_bonus_pay_systemuserid: Uuid evo_broker_accountid: Uuid evo_broker_reward: Decimal evo_broker_reward_conditionid: Uuid @@ -1292,6 +1344,7 @@ type evo_contract { evo_debt_total: Decimal evo_delay_days_count: Int evo_director_bonus: Decimal + evo_director_fingap_bonus: Decimal evo_director_nsib_bonus: Decimal evo_discount_perc: Decimal evo_discount_supplier_currency: Decimal @@ -1304,11 +1357,14 @@ type evo_contract { evo_double_agent_reward_conditionid: Uuid evo_double_agent_reward_summ: Decimal evo_economic: Decimal + evo_economic_actual: Decimal evo_end_date_of_pledge_claim: DateTime evo_end_date_of_pledge_leasobject: DateTime evo_expinput_actual_date: DateTime evo_fedres_xml_date: DateTime evo_finegibdds: [evo_finegibdd] + evo_fingap_bonus_sum: Decimal + evo_fingap_period: Int evo_fin_department_accountid: Uuid evo_fin_department_reward: Decimal evo_fin_department_reward_conditionid: Uuid @@ -1320,6 +1376,7 @@ type evo_contract { evo_first_payment_rub: Decimal evo_first_payment_rub_without_subsidy: Decimal evo_forwarder_contactid: Uuid + evo_fuel_card_addproductid: Uuid evo_fuel_card_addproduct_typeid: Uuid evo_graphs(statecode: Int): [evo_graph] evo_graph_irr: Decimal @@ -1355,13 +1412,16 @@ type evo_contract { evo_nsib_bonus_summ: Decimal evo_ns_bonus_summ: Decimal evo_number_dkp: String + evo_ownership_date: DateTime evo_paymentorders(evo_name: String, statecode: Int): [evo_paymentorder] + evo_payment_redemption: Int evo_payment_redemption_sum: Decimal evo_payment_redemption_sum_without_nds: Decimal evo_period: Int evo_price_without_discount: Decimal evo_price_without_discount_supplier_currency: Decimal evo_price_wthout_discount_nds_sup_currency: Decimal + evo_purchases_participation: Boolean evo_quoteid: Uuid evo_rate: Decimal evo_rateid: Uuid @@ -1391,6 +1451,7 @@ type evo_contract { evo_supplier_pay_actual: Decimal evo_supplier_pay_actual_currency: Decimal evo_supplier_signer_contactid: Uuid + evo_tarifid: Uuid evo_telematics_addproduct_typeid: Uuid evo_telematics_addproduct_typeid_new: Uuid evo_telematics_equipment_addproductid: Uuid @@ -1405,6 +1466,7 @@ type evo_contract { evo_trade_in_cost_pre: Decimal evo_transactioncurrencyid: Uuid evo_transactioncurrencyidData: transactioncurrency + evo_uncritical_scan: Boolean evo_vehicle_tax_period: Decimal evo_vehicle_tax_year: Decimal modifiedon: DateTime @@ -1426,6 +1488,7 @@ type evo_external_system_request { evo_emailidData: email evo_external_system_requestid: Uuid evo_finegibddid: Uuid + evo_fuel_card_request_id: Decimal evo_insurance_periodid: Uuid evo_insurance_policyid: Uuid evo_integration_status: Int @@ -1508,6 +1571,7 @@ type evo_coefficient { type evo_planpayment { createdon: DateTime + evo_addcontractid: Uuid evo_addproduct_typeid: Uuid evo_cashflow_nsib: Decimal evo_cost_equipment: Decimal @@ -1535,6 +1599,7 @@ type evo_planpayment { modifiedon: DateTime ownerid: Uuid statecode: Int + statuscode: Int toObjectString: String } @@ -1565,6 +1630,7 @@ type evo_tarif { evo_models(statecode: Int): [evo_model] evo_model_exceptions(statecode: Int): [evo_model] evo_name: String + evo_pay_supplier_without_addcontract: Boolean evo_rates(statecode: Int): [evo_rate] evo_tarifid: Uuid evo_transactioncurrencyid: Uuid @@ -1675,6 +1741,7 @@ type evo_address { type systemuser { businessunitid: Uuid + businessunitidData: businessunit createdon: DateTime domainname: String evo_baseproducts(statecode: Int): [evo_baseproduct] @@ -1687,6 +1754,7 @@ type systemuser { evo_loader: String evo_role_treasury: Boolean evo_sfm: Boolean + evo_underwriting_purchases_rules: Boolean evo_wordmergerui_access: Boolean firstname: String fullname: String @@ -1800,16 +1868,19 @@ type evo_addcontract { evo_acquisition_costs: Decimal evo_activdate_1c: DateTime evo_activdate_crm: DateTime + evo_activdate_insurance: DateTime evo_addcontractid: Uuid evo_add_bonus_summ: Decimal evo_agent_reward_summ: Decimal evo_age_drivers: Int evo_age_drivers_new: Int + evo_approv_business_analyst: Boolean evo_balance: Int evo_balance_change: Boolean evo_balance_new: Int evo_bank_detailsid: Uuid evo_bank_detailsid_new: Uuid + evo_ban_edit_date: DateTime evo_base: String evo_base_bonus: Decimal evo_base_calc_pay: Decimal @@ -1875,6 +1946,7 @@ type evo_addcontract { evo_driving_axle_new: String evo_early_change_discount: Boolean evo_early_discount_perc: Decimal + evo_early_partly_type: Int evo_early_redemption_change: Boolean evo_ecological_class: Int evo_ecological_class_new: Int @@ -2035,6 +2107,7 @@ type evo_addcontract { evo_supplier_pay_actual: Decimal evo_supplier_pay_actual_currency: Decimal evo_supplier_signer_contactid_new: Uuid + evo_suspend_contract_change: Boolean evo_telematics_addproduct_typeid: Uuid evo_telematics_addproduct_typeid_new: Uuid evo_townid: Uuid @@ -2129,6 +2202,16 @@ type MutationBy { updateEntity(data: EntityDataInput): Boolean! } +type team { + createdon: DateTime + evo_baseproducts(statecode: Int): [evo_baseproduct] + evo_identity_documents: [evo_identity_document] + modifiedon: DateTime + name: String + teamid: Uuid + toObjectString: String +} + """The `DateTime` scalar represents an ISO-8601 compliant date time type.""" scalar DateTime @@ -2168,8 +2251,10 @@ type evo_insurance_policy { evo_polis_number: String evo_polis_type: Int evo_pre_polis_number: String + evo_quoteid: Uuid evo_statuscodeid: Uuid modifiedon: DateTime + ownerid: Uuid statecode: Int statuscode: Int toObjectString: String @@ -2177,11 +2262,13 @@ type evo_insurance_policy { type evo_addproductnumber { createdon: DateTime + evo_accountid: Uuid evo_addproductnumberid: Uuid evo_insurance_type: Int evo_name: String evo_number_status: Int modifiedon: DateTime + ownerid: Uuid toObjectString: String } diff --git a/src/core/services/CrmService/types/entities.ts b/src/core/services/CrmService/types/entities.ts index 5057482..ac6e4bb 100644 --- a/src/core/services/CrmService/types/entities.ts +++ b/src/core/services/CrmService/types/entities.ts @@ -166,6 +166,14 @@ export interface IQuote extends BaseEntity { evo_fin_department_accountid?: string; evo_broker_reward_total?: number; evo_broker_reward_conditionid?: string; + + evo_fingap_accountid?: string; + evo_fingap_payer?: number; + evo_fingap_price?: number; + evo_fingap_period?: number; + evo_product_risks?: { + evo_addproduct_typeid: string; + }[]; } export interface IEvoGraph extends BaseEntity { @@ -368,6 +376,8 @@ export interface IEvoAddproductType extends BaseEntity { evo_description?: string; evo_whom_register?: number; evo_gibdd_region?: boolean; + evo_type_calc_cerebellum?: number; + evo_addproduct_types?: IEvoAddproductType[]; } export interface IEvoTarif extends BaseEntity { diff --git a/src/core/types/Calculation/Store/index.ts b/src/core/types/Calculation/Store/index.ts index a1c2d2f..6f206ad 100644 --- a/src/core/types/Calculation/Store/index.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -10,6 +10,7 @@ import { import { TCalculationProcess } from 'client/stores/CalculationStore/subStores/calculationProcess'; import { TCalculationUrls } from 'client/stores/CalculationStore/subStores/calculationUrls'; import { TELTStore } from 'client/stores/CalculationStore/subStores/eltStore'; +import { TFinGAP } from 'client/stores/CalculationStore/subStores/finGAP'; import { IBaseOption, TOptionizedEntity, @@ -136,6 +137,7 @@ interface ICalculationStores { calculationProcess: TCalculationProcess; calculationUrls: TCalculationUrls; ELTStore: TELTStore; + $finGAP: TFinGAP; }; } diff --git a/src/core/types/Calculation/Store/values.ts b/src/core/types/Calculation/Store/values.ts index 3f26b65..6854a65 100644 --- a/src/core/types/Calculation/Store/values.ts +++ b/src/core/types/Calculation/Store/values.ts @@ -88,10 +88,10 @@ export type ValuesNames = | 'quoteName' | 'quoteContactGender' | 'quoteRedemptionGraph' + | 'showFinGAP' | 'tarif' | 'creditRate' | 'rate' - | 'userSession' | 'requirementTelematic' | 'maxPriceChange' | 'importerRewardPerc' @@ -133,12 +133,15 @@ export type ValuesNames = | 'resultAB_UL' | 'resultBonusMPL' | 'resultDopMPLLeasing' - | 'resultBonusDopProd'; + | 'resultBonusDopProd' + | 'resultBonusSafeFinance'; export type ComputedValuesNames = | 'leaseObjectRiskName' | 'insKaskoPriceLeasePeriod' | 'irrInfo' - | 'registrationDescription'; + | 'registrationDescription' + | 'plPriceRub' + | 'discountRub'; export type AllValues = ValuesNames | ComputedValuesNames;