diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index b86eaa4..06b403b 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -372,7 +372,7 @@ const sections: ISections[] = [ }, // TODO formatter + rub, parser { - title: 'Скидка от поставщика, рубли', + title: 'Скидка от поставщика', Component: InputNumber, props: { min: '0', @@ -393,36 +393,37 @@ const sections: ISections[] = [ name: 'tbxSupplierDiscountPerc', valueName: 'supplierDiscountPerc', }, - }, // TODO Input x Addon - { - title: 'Валюта доп.оборудования', - Component: Select, - props: { - name: 'selectAddEquipmentCurrency', - valueName: 'addEquipmentCurrency', - }, - }, - { - title: 'Стоимость доп.оборудования', - Component: InputNumber, - props: { - min: '0', - max: '1000000000', - step: '10000.00', - name: 'tbxAddEquipmentPrice', - valueName: 'addEquipmentPrice', - }, - }, - { - title: 'Плательщик доп.оборудования', - Component: Radio, - props: { - name: 'radioAddEquipmentPayer', - valueName: 'addEquipmentPayer', - withSearch: false, - style: 'button', - }, }, + // TODO Input x Addon + // { + // title: 'Валюта доп.оборудования', + // Component: Select, + // props: { + // name: 'selectAddEquipmentCurrency', + // valueName: 'addEquipmentCurrency', + // }, + // }, + // { + // title: 'Стоимость доп.оборудования', + // Component: InputNumber, + // props: { + // min: '0', + // max: '1000000000', + // step: '10000.00', + // name: 'tbxAddEquipmentPrice', + // valueName: 'addEquipmentPrice', + // }, + // }, + // { + // title: 'Плательщик доп.оборудования', + // Component: Radio, + // props: { + // name: 'radioAddEquipmentPayer', + // valueName: 'addEquipmentPayer', + // withSearch: false, + // style: 'button', + // }, + // }, ], }, { diff --git a/src/client/Containers/Calculation/index.jsx b/src/client/Containers/Calculation/index.jsx index 680c2f0..42d1754 100644 --- a/src/client/Containers/Calculation/index.jsx +++ b/src/client/Containers/Calculation/index.jsx @@ -5,23 +5,36 @@ import { useStores } from 'client/hooks/useStores'; import CalculationService from 'client/services/CalculationService'; import { Box, Flex } from 'client/UIKit/grid'; import initialOptions from 'core/Data/initialOptions'; -import staticEntitiesList from 'core/Data/staticEntitiesList'; import React, { useEffect, useState } from 'react'; import Result from 'client/Components/Result'; import Modal from 'client/Elements/Modal'; import Results from './Results'; import Sections from './Sections'; +import { gql } from '@apollo/client'; const Calculation = () => { const [status, setStatus] = useState(LoadingStatus.loading); const { calculationStore } = useStores(); + //TODO: move to external file useEffect(() => { Promise.all([ CalculationService.getEntities({ queries: initialOptions, }), - CalculationService.getEntities({ - queries: staticEntitiesList, + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int) { + evo_impairment_group: evo_impairment_groups(statecode: $statecode) { + evo_impairment_groupid + evo_name + } + evo_currencychange: evo_currencychanges(statecode: $statecode) { + evo_currencychange + evo_ref_transactioncurrency + } + } + `, + variables: { statecode: 0 }, }), CalculationService.getEntities({ queries: [ @@ -46,6 +59,16 @@ const Calculation = () => { calculationStore.setTableColumns('tableInsurance')({ options: { ...insuranceCompanies }, }); + + //TODO: move to external file + var supplierCurrency = calculationStore.options.selectSupplierCurrency.find( + x => x.isocurrencycode === 'RUB', + ); + calculationStore.setValue( + 'supplierCurrency', + supplierCurrency.transactioncurrencyid, + ); + setStatus(LoadingStatus.ready); }, ) diff --git a/src/client/services/CalculationService.ts b/src/client/services/CalculationService.ts index 8f70e97..b8211fc 100644 --- a/src/client/services/CalculationService.ts +++ b/src/client/services/CalculationService.ts @@ -92,10 +92,7 @@ class CalculationService { //@ts-ignore resEntities[ //@ts-ignore - !CRMEntityAliases.includes(targetName) && - isPlural(targetName) - ? singular(targetName) - : targetName + isPlural(targetName) ? singular(targetName) : targetName ] = entityOption; } } @@ -173,9 +170,7 @@ class CalculationService { //@ts-ignore resEntities[ //@ts-ignore - !CRMEntityAliases.includes(targetName) && isPlural(targetName) - ? singular(targetName) - : targetName + isPlural(targetName) ? singular(targetName) : targetName ] = entityOption; } } diff --git a/src/client/stores/CalculationStore/Effects/lib/tools.js b/src/client/stores/CalculationStore/Effects/lib/tools.js index 68a2372..ba13171 100644 --- a/src/client/stores/CalculationStore/Effects/lib/tools.js +++ b/src/client/stores/CalculationStore/Effects/lib/tools.js @@ -14,10 +14,9 @@ export function calcPrice( export const calculatePerc = calculationStore => ( supplierCurrencyId, leaseObjectPrice, - discountRub, - discountPercFieldName, + rubSum, + percFieldName, ) => { - // TODO: check evo_currecychange const supplierCurrency = calculationStore .getOptions('selectSupplierCurrency') .find(x => x.transactioncurrencyid === supplierCurrencyId); @@ -31,17 +30,16 @@ export const calculatePerc = calculationStore => ( parseFloat(leaseObjectPrice), evo_currencychangeValue, ); - let perc = (discountRub / price) * 100; - calculationStore.setValue(discountPercFieldName, perc); + let perc = (rubSum / price) * 100; + calculationStore.setValue(percFieldName, perc); }; export const calculateRub = calculationStore => ( supplierCurrencyId, leaseObjectPrice, - discountPerc, - discountRubFieldName, + perc, + rubFieldName, ) => { - // TODO: check evo_currecychange const supplierCurrency = calculationStore .getOptions('selectSupplierCurrency') .find(x => x.transactioncurrencyid === supplierCurrencyId); @@ -55,6 +53,6 @@ export const calculateRub = calculationStore => ( parseFloat(leaseObjectPrice), evo_currencychangeValue, ); - let rub = (discountPerc * price) / 100; - calculationStore.setValue(discountRubFieldName, rub); + let rub = (perc * price) / 100; + calculationStore.setValue(rubFieldName, rub); }; diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 97089e7..4802350 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -57,6 +57,10 @@ const reactionEffects: IReactionEffect[] = [ quoteid name quotenumber + evo_recalc_limit + evo_statuscode: evo_statuscodeidData { + evo_id + } } } `, @@ -263,7 +267,6 @@ const reactionEffects: IReactionEffect[] = [ opportunity.evo_client_riskid, ); } else { - //TODO: проверить if (opportunity.parentaccountid) CalculationService.crmgqlquery({ query: gql` @@ -347,10 +350,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setStatus('selectAgent', Status.Default); calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); + calculationStore.setValue('finDepartment', null); calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); + calculationStore.setValue('broker', null); break; case 100000001: @@ -360,45 +363,45 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setStatus('selectFinDepartment', Status.Default); calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); + calculationStore.setValue('broker', null); break; case 100000002: calculationStore.setStatus('selectSupplier', Status.Disabled); - calculationStore.setValue('supplier', undefined); + calculationStore.setValue('supplier', null); calculationStore.setStatus('selectAgent', Status.Default); calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); + calculationStore.setValue('finDepartment', null); calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); + calculationStore.setValue('broker', null); break; case 100000003: calculationStore.setStatus('selectSupplier', Status.Disabled); - calculationStore.setValue('supplier', undefined); + calculationStore.setValue('supplier', null); calculationStore.setStatus('selectAgent', Status.Default); - calculationStore.setValue('agent', undefined); + calculationStore.setValue('agent', null); calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); + calculationStore.setValue('finDepartment', null); calculationStore.setStatus('selectBroker', Status.Default); break; case 100000004: default: calculationStore.setStatus('selectSupplier', Status.Disabled); - calculationStore.setValue('supplier', undefined); + calculationStore.setValue('supplier', null); calculationStore.setStatus('selectAgent', Status.Disabled); - calculationStore.setValue('agent', undefined); + calculationStore.setValue('agent', null); calculationStore.setStatus('selectFinDepartment', Status.Disabled); - calculationStore.setValue('finDepartment', undefined); + calculationStore.setValue('finDepartment', null); calculationStore.setStatus('selectBroker', Status.Disabled); - calculationStore.setValue('broker', undefined); + calculationStore.setValue('broker', null); break; } }, @@ -1075,6 +1078,9 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setStatus('tbxLeaseObjectCount', Status.Default); } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1089,6 +1095,9 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setStatus('btnDriversApplication', Status.Default); } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1103,6 +1112,9 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setStatus('btnFranschise', Status.Default); } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1121,6 +1133,9 @@ const reactionEffects: IReactionEffect[] = [ } } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1233,6 +1248,9 @@ const reactionEffects: IReactionEffect[] = [ } } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1250,6 +1268,9 @@ const reactionEffects: IReactionEffect[] = [ } } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1273,6 +1294,9 @@ const reactionEffects: IReactionEffect[] = [ } } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -1727,1085 +1751,1112 @@ const reactionEffects: IReactionEffect[] = [ options: { fireImmediately: true }, }), - // calculationStore => ({ - // expression: () => { - // const { model } = calculationStore.values; - // return model; - // }, - // effect: modelId => { - // if (modelId) { - // const model = calculationStore.options.selectModel?.find( - // x => x.evo_modelid === modelId, - // ); - // if (model) { - // CalculationService.getEntityOptions({ - // query: { - // entityName: 'evo_equipment', - // where: { - // statecode: 0, - // evo_modelid: modelId, - // }, - // }, - // }).then(({ entityOptions: equipments }) => { - // if (equipments && equipments.length > 0) { - // calculationStore.setStatus('selectConfiguration', Status.Default); - // calculationStore.setOptions('selectConfiguration', equipments); - // calculationStore.setValue('configuration', null); - // return; - // } - // }); - // } - // } - // calculationStore.setStatus('selectConfiguration', Status.Disabled); - // calculationStore.setOptions('selectConfiguration', []); - // calculationStore.setValue('configuration', null); - // }, - // }), + calculationStore => ({ + expression: () => { + const { model } = calculationStore.values; + return model; + }, + effect: modelId => { + calculationStore.setStatus('selectConfiguration', Status.Disabled); + calculationStore.setOptions('selectConfiguration', []); + calculationStore.setValue('configuration', null); - // calculationStore => ({ - // expression: () => { - // const { configuration } = calculationStore.values; - // const { selectConfiguration } = calculationStore.options; - // return [configuration, selectConfiguration]; - // }, - // effect: ([configurationId, selectConfigurationOptions]) => { - // if (selectConfigurationOptions && selectConfigurationOptions.length) { - // if (!configurationId) { - // calculationStore.setValidation('selectConfiguration', false); - // return; - // } - // } - // calculationStore.setValidation('selectConfiguration', true); - // }, - // }), + if (modelId) { + const model = calculationStore.options.selectModel?.find( + x => x.evo_modelid === modelId, + ); + if (model) { + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $evo_modelid: Uuid) { + evo_equipment: evo_equipments( + statecode: $statecode + evo_modelid: $evo_modelid + ) { + evo_equipmentid + evo_name + evo_impairment_groupid + evo_leasingobject_risk + } + } + `, + toOptions: ['evo_equipment'], + variables: { + statecode: 0, + evo_modelid: modelId, + }, + }).then(({ entities }) => { + if ( + entities.evo_equipment && + Array.isArray(entities.evo_equipment) && + entities.evo_equipment.length > 0 + ) { + calculationStore.setStatus('selectConfiguration', Status.Default); + calculationStore.setOptions( + 'selectConfiguration', + entities.evo_equipment, + ); + } + }); + } + } + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { model, configuration } = calculationStore.values; - // return [model, configuration]; - // }, - // effect: ([modelId, configurationId]) => { - // if (configurationId) { - // const configuration = calculationStore.options.selectConfiguration?.find( - // x => x.evo_equipmentid === configurationId, - // ); - // if (configuration) { - // if (configuration.evo_impairment_groupid) { - // const evo_impairment_groups = calculationStore.getStaticData( - // 'evo_impairment_group', - // ); - // const evo_impairment_group = evo_impairment_groups.find( - // x => - // x.evo_impairment_groupid === - // configuration.evo_impairment_groupid, - // ); - // calculationStore.setValue( - // 'depreciationGroup', - // evo_impairment_group ? evo_impairment_group.evo_name : '', - // ); - // return; - // } - // } - // } - // const model = calculationStore.options.selectModel?.find( - // x => x.evo_modelid === modelId, - // ); - // if (model) - // if (model.evo_impairment_groupid) { - // const evo_impairment_groups = calculationStore.getStaticData( - // 'evo_impairment_group', - // ); - // const evo_impairment_group = evo_impairment_groups.find( - // x => x.evo_impairment_groupid === model.evo_impairment_groupid, - // ); - // calculationStore.setValue( - // 'depreciationGroup', - // evo_impairment_group ? evo_impairment_group.evo_name : '', - // ); - // return; - // } - // calculationStore.setValue('depreciationGroup', null); - // }, - // }), + calculationStore => ({ + expression: () => { + const { configuration } = calculationStore.values; + const { selectConfiguration } = calculationStore.options; + return [configuration, selectConfiguration]; + }, + effect: ([configurationId, selectConfigurationOptions]) => { + if (selectConfigurationOptions && selectConfigurationOptions.length) { + if (!configurationId) { + calculationStore.setValidation('selectConfiguration', false); + return; + } + } + calculationStore.setValidation('selectConfiguration', true); + }, + }), - // calculationStore => ({ - // expression: () => { - // const { - // supplierCurrency, - // leaseObjectPrice, - // supplierDiscountRub, - // } = calculationStore.values; - // return [supplierCurrency, leaseObjectPrice, supplierDiscountRub]; - // }, - // effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountRub]) => { - // if (supplierDiscountRub === undefined) { - // return; - // } - // calculatePerc(calculationStore)( - // supplierCurrencyId, - // leaseObjectPrice, - // supplierDiscountRub, - // 'supplierDiscountPerc', - // ); - // }, - // }), - // calculationStore => ({ - // expression: () => { - // const { - // supplierCurrency, - // leaseObjectPrice, - // supplierDiscountPerc, - // } = calculationStore.values; - // return [supplierCurrency, leaseObjectPrice, supplierDiscountPerc]; - // }, - // effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountPerc]) => { - // if (supplierDiscountPerc === undefined) { - // return; - // } - // calculateRub(calculationStore)( - // supplierCurrencyId, - // leaseObjectPrice, - // supplierDiscountPerc, - // 'supplierDiscountRub', - // ); - // }, - // }), + calculationStore => ({ + expression: () => { + const { model, configuration } = calculationStore.values; + return [model, configuration]; + }, + effect: ([modelId, configurationId]) => { + if (configurationId) { + const configuration = calculationStore.options.selectConfiguration?.find( + x => x.evo_equipmentid === configurationId, + ); + if (configuration) { + if (configuration.evo_impairment_groupid) { + const evo_impairment_groups = calculationStore.getStaticData( + 'evo_impairment_group', + ); + const evo_impairment_group = evo_impairment_groups.find( + x => + x.evo_impairment_groupid === + configuration.evo_impairment_groupid, + ); + calculationStore.setValue( + 'depreciationGroup', + evo_impairment_group ? evo_impairment_group.evo_name : '', + ); + return; + } + } + } + const model = calculationStore.options.selectModel?.find( + x => x.evo_modelid === modelId, + ); + if (model) + if (model.evo_impairment_groupid) { + const evo_impairment_groups = calculationStore.getStaticData( + 'evo_impairment_group', + ); + const evo_impairment_group = evo_impairment_groups.find( + x => x.evo_impairment_groupid === model.evo_impairment_groupid, + ); + calculationStore.setValue( + 'depreciationGroup', + evo_impairment_group ? evo_impairment_group.evo_name : '', + ); + return; + } + calculationStore.setValue('depreciationGroup', null); + }, + }), - // calculationStore => ({ - // expression: () => { - // const { firstPaymentRub } = calculationStore.values; - // return firstPaymentRub; - // }, - // effect: firstPaymentRub => { - // if (firstPaymentRub === undefined) { - // return; - // } - // const { supplierCurrency, leaseObjectPrice } = calculationStore.values; - // calculatePerc(calculationStore)( - // supplierCurrency, - // leaseObjectPrice, - // firstPaymentRub, - // 'firstPaymentPerc', - // ); - // }, - // }), - // calculationStore => ({ - // expression: () => { - // const { - // supplierCurrency, - // leaseObjectPrice, - // firstPaymentPerc, - // } = calculationStore.values; - // return [supplierCurrency, leaseObjectPrice, firstPaymentPerc]; - // }, - // effect: ([supplierCurrencyId, leaseObjectPrice, firstPaymentPerc]) => { - // if (firstPaymentPerc === undefined) { - // return; - // } - // calculateRub(calculationStore)( - // supplierCurrencyId, - // leaseObjectPrice, - // firstPaymentPerc, - // 'firstPaymentRub', - // ); - // }, - // }), + calculationStore => ({ + expression: () => { + const { leaseObjectPrice, supplierDiscountRub } = calculationStore.values; + return [leaseObjectPrice, supplierDiscountRub]; + }, + effect: ([leaseObjectPrice, supplierDiscountRub]) => { + if (supplierDiscountRub === undefined) { + return; + } - // calculationStore => ({ - // expression: () => { - // const { - // supplierCurrency, - // leaseObjectPrice, - // comissionPerc, - // } = calculationStore.values; - // return [supplierCurrency, leaseObjectPrice, comissionPerc]; - // }, - // effect: ([supplierCurrencyId, leaseObjectPrice, comissionPerc]) => { - // if (comissionPerc === undefined) { - // return; - // } - // calculateRub(calculationStore)( - // supplierCurrencyId, - // leaseObjectPrice, - // comissionPerc, - // 'comissionRub', - // ); - // }, - // }), - // calculationStore => ({ - // expression: () => { - // const { comissionRub } = calculationStore.values; - // return comissionRub; - // }, - // effect: comissionRub => { - // if (comissionRub === undefined) { - // return; - // } - // const { supplierCurrency, leaseObjectPrice } = calculationStore.values; - // calculatePerc(calculationStore)( - // supplierCurrency, - // leaseObjectPrice, - // comissionRub, - // 'comissionPerc', - // ); - // }, - // }), + calculationStore.setValue( + 'supplierDiscountPerc', + (supplierDiscountRub / leaseObjectPrice) * 100, + ); + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { - // supplierCurrency, - // leaseObjectPrice, - // lastPaymentPerc, - // lastPaymentRule, - // } = calculationStore.values; - // return [ - // supplierCurrency, - // leaseObjectPrice, - // lastPaymentPerc, - // lastPaymentRule, - // ]; - // }, - // effect: ([ - // supplierCurrencyId, - // leaseObjectPrice, - // lastPaymentPerc, - // lastPaymentRule, - // ]) => { - // if (lastPaymentPerc === undefined || lastPaymentRule !== 100000001) { - // return; - // } - // calculateRub(calculationStore)( - // supplierCurrencyId, - // leaseObjectPrice, - // lastPaymentPerc, - // 'lastPaymentRub', - // ); - // }, - // }), - // calculationStore => ({ - // expression: () => { - // const { - // supplierCurrency, - // leaseObjectPrice, - // lastPaymentRub, - // lastPaymentRule, - // } = calculationStore.values; - // return [ - // supplierCurrency, - // leaseObjectPrice, - // lastPaymentRub, - // lastPaymentRule, - // ]; - // }, - // effect: ([ - // supplierCurrencyId, - // leaseObjectPrice, - // lastPaymentRub, - // lastPaymentRule, - // ]) => { - // if (lastPaymentRub === undefined || lastPaymentRule !== 100000000) { - // return; - // } - // calculatePerc(calculationStore)( - // supplierCurrencyId, - // leaseObjectPrice, - // lastPaymentRub, - // 'lastPaymentPerc', - // ); - // }, - // }), + calculationStore => ({ + expression: () => { + const { + leaseObjectPrice, + supplierDiscountPerc, + } = calculationStore.values; + return [leaseObjectPrice, supplierDiscountPerc]; + }, + effect: ([leaseObjectPrice, supplierDiscountPerc]) => { + if (supplierDiscountPerc === undefined) { + return; + } - // calculationStore => ({ - // expression: () => { - // const { - // recalcWithRevision, - // supplierCurrency, - // supplierDiscountRub, - // supplierDiscountPerc, - // leaseObjectPrice, - // } = calculationStore.values; - // return [ - // recalcWithRevision, - // supplierCurrency, - // supplierDiscountRub, - // supplierDiscountPerc, - // leaseObjectPrice, - // ]; - // }, - // effect: ([ - // recalcWithRevision, - // supplierCurrencyId, - // supplierDiscountRub, - // supplierDiscountPerc, - // leaseObjectPrice, - // ]) => { - // if (recalcWithRevision === true) { - // return; - // } - // const supplierCurrency = calculationStore - // .getOptions('selectSupplierCurrency') - // .find(x => x.transactioncurrencyid === supplierCurrencyId); - // const evo_currencychange = calculationStore - // .getStaticData('evo_currencychange') - // ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); - // const evo_currencychangeValue = - // (evo_currencychange && evo_currencychange.evo_currencychange) || 0; - // let price = calcPrice( - // supplierCurrency?.isocurrencycode, - // leaseObjectPrice, - // evo_currencychangeValue, - // ); + calculationStore.setValue( + 'supplierDiscountRub', + (supplierDiscountPerc * leaseObjectPrice) / 100, + ); + }, + options: { + fireImmediately: true, + }, + }), - // let maxPriceChange = - // price - supplierDiscountRub < 800000 - // ? price - supplierDiscountRub + 50000 - // : (price - supplierDiscountRub) * 1.05; + calculationStore => ({ + expression: () => { + const { firstPaymentRub } = calculationStore.values; + return firstPaymentRub; + }, + effect: firstPaymentRub => { + if (firstPaymentRub === undefined) { + return; + } + const { supplierCurrency, leaseObjectPrice } = calculationStore.values; + calculatePerc(calculationStore)( + supplierCurrency, + leaseObjectPrice, + firstPaymentRub, + 'firstPaymentPerc', + ); + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore.setValue('maxPriceChange', maxPriceChange); - // }, - // }), + calculationStore => ({ + expression: () => { + const { + supplierCurrency, + leaseObjectPrice, + firstPaymentPerc, + } = calculationStore.values; + return [supplierCurrency, leaseObjectPrice, firstPaymentPerc]; + }, + effect: ([supplierCurrencyId, leaseObjectPrice, firstPaymentPerc]) => { + if (firstPaymentPerc === undefined) { + return; + } + calculateRub(calculationStore)( + supplierCurrencyId, + leaseObjectPrice, + firstPaymentPerc, + 'firstPaymentRub', + ); + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { recalcWithRevision } = calculationStore.values; - // return recalcWithRevision; - // }, - // effect: recalcWithRevision => { - // if (recalcWithRevision === true) { - // calculationStore.setStatus('selectLead', Status.Disabled); - // calculationStore.setStatus('selectOpportunity', Status.Disabled); - // calculationStore.setStatus('selectQuote', Status.Disabled); - // } else { - // calculationStore.setStatus('selectLead', Status.Default); - // calculationStore.setStatus('selectOpportunity', Status.Default); - // calculationStore.setStatus('selectQuote', Status.Default); - // } - // }, - // }), + calculationStore => ({ + expression: () => { + const { + supplierCurrency, + leaseObjectPrice, + comissionPerc, + } = calculationStore.values; + return [supplierCurrency, leaseObjectPrice, comissionPerc]; + }, + effect: ([supplierCurrencyId, leaseObjectPrice, comissionPerc]) => { + if (comissionPerc === undefined) { + return; + } + calculateRub(calculationStore)( + supplierCurrencyId, + leaseObjectPrice, + comissionPerc, + 'comissionRub', + ); + }, + options: { + fireImmediately: true, + }, + }), + calculationStore => ({ + expression: () => { + const { comissionRub } = calculationStore.values; + return comissionRub; + }, + effect: comissionRub => { + if (comissionRub === undefined) { + return; + } + const { supplierCurrency, leaseObjectPrice } = calculationStore.values; + calculatePerc(calculationStore)( + supplierCurrency, + leaseObjectPrice, + comissionRub, + 'comissionPerc', + ); + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { - // supplierDiscountRub, - // leaseObjectPrice, - // supplierCurrency, - // } = calculationStore.values; - // return [supplierDiscountRub, leaseObjectPrice, supplierCurrency]; - // }, - // effect: ([supplierDiscountRub, leaseObjectPrice, supplierCurrencyId]) => { - // const { recalcWithRevision, maxPriceChange } = calculationStore.values; - // if (recalcWithRevision === false) { - // return; - // } + calculationStore => ({ + expression: () => { + const { + supplierCurrency, + leaseObjectPrice, + lastPaymentPerc, + lastPaymentRule, + } = calculationStore.values; + return [ + supplierCurrency, + leaseObjectPrice, + lastPaymentPerc, + lastPaymentRule, + ]; + }, + effect: ([ + supplierCurrencyId, + leaseObjectPrice, + lastPaymentPerc, + lastPaymentRule, + ]) => { + if (lastPaymentPerc === undefined || lastPaymentRule !== 100000001) { + return; + } + calculateRub(calculationStore)( + supplierCurrencyId, + leaseObjectPrice, + lastPaymentPerc, + 'lastPaymentRub', + ); + }, + options: { + fireImmediately: true, + }, + }), + calculationStore => ({ + expression: () => { + const { + supplierCurrency, + leaseObjectPrice, + lastPaymentRub, + lastPaymentRule, + } = calculationStore.values; + return [ + supplierCurrency, + leaseObjectPrice, + lastPaymentRub, + lastPaymentRule, + ]; + }, + effect: ([ + supplierCurrencyId, + leaseObjectPrice, + lastPaymentRub, + lastPaymentRule, + ]) => { + if (lastPaymentRub === undefined || lastPaymentRule !== 100000000) { + return; + } + calculatePerc(calculationStore)( + supplierCurrencyId, + leaseObjectPrice, + lastPaymentRub, + 'lastPaymentPerc', + ); + }, + options: { + fireImmediately: true, + }, + }), - // const supplierCurrency = calculationStore - // .getOptions('selectSupplierCurrency') - // .find(x => x.transactioncurrencyid === supplierCurrencyId); - // const evo_currencychange = calculationStore - // .getStaticData('evo_currencychange') - // ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); - // const evo_currencychangeValue = - // (evo_currencychange && evo_currencychange.evo_currencychange) || 0; - // let price = calcPrice( - // supplierCurrency?.isocurrencycode, - // leaseObjectPrice, - // evo_currencychangeValue, - // ); + calculationStore => ({ + expression: () => { + const { + recalcWithRevision, + supplierCurrency, + supplierDiscountRub, + supplierDiscountPerc, + leaseObjectPrice, + } = calculationStore.values; + return [ + recalcWithRevision, + supplierCurrency, + supplierDiscountRub, + supplierDiscountPerc, + leaseObjectPrice, + ]; + }, + effect: ([ + recalcWithRevision, + supplierCurrencyId, + supplierDiscountRub, + supplierDiscountPerc, + leaseObjectPrice, + ]) => { + if (recalcWithRevision === true) { + return; + } + const supplierCurrency = calculationStore + .getOptions('selectSupplierCurrency') + .find(x => x.transactioncurrencyid === supplierCurrencyId); + const evo_currencychange = calculationStore + .getStaticData('evo_currencychange') + ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + const evo_currencychangeValue = + (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + let price = calcPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice, + evo_currencychangeValue, + ); - // if (price - supplierDiscountRub > maxPriceChange) { - // calculationStore.setValidation('tbxLeaseObjectPrice', false); - // openNotification({ - // type: 'error', - // title: 'Ошибка', - // description: - // 'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра.' + - // 'Уменьшите стоимость предмета лизинга', - // })(); - // } else { - // calculationStore.setValidation('tbxLeaseObjectPrice', true); - // } - // }, - // }), + let maxPriceChange = + price - supplierDiscountRub < 800000 + ? price - supplierDiscountRub + 50000 + : (price - supplierDiscountRub) * 1.05; - // calculationStore => ({ - // expression: () => { - // const { leaseObjectUsed } = calculationStore.values; - // return leaseObjectUsed; - // }, - // effect: leaseObjectUsed => { - // if (leaseObjectUsed === true) { - // calculationStore.setValue('deliveryTime', 100000000); - // calculationStore.setStatus('radioDeliveryTime', Status.Disabled); - // } else { - // calculationStore.setStatus('radioDeliveryTime', Status.Default); - // } - // }, - // }), + calculationStore.setValue('maxPriceChange', maxPriceChange); + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { leaseObjectCategory } = calculationStore.values; - // return leaseObjectCategory; - // }, - // effect: leaseObjectCategory => { - // if ( - // leaseObjectCategory === 100000001 || - // leaseObjectCategory === 100000001 - // ) { - // calculationStore.setValue('withTrailer', null); - // calculationStore.setStatus('selectWithTrailer', Status.Disabled); - // } else { - // calculationStore.setStatus('selectWithTrailer', Status.Default); - // } - // }, - // }), + calculationStore => ({ + expression: () => { + const { recalcWithRevision } = calculationStore.values; + return recalcWithRevision; + }, + effect: recalcWithRevision => { + if (recalcWithRevision === true) { + calculationStore.setStatus('selectLead', Status.Disabled); + calculationStore.setStatus('selectOpportunity', Status.Disabled); + calculationStore.setStatus('selectQuote', Status.Disabled); + } else { + calculationStore.setStatus('selectLead', Status.Default); + calculationStore.setStatus('selectOpportunity', Status.Default); + calculationStore.setStatus('selectQuote', Status.Default); + } + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { quote } = calculationStore.values; - // return quote; - // }, - // effect: quoteId => { - // if (quoteId) { - // const quote = calculationStore.options.selectQuote?.find( - // x => x.quoteid === quoteId, - // ); - // if (quote) { - // if (quote.evo_recalc_limit && quote.evo_recalc_limit > 0) { - // if (quote.evo_statuscodeid) { - // CalculationService.getEntityOptions({ - // query: { - // entityName: 'evo_statuscode', - // where: { - // evo_statuscodeid: quote.evo_statuscodeid, - // statecode: 0, - // }, - // }, - // }) - // .then(({ entityOptions: evo_statuscodes }) => { - // if (evo_statuscodes && evo_statuscodes.length > 0) { - // const evo_statuscode = evo_statuscodes[0]; - // if (evo_statuscode.evo_id === '2.3') { - // calculationStore.setStatus( - // 'cbxRecalcWithRevision', - // Status.Default, - // ); - // return; - // } - // } - // }) - // .catch(err => { - // throw err; - // }); - // } - // } - // } - // } - // calculationStore.setStatus('cbxRecalcWithRevision', Status.Disabled); - // }, - // }), + calculationStore => ({ + expression: () => { + const { + supplierDiscountRub, + leaseObjectPrice, + supplierCurrency, + } = calculationStore.values; + return [supplierDiscountRub, leaseObjectPrice, supplierCurrency]; + }, + effect: ([supplierDiscountRub, leaseObjectPrice, supplierCurrencyId]) => { + const { recalcWithRevision, maxPriceChange } = calculationStore.values; + if (recalcWithRevision === false) { + return; + } - // calculationStore => ({ - // expression: () => { - // const { firstPaymentPerc } = calculationStore.values; - // return firstPaymentPerc; - // }, - // effect: firstPaymentPerc => { - // const { recalcWithRevision, quote: quoteId } = calculationStore.values; - // if (recalcWithRevision) { - // const quote = calculationStore.options.selectQuote?.find( - // x => x.quoteid === quoteId, - // ); - // if (quote && quote.evo_approved_first_payment) { - // if (firstPaymentPerc < quote.evo_approved_first_payment) { - // calculationStore.setValidation('tbxFirstPaymentPerc', false); - // openNotification({ - // type: 'error', - // title: 'Ошибка', - // description: - // 'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения', - // })(); - // return; - // } - // } - // } - // calculationStore.setValidation('tbxFirstPaymentPerc', undefined); - // }, - // }), + const supplierCurrency = calculationStore + .getOptions('selectSupplierCurrency') + .find(x => x.transactioncurrencyid === supplierCurrencyId); + const evo_currencychange = calculationStore + .getStaticData('evo_currencychange') + ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + const evo_currencychangeValue = + (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + let price = calcPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice, + evo_currencychangeValue, + ); - // calculationStore => ({ - // expression: () => { - // const { brand, model, leaseObjectUsed } = calculationStore.values; - // return [brand, model, leaseObjectUsed]; - // }, - // effect: ([brandId, modelId, leaseObjectUsed]) => { - // if (leaseObjectUsed === false) { - // const model = calculationStore.options.selectModel?.find( - // x => x.evo_modelid === modelId, - // ); - // const brand = calculationStore.options.selectBrand?.find( - // x => x.evo_brandid === brandId, - // ); + if (price - supplierDiscountRub > maxPriceChange) { + calculationStore.setValidation('tbxLeaseObjectPrice', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: + 'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра.' + + 'Уменьшите стоимость предмета лизинга', + })(); + } else { + calculationStore.setValidation('tbxLeaseObjectPrice', true); + } + }, + }), - // if ( - // model && - // model.evo_importer_reward_perc && - // model.evo_importer_reward_perc > 0 - // ) { - // calculationStore.setValue( - // 'importerRewardPerc', - // model.evo_importer_reward_perc, - // ); - // return; - // } - // if ( - // brand && - // brand.evo_importer_reward_perc && - // brand.evo_importer_reward_perc > 0 - // ) { - // calculationStore.setValue( - // 'importerRewardPerc', - // brand.evo_importer_reward_perc, - // ); - // return; - // } - // } - // calculationStore.setValue('importerRewardPerc', 0); - // }, - // }), + calculationStore => ({ + expression: () => { + const { leaseObjectUsed } = calculationStore.values; + return leaseObjectUsed; + }, + effect: leaseObjectUsed => { + if (leaseObjectUsed === true) { + calculationStore.setValue('deliveryTime', 100000000); + calculationStore.setStatus('radioDeliveryTime', Status.Disabled); + } else { + calculationStore.setStatus('radioDeliveryTime', Status.Default); + } + }, + options: { + fireImmediately: true, + }, + }), - // calculationStore => ({ - // expression: () => { - // const { brand, model, leaseObjectUsed } = calculationStore.values; - // return [brand, model, leaseObjectUsed]; - // }, - // effect: ([brandId, modelId, leaseObjectUsed]) => { - // if (leaseObjectUsed === false) { - // const model = calculationStore.options.selectModel?.find( - // x => x.evo_modelid === modelId, - // ); - // const brand = calculationStore.options.selectBrand?.find( - // x => x.evo_brandid === brandId, - // ); + calculationStore => ({ + expression: () => { + const { leaseObjectCategory } = calculationStore.values; + return leaseObjectCategory; + }, + effect: leaseObjectCategory => { + if ( + leaseObjectCategory === 100000001 || + leaseObjectCategory === 100000001 + ) { + calculationStore.setValue('withTrailer', null); + calculationStore.setStatus('selectWithTrailer', Status.Disabled); + } else { + calculationStore.setStatus('selectWithTrailer', Status.Default); + } + }, + options: { + fireImmediately: true, + }, + }), - // if ( - // model && - // model.evo_importer_reward_rub && - // model.evo_importer_reward_rub > 0 - // ) { - // calculationStore.setValue( - // 'importerRewardRub', - // model.evo_importer_reward_rub, - // ); - // return; - // } - // if ( - // brand && - // brand.evo_importer_reward_rub && - // brand.evo_importer_reward_rub > 0 - // ) { - // calculationStore.setValue( - // 'importerRewardRub', - // brand.evo_importer_reward_rub, - // ); - // return; - // } - // } - // calculationStore.setValue('importerRewardRub', 0); - // }, - // }), + calculationStore => ({ + expression: () => { + const { quote } = calculationStore.values; + return quote; + }, + effect: quoteId => { + calculationStore.setStatus('cbxRecalcWithRevision', Status.Disabled); + if (quoteId) { + const quote = calculationStore.options.selectQuote?.find( + x => x.quoteid === quoteId, + ); + if (quote) { + if (quote.evo_recalc_limit && quote.evo_recalc_limit > 0) { + if (quote.evo_statuscode?.evo_id === '2.3') { + calculationStore.setStatus( + 'cbxRecalcWithRevision', + Status.Default, + ); + } + } + } + } + }, + }), - // calculationStore => ({ - // expression: () => { - // const { rows: tableRows } = calculationStore.tables.tableInsurance; - // const kaskoRowIndex = tableRows.findIndex( - // x => x.policyType?.value === 'КАСКО', - // ); + calculationStore => ({ + expression: () => { + const { firstPaymentPerc } = calculationStore.values; + return firstPaymentPerc; + }, + effect: firstPaymentPerc => { + const { recalcWithRevision, quote: quoteId } = calculationStore.values; + if (recalcWithRevision) { + const quote = calculationStore.options.selectQuote?.find( + x => x.quoteid === quoteId, + ); + if (quote && quote.evo_approved_first_payment) { + if (firstPaymentPerc < quote.evo_approved_first_payment) { + calculationStore.setValidation('tbxFirstPaymentPerc', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: + 'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения', + })(); + return; + } + } + } + calculationStore.setValidation('tbxFirstPaymentPerc', undefined); + }, + }), - // const kaskoValues = calculationStore.getTableRowValues( - // 'tableInsurance', - // kaskoRowIndex, - // 'value', - // ); + calculationStore => ({ + expression: () => { + const { brand, model, leaseObjectUsed } = calculationStore.values; + return [brand, model, leaseObjectUsed]; + }, + effect: ([brandId, modelId, leaseObjectUsed]) => { + if (leaseObjectUsed === false) { + const model = calculationStore.options.selectModel?.find( + x => x.evo_modelid === modelId, + ); + const brand = calculationStore.options.selectBrand?.find( + x => x.evo_brandid === brandId, + ); - // return { - // ...kaskoValues, - // }; - // }, - // effect: ({ insuranceCompany, insTerm, insured }) => { - // if (insTerm) { - // const { rows: tableRows } = calculationStore.tables.tableInsurance; - // const dgoRowIndex = tableRows.findIndex( - // x => x.policyType?.value === 'ДГО', - // ); - // if (dgoRowIndex && dgoRowIndex >= 0) - // calculationStore.setTableRows( - // 'tableInsurance', - // dgoRowIndex, - // )([ - // { - // insuranceCompany: { - // value: insuranceCompany, - // }, - // insTerm: { - // value: insTerm, - // }, - // insured: { - // value: insured, - // }, - // }, - // { - // insuranceCompany: { - // value: insuranceCompany, - // }, - // insTerm: { - // value: insTerm, - // }, - // insured: { - // value: insured, - // }, - // }, - // ]); - // } - // }, - // }), + if ( + model && + model.evo_importer_reward_perc && + model.evo_importer_reward_perc > 0 + ) { + calculationStore.setValue( + 'importerRewardPerc', + model.evo_importer_reward_perc, + ); + return; + } + if ( + brand && + brand.evo_importer_reward_perc && + brand.evo_importer_reward_perc > 0 + ) { + calculationStore.setValue( + 'importerRewardPerc', + brand.evo_importer_reward_perc, + ); + return; + } + } + calculationStore.setValue('importerRewardPerc', 0); + }, + options: { fireImmediately: true }, + }), - // calculationStore => ({ - // expression: () => { - // const { rows: tableRows } = calculationStore.tables.tableInsurance; - // const kaskoRowIndex = tableRows.findIndex(x => x.policyType === 'КАСКО'); - // const kaskoRow = tableRows[kaskoRowIndex]; - // const { leasingPeriod } = calculationStore.values; - // if (kaskoRow) { - // return { - // insTerm: kaskoRow.insTerm?.value, - // kaskoRowIndex, - // leasingPeriod, - // }; - // } - // }, - // effect: ({ insTerm, kaskoRowIndex, leasingPeriod }) => { - // if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { - // if (kaskoRowIndex >= 0) - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insured: { value: 100000001, status: Status.Disabled }, - // }); - // } else { - // if (kaskoRowIndex >= 0) - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insured: { status: Status.Default }, - // }); - // } - // }, - // }), + calculationStore => ({ + expression: () => { + const { brand, model, leaseObjectUsed } = calculationStore.values; + return [brand, model, leaseObjectUsed]; + }, + effect: ([brandId, modelId, leaseObjectUsed]) => { + if (leaseObjectUsed === false) { + const model = calculationStore.options.selectModel?.find( + x => x.evo_modelid === modelId, + ); + const brand = calculationStore.options.selectBrand?.find( + x => x.evo_brandid === brandId, + ); - // calculationStore => ({ - // expression: () => { - // const { leasingPeriod } = calculationStore.values; - // return leasingPeriod; - // }, - // effect: leasingPeriod => { - // const { rows: tableRows } = calculationStore.tables.tableInsurance; - // const kaskoRowIndex = tableRows.findIndex( - // x => x.policyType?.value === 'КАСКО', - // ); - // const osagoRowIndex = tableRows.findIndex( - // x => x.policyType?.value === 'ОСАГО', - // ); + if ( + model && + model.evo_importer_reward_rub && + model.evo_importer_reward_rub > 0 + ) { + calculationStore.setValue( + 'importerRewardRub', + model.evo_importer_reward_rub, + ); + return; + } + if ( + brand && + brand.evo_importer_reward_rub && + brand.evo_importer_reward_rub > 0 + ) { + calculationStore.setValue( + 'importerRewardRub', + brand.evo_importer_reward_rub, + ); + return; + } + } + calculationStore.setValue('importerRewardRub', 0); + }, + options: { fireImmediately: true }, + }), - // if (leasingPeriod) { - // if (leasingPeriod < 12) { - // if (kaskoRowIndex >= 0) - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insured: { value: 100000000, status: Status.Disabled }, - // }); - // if (osagoRowIndex >= 0) { - // calculationStore.setTableRow( - // 'tableInsurance', - // osagoRowIndex, - // )({ - // insured: { value: 100000000, status: Status.Disabled }, - // }); - // } - // } else { - // if (kaskoRowIndex >= 0) - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insured: { value: 100000000, status: Status.Default }, - // }); - // if (osagoRowIndex >= 0) { - // calculationStore.setTableRow( - // 'tableInsurance', - // osagoRowIndex, - // )({ - // insured: { status: Status.Default }, - // }); - // } - // } + calculationStore => ({ + expression: () => { + const { rows: tableRows } = calculationStore.tables.tableInsurance; + const kaskoRowIndex = tableRows.findIndex( + x => x.policyType?.value === 'КАСКО', + ); - // if (leasingPeriod < 13) { - // if (kaskoRowIndex >= 0) - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insTerm: { value: 100000000, status: Status.Disabled }, - // }); - // return; - // } else if (leasingPeriod > 12 && leasingPeriod < 16) { - // if (kaskoRowIndex >= 0) - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insTerm: { value: 100000001, status: Status.Disabled }, - // }); - // return; - // } else { - // if (kaskoRowIndex >= 0) { - // calculationStore.setTableRow( - // 'tableInsurance', - // kaskoRowIndex, - // )({ - // insured: { status: Status.Default }, - // insTerm: { status: Status.Default }, - // }); - // } - // } - // } - // }, - // options: { - // fireImmediately: true, - // }, - // }), + const kaskoValues = calculationStore.getTableRowValues( + 'tableInsurance', + kaskoRowIndex, + 'value', + ); - // calculationStore => ({ - // expression: () => { - // const { graphType, leasingPeriod } = calculationStore.values; - // return { graphType, leasingPeriod }; - // }, - // effect: ({ graphType, leasingPeriod }) => { - // if (graphType === 100000003 && leasingPeriod < 14) { - // calculationStore.setValue('leasingPeriod', 14); - // openNotification({ - // type: 'warning', - // title: 'Внимание', - // description: - // 'При сезонном графике срок лизинга должен быть больше 14 месяцев', - // })(); - // } - // }, - // }), + return { + ...kaskoValues, + }; + }, + effect: ({ insuranceCompany, insTerm, insured }) => { + if (insTerm) { + const { rows: tableRows } = calculationStore.tables.tableInsurance; + const dgoRowIndex = tableRows.findIndex( + x => x.policyType?.value === 'ДГО', + ); + if (dgoRowIndex && dgoRowIndex >= 0) + calculationStore.setTableRows( + 'tableInsurance', + dgoRowIndex, + )([ + { + insuranceCompany: { + value: insuranceCompany, + }, + insTerm: { + value: insTerm, + }, + insured: { + value: insured, + }, + }, + { + insuranceCompany: { + value: insuranceCompany, + }, + insTerm: { + value: insTerm, + }, + insured: { + value: insured, + }, + }, + ]); + } + }, + }), - // calculationStore => ({ - // expression: () => { - // const { - // leasingPeriod, - // graphType, - // parmentsDecreasePercent, - // seasonType, - // highSeasonStart: highSeasonStartId, - // firstPaymentPerc, - // lastPaymentPerc, - // } = calculationStore.values; + 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 highSeasonStart = calculationStore.options.selectHighSeasonStart?.find( - // x => x.value === highSeasonStartId, - // ); + return { + insTerm: kaskoRow.insTerm?.value, + leasingPeriod, + }; + }, + effect: ({ insTerm, leasingPeriod }) => { + const { rows: tableRows } = calculationStore.tables.tableInsurance; + const kaskoRowIndex = tableRows.findIndex( + x => x.policyType?.value === 'КАСКО', + ); + if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { + if (kaskoRowIndex >= 0) + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insured: { value: 100000001, status: Status.Disabled }, + }); + } else { + if (kaskoRowIndex >= 0) + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insured: { status: Status.Default }, + }); + } + }, + }), - // return { - // leasingPeriod, - // graphType, - // parmentsDecreasePercent, - // seasonType, - // highSeasonStart: parseInt(highSeasonStart?.name || '2'), - // firstPaymentPerc, - // lastPaymentPerc, - // }; - // }, - // effect: async (nextParams, prevParams) => { - // const { - // leasingPeriod, - // graphType, - // parmentsDecreasePercent, - // seasonType, - // highSeasonStart, - // firstPaymentPerc, - // lastPaymentPerc, - // } = nextParams; + calculationStore => ({ + expression: () => { + const { leasingPeriod } = calculationStore.values; + return leasingPeriod; + }, + effect: leasingPeriod => { + const { rows: tableRows } = calculationStore.tables.tableInsurance; + const kaskoRowIndex = tableRows.findIndex( + x => x.policyType?.value === 'КАСКО', + ); + const osagoRowIndex = tableRows.findIndex( + x => x.policyType?.value === 'ОСАГО', + ); - // const prevValues = toJS(calculationStore.tables.tablePayments.rows).map( - // x => x.paymentRelation?.value, - // ); - // let payments: TableProps[] = [ - // { - // paymentRelation: { - // value: firstPaymentPerc, - // status: Status.Disabled, - // }, - // }, - // ]; + if (leasingPeriod) { + if (leasingPeriod < 12) { + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insured: { value: 100000000, status: Status.Disabled }, + }); + calculationStore.setTableRow( + 'tableInsurance', + osagoRowIndex, + )({ + insured: { value: 100000000, status: Status.Disabled }, + }); + } else { + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insured: { value: 100000000, status: Status.Default }, + }); + calculationStore.setTableRow( + 'tableInsurance', + osagoRowIndex, + )({ + insured: { status: Status.Default }, + }); + } - // calculationStore.cleanTable('tablePayments'); + if (leasingPeriod === 12) { + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insTerm: { value: 100000000, status: Status.Disabled }, + }); + return; + } else if (leasingPeriod > 12 && leasingPeriod < 16) { + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insTerm: { value: 100000001, status: Status.Disabled }, + }); + return; + } else { + calculationStore.setTableRow( + 'tableInsurance', + kaskoRowIndex, + )({ + insured: { status: Status.Default }, + insTerm: { status: Status.Default }, + }); + } + } + }, + options: { + fireImmediately: true, + }, + }), - // switch (graphType) { - // case 100000000: { - // const middleRows = Array.from({ length: leasingPeriod - 2 }, () => ({ - // paymentRelation: { - // value: 100, - // status: Status.Disabled, - // }, - // })); - // payments = [...payments, ...middleRows]; + calculationStore => ({ + expression: () => { + const { graphType, leasingPeriod } = calculationStore.values; + return { graphType, leasingPeriod }; + }, + effect: ({ graphType, leasingPeriod }) => { + if (graphType === 100000003 && leasingPeriod < 14) { + calculationStore.setValue('leasingPeriod', 14); + openNotification({ + type: 'warning', + title: 'Внимание', + description: + 'При сезонном графике срок лизинга должен быть больше 14 месяцев', + })(); + } + }, + }), - // break; - // } + calculationStore => ({ + expression: () => { + const { + leasingPeriod, + graphType, + parmentsDecreasePercent, + seasonType, + highSeasonStart: highSeasonStartId, + firstPaymentPerc, + lastPaymentPerc, + } = calculationStore.values; - // case 100000001: { - // const middleRows = Array.from({ length: leasingPeriod - 3 }, () => ({ - // paymentRelation: { - // value: 100, - // status: Status.Default, - // }, - // })); - // payments = [ - // ...payments, - // { - // paymentRelation: { - // value: 100, - // status: Status.Disabled, - // }, - // }, - // ...middleRows, - // ]; + const highSeasonStart = calculationStore.options.selectHighSeasonStart?.find( + x => x.value === highSeasonStartId, + ); - // break; - // } + return { + leasingPeriod, + graphType, + parmentsDecreasePercent, + seasonType, + highSeasonStart: parseInt(highSeasonStart?.name || '2'), + firstPaymentPerc, + lastPaymentPerc, + }; + }, + effect: async (nextParams, prevParams) => { + const { + leasingPeriod, + graphType, + parmentsDecreasePercent, + seasonType, + highSeasonStart, + firstPaymentPerc, + lastPaymentPerc, + } = nextParams; - // case 100000002: { - // const middleRows = Array.from( - // { length: leasingPeriod - 3 }, - // (v, i) => ({ - // paymentRelation: { - // value: 100, - // status: Status.Disabled, - // }, - // }), - // ); - // for (let i in middleRows) { - // const currRow = middleRows[parseInt(i)]; - // const prevRow = middleRows[parseInt(i) - 1]; - // currRow.paymentRelation.value = parseFloat( - // ( - // ((prevRow ? prevRow.paymentRelation.value : 100) * - // parmentsDecreasePercent) / - // 100 - // ).toFixed(2), - // ); - // } - // payments = [ - // ...payments, - // { - // paymentRelation: { - // value: 100, - // status: Status.Disabled, - // }, - // }, - // ...middleRows, - // ]; + const prevValues = toJS(calculationStore.tables.tablePayments.rows).map( + x => x.paymentRelation?.value, + ); + let payments: TableProps[] = [ + { + paymentRelation: { + value: firstPaymentPerc, + status: Status.Disabled, + }, + }, + ]; - // break; - // } + calculationStore.cleanTable('tablePayments'); - // case 100000003: { - // let HIGH = 100, - // MIDDLE = 75, - // LOW = 50; + switch (graphType) { + case 100000000: { + const middleRows = Array.from({ length: leasingPeriod - 2 }, () => ({ + paymentRelation: { + value: 100, + status: Status.Disabled, + }, + })); + payments = [...payments, ...middleRows]; - // if ( - // prevParams.graphType === nextParams.graphType - // // && nextParams.graphType === 100000003 - // ) { - // /** - // * FIND PREV HIGH, MIDDLE, LOW - // */ - // const { - // leasingPeriod: prevLeasingPeriod, - // seasonType: prevSeasonType, - // highSeasonStart: prevHighSeasonStart, - // } = prevParams; + break; + } - // const prevPeriodsNumber = - // prevLeasingPeriod <= 14 ? prevLeasingPeriod - 2 : 12; - // const prevShiftNumber = prevHighSeasonStart - 2; + case 100000001: { + const middleRows = Array.from({ length: leasingPeriod - 3 }, () => ({ + paymentRelation: { + value: 100, + status: Status.Default, + }, + })); + payments = [ + ...payments, + { + paymentRelation: { + value: 100, + status: Status.Disabled, + }, + }, + ...middleRows, + ]; - // let middleRows = prevValues.slice(1, prevPeriodsNumber + 1); - // if (middleRows.length < 12) { - // middleRows = [ - // ...middleRows, - // ...Array.from({ length: 12 - middleRows.length }, v => 0), - // ]; - // } - // if (prevShiftNumber > 0) - // middleRows = shiftRight(middleRows, prevShiftNumber); + break; + } - // switch (prevSeasonType) { - // // 6/6 - // case 100000000: { - // HIGH = middleRows[0]; - // LOW = middleRows[6]; - // break; - // } - // // 8/4 - // case 100000001: { - // HIGH = middleRows[0]; - // LOW = middleRows[8]; + case 100000002: { + const middleRows = Array.from( + { length: leasingPeriod - 3 }, + (v, i) => ({ + paymentRelation: { + value: 100, + status: Status.Disabled, + }, + }), + ); + for (let i in middleRows) { + const currRow = middleRows[parseInt(i)]; + const prevRow = middleRows[parseInt(i) - 1]; + currRow.paymentRelation.value = parseFloat( + ( + ((prevRow ? prevRow.paymentRelation.value : 100) * + parmentsDecreasePercent) / + 100 + ).toFixed(2), + ); + } + payments = [ + ...payments, + { + paymentRelation: { + value: 100, + status: Status.Disabled, + }, + }, + ...middleRows, + ]; - // break; - // } - // // 4/4/4 - // case 100000002: { - // HIGH = middleRows[0]; - // MIDDLE = middleRows[4]; - // LOW = middleRows[8]; - // break; - // } - // } - // /** */ - // } + break; + } - // /** - // * GENERATE PERIODS - // */ + case 100000003: { + let HIGH = 100, + MIDDLE = 75, + LOW = 50; - // const { - // leasingPeriod: nextLeasingPeriod, - // seasonType: nextSeasonType, - // highSeasonStart: nextHighSeasonStart, - // } = nextParams; + if ( + prevParams.graphType === nextParams.graphType + // && nextParams.graphType === 100000003 + ) { + /** + * FIND PREV HIGH, MIDDLE, LOW + */ + const { + leasingPeriod: prevLeasingPeriod, + seasonType: prevSeasonType, + highSeasonStart: prevHighSeasonStart, + } = prevParams; - // const nextPeriodsNumber = - // nextLeasingPeriod <= 14 ? nextLeasingPeriod - 2 : 12; - // const nextShiftNumber = nextHighSeasonStart - 2; + const prevPeriodsNumber = + prevLeasingPeriod <= 14 ? prevLeasingPeriod - 2 : 12; + const prevShiftNumber = prevHighSeasonStart - 2; - // let nextPeriods: number[] = []; + let middleRows = prevValues.slice(1, prevPeriodsNumber + 1); + if (middleRows.length < 12) { + middleRows = [ + ...middleRows, + ...Array.from({ length: 12 - middleRows.length }, v => 0), + ]; + } + if (prevShiftNumber > 0) + middleRows = shiftRight(middleRows, prevShiftNumber); - // switch (nextSeasonType) { - // // 6/6 - // case 100000000: { - // nextPeriods = Array.from({ length: 12 }, (v, i) => - // i < 6 ? HIGH : LOW, - // ); - // break; - // } - // // 8/4 - // case 100000001: { - // nextPeriods = Array.from({ length: 12 }, (v, i) => - // i < 8 ? HIGH : LOW, - // ); - // break; - // } - // // 4/4/4 - // case 100000002: { - // nextPeriods = Array.from( - // { length: 12 }, - // (v, i) => (i < 4 && HIGH) || (i < 8 && MIDDLE) || LOW, - // ); - // break; - // } - // } - // if (nextShiftNumber > 0) { - // nextPeriods = shift(nextPeriods, nextShiftNumber); - // } - // nextPeriods.length = nextPeriodsNumber; + switch (prevSeasonType) { + // 6/6 + case 100000000: { + HIGH = middleRows[0]; + LOW = middleRows[6]; + break; + } + // 8/4 + case 100000001: { + HIGH = middleRows[0]; + LOW = middleRows[8]; - // const middleRows = Array.from( - // { length: nextLeasingPeriod - 2 }, - // (v, i) => { - // return { - // paymentRelation: { - // value: - // nextPeriods[ - // i - nextPeriodsNumber * Math.floor(i / nextPeriodsNumber) - // ], - // status: - // i < nextPeriodsNumber ? Status.Default : Status.Disabled, - // }, - // }; - // }, - // ); + break; + } + // 4/4/4 + case 100000002: { + HIGH = middleRows[0]; + MIDDLE = middleRows[4]; + LOW = middleRows[8]; + break; + } + } + /** */ + } - // payments = [...payments, ...middleRows]; + /** + * GENERATE PERIODS + */ - // break; - // } + const { + leasingPeriod: nextLeasingPeriod, + seasonType: nextSeasonType, + highSeasonStart: nextHighSeasonStart, + } = nextParams; - // case 100000004: { - // const middleRows = Array.from({ length: leasingPeriod - 5 }, () => ({ - // paymentRelation: { - // value: 100, - // status: Status.Disabled, - // }, - // })); + const nextPeriodsNumber = + nextLeasingPeriod <= 14 ? nextLeasingPeriod - 2 : 12; + const nextShiftNumber = nextHighSeasonStart - 2; - // payments = [ - // ...payments, - // { - // paymentRelation: { - // value: 25, - // status: Status.Default, - // }, - // }, - // { - // paymentRelation: { - // value: 50, - // status: Status.Default, - // }, - // }, - // { - // paymentRelation: { - // value: 75, - // status: Status.Default, - // }, - // }, - // ...middleRows, - // ]; - // break; - // } + let nextPeriods: number[] = []; - // default: { - // break; - // } - // } + switch (nextSeasonType) { + // 6/6 + case 100000000: { + nextPeriods = Array.from({ length: 12 }, (v, i) => + i < 6 ? HIGH : LOW, + ); + break; + } + // 8/4 + case 100000001: { + nextPeriods = Array.from({ length: 12 }, (v, i) => + i < 8 ? HIGH : LOW, + ); + break; + } + // 4/4/4 + case 100000002: { + nextPeriods = Array.from( + { length: 12 }, + (v, i) => (i < 4 && HIGH) || (i < 8 && MIDDLE) || LOW, + ); + break; + } + } + if (nextShiftNumber > 0) { + nextPeriods = shift(nextPeriods, nextShiftNumber); + } + nextPeriods.length = nextPeriodsNumber; - // payments = [ - // ...payments, - // { - // paymentRelation: { - // value: lastPaymentPerc, - // status: Status.Disabled, - // }, - // }, - // ]; + const middleRows = Array.from( + { length: nextLeasingPeriod - 2 }, + (v, i) => { + return { + paymentRelation: { + value: + nextPeriods[ + i - nextPeriodsNumber * Math.floor(i / nextPeriodsNumber) + ], + status: + i < nextPeriodsNumber ? Status.Default : Status.Disabled, + }, + }; + }, + ); - // calculationStore.setTableRows('tablePayments', 0)(payments); - // }, - // options: { - // fireImmediately: true, - // }, - // }), + payments = [...payments, ...middleRows]; + + break; + } + + case 100000004: { + const middleRows = Array.from({ length: leasingPeriod - 5 }, () => ({ + paymentRelation: { + value: 100, + status: Status.Disabled, + }, + })); + + payments = [ + ...payments, + { + paymentRelation: { + value: 25, + status: Status.Default, + }, + }, + { + paymentRelation: { + value: 50, + status: Status.Default, + }, + }, + { + paymentRelation: { + value: 75, + status: Status.Default, + }, + }, + ...middleRows, + ]; + break; + } + + default: { + break; + } + } + + payments = [ + ...payments, + { + paymentRelation: { + value: lastPaymentPerc, + status: Status.Disabled, + }, + }, + ]; + + calculationStore.setTableRows('tablePayments', 0)(payments); + }, + options: { + fireImmediately: true, + }, + }), ]; export default reactionEffects; diff --git a/src/core/Data/initialOptions.ts b/src/core/Data/initialOptions.ts index 9bc9091..ffa08ea 100644 --- a/src/core/Data/initialOptions.ts +++ b/src/core/Data/initialOptions.ts @@ -28,7 +28,7 @@ const initialOptions: TEntityQuery[] = [ 'accountid', 'evo_leadid', 'evo_client_riskid', - // 'parentaccountid', + 'parentaccountid', ], where: { statecode: 0 }, many: true, diff --git a/src/core/Data/staticEntitiesList.ts b/src/core/Data/staticEntitiesList.ts deleted file mode 100644 index 7481517..0000000 --- a/src/core/Data/staticEntitiesList.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { TEntityQuery } from '../types/Entities/query'; - -const staticEntitiesList: TEntityQuery[] = [ - { - entityName: 'evo_impairment_group', - where: { - statecode: 0, - }, - fields: ['evo_impairment_groupid', 'evo_name'], - many: true, - }, - { - entityName: 'evo_currencychange', - where: { - //TODO: Date without time - // evo_coursedate: new Date(), - statecode: 0, - }, - fields: ['evo_currencychange'], - many: true, - }, -]; - -export default staticEntitiesList; diff --git a/src/core/config/initialValues.ts b/src/core/config/initialValues.ts index 8ba6299..e7b48a7 100644 --- a/src/core/config/initialValues.ts +++ b/src/core/config/initialValues.ts @@ -4,7 +4,7 @@ const initialValues: TValues = { recalcWithRevision: false, contactGender: 100000000, leaseObjectPrice: 1000000, - // supplierCurrency: 'RUB', + supplierCurrency: 'RUB', supplierDiscountRub: 0, supplierDiscountPerc: 0, // addEquipmentCurrency: 'RUB', diff --git a/src/core/types/Calculation/Store/index.ts b/src/core/types/Calculation/Store/index.ts index dfce126..69d8953 100644 --- a/src/core/types/Calculation/Store/index.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -16,7 +16,7 @@ import { TValue, TValues, ValuesNames } from './values'; interface ICalculationValues { staticData: TStaticData; - getStaticData: (dataName: CRMEntityNames) => IBaseOption[]; + getStaticData: (dataName: CRMEntityNames) => (IBaseOption & TCRMEntity)[]; applyStaticData: (data: TStaticData) => void; options: TElements<(IBaseOption & TCRMEntity)[]>; diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 7e7e746..009915b 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -50,6 +50,7 @@ export interface IQuote { ownerid?: string; statecode?: number; evo_statuscodeid?: string; + evo_statuscode?: IEvoStatusCode; } export interface ITransactionCurrency { @@ -191,6 +192,7 @@ export interface IEvoCurrencyChange { evo_currencychange?: number; evo_coursedate?: Date; statecode?: number; + evo_coursedate_param: any; } export interface IEvoStatusCode { diff --git a/src/core/types/Entities/crmEntityNames.ts b/src/core/types/Entities/crmEntityNames.ts index 0bad4ef..be07889 100644 --- a/src/core/types/Entities/crmEntityNames.ts +++ b/src/core/types/Entities/crmEntityNames.ts @@ -30,16 +30,7 @@ export type CRMEntityNames = | 'systemuser' | 'evo_sot_coefficient_type'; -export const CRMEntityAliases = [ - 'agent', - 'double_agent', - 'broker', - 'findepartment', -] as const; -type CRMEntityAliasesType = typeof CRMEntityAliases; -export type CRMEntityAliasesUnion = CRMEntityAliasesType[number]; - //TODO: or string export type TEntities = { - [entityName in CRMEntityNames | CRMEntityAliasesUnion]?: T; + [entityName in CRMEntityNames]?: T; };