diff --git a/src/client/Containers/Calculation/index.jsx b/src/client/Containers/Calculation/index.jsx index 6e3d725..dfc19e4 100644 --- a/src/client/Containers/Calculation/index.jsx +++ b/src/client/Containers/Calculation/index.jsx @@ -24,28 +24,31 @@ const Calculation = () => { CalculationService.getEntities({ queries: staticEntitiesList, }), - // CalculationService.getEntities({ - // queries: [ - // { - // entityName: 'accounts', - // where: { evo_account_type: 100000002, statecode: 0 }, - // }, - // ], - // toOptions: true, - // }), + CalculationService.getEntities({ + queries: [ + { + alias: 'insuranceCompany', + entityName: 'account', + where: { evo_account_type: 100000002, statecode: 0 }, + fields: ['accountid', 'name', 'evo_type_ins_policy'], + many: true, + }, + ], + toOptions: true, + }), ]) .then( ([ { entities: initialOptions }, { entities: staticEntities }, - // { entities: insuranceCompanies }, + { entities: insuranceCompanies }, ]) => { - console.log(initialOptions); + console.log(insuranceCompanies); calculationStore.applyOptions(initialOptions); calculationStore.applyStaticData(staticEntities); - // calculationStore.setTableColumns('tableInsurance')({ - // options: { insuranceCompany: insuranceCompanies }, - // }); + calculationStore.setTableColumns('tableInsurance')({ + options: { ...insuranceCompanies }, + }); setStatus(LoadingStatus.ready); }, ) diff --git a/src/core/Data/initialOptions.ts b/src/core/Data/initialOptions.ts index d828e02..c9f1e91 100644 --- a/src/core/Data/initialOptions.ts +++ b/src/core/Data/initialOptions.ts @@ -1,19 +1,29 @@ import { TEntityQuery } from 'core/types/Entities/query'; +import { DateTime } from 'luxon'; + +const currentDate = DateTime.local().toUTC().toJSDate(); const initialOptions: TEntityQuery[] = [ { alias: 'selectLead', entityName: 'lead', - fields: ['leadid', 'fullname'], + fields: ['leadid', 'fullname', 'evo_opportunityid'], + where: { statecode: 0 }, + many: true, + }, + { + alias: 'selectOpportunity', + entityName: 'opportunity', + fields: [ + 'opportunityid', + 'name', + 'accountid', + 'evo_leadid', + 'evo_client_riskid', + ], where: { statecode: 0 }, many: true, }, - // { - // alias: 'selectOpportunity', - // entityName: 'opportunities', - // fields: ['opportunityid', 'name'], - // where: { statecode: 0 }, - // }, { alias: 'selectSupplier', entityName: 'account', @@ -25,71 +35,153 @@ const initialOptions: TEntityQuery[] = [ fields: ['accountid', 'name'], many: true, }, - // { - // alias: 'selectSupplierCurrency', - // entityName: 'transactioncurrency', - // where: { - // statecode: 0, - // }, - // }, - // { - // alias: 'selectClientRisk', - // entityName: 'evo_client_risk', - // where: { - // statecode: 0, - // }, - // }, - // { - // alias: 'selectClientType', - // entityName: 'evo_client_type', - // where: { - // statecode: 0, - // }, - // }, - // { - // alias: 'selectDealer', - // entityName: 'account', - // where: { - // evo_account_type: 100000001, - // statecode: 0, - // }, - // whereIn: { - // evo_supplier_type: 100000000, - // }, - // }, - // { - // alias: 'selectGPSBrand', - // entityName: 'evo_gps_brand', - // where: { - // statecode: 0, - // }, - // }, - // { - // alias: 'selectRegionRegistration', - // entityName: 'evo_region', - // where: { - // statecode: 0, - // }, - // }, - // { - // alias: 'selectTownRegistration', - // entityName: 'evo_town', - // where: { - // statecode: 0, - // }, - // }, - // // TODO: remove on prod - // { - // alias: 'selectAccount', - // entityName: 'account', - // }, - // { - // alias: 'selectBrand', - // entityName: 'evo_brand', - // where: { - // statecode: 0, - // }, - // }, + { + alias: 'selectSupplierCurrency', + entityName: 'transactioncurrency', + where: { + statecode: 0, + }, + fields: ['transactioncurrencyid', 'isocurrencycode'], + many: true, + }, + { + alias: 'selectClientRisk', + entityName: 'evo_client_risk', + where: { + statecode: 0, + }, + fields: ['statecode', 'evo_name', 'evo_client_riskid'], + many: true, + }, + { + alias: 'selectClientType', + entityName: 'evo_client_type', + where: { + statecode: 0, + }, + fields: ['evo_name', 'evo_client_typeid'], + many: true, + }, + { + alias: 'selectDealer', + entityName: 'account', + where: { + evo_account_type: 100000001, + statecode: 0, + evo_legal_form: 100000001, + }, + fields: ['accountid', 'name'], + many: true, + }, + { + alias: 'selectGPSBrand', + entityName: 'evo_gps_brand', + where: { + statecode: 0, + }, + fields: ['evo_gps_brandid', 'evo_name'], + many: true, + }, + { + alias: 'selectRegionRegistration', + entityName: 'evo_region', + where: { + statecode: 0, + }, + fields: ['evo_name', 'evo_regionid'], + many: true, + }, + + { + alias: 'selectAccount', + entityName: 'account', + where: { + evo_account_type: 100000000, + statecode: 0, + }, + fields: ['accountid', 'name', 'evo_client_riskid'], + many: true, + }, + { + alias: 'selectBrand', + entityName: 'evo_brand', + where: { + statecode: 0, + }, + fields: [ + 'evo_name', + 'evo_brandid', + 'evo_importer_reward_perc', + 'evo_importer_reward_rub', + ], + many: true, + }, + { + alias: 'selectProduct', + entityName: 'evo_baseproduct', + where: { + evo_relation: 100000000, + statecode: 0, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: ['evo_name', 'evo_baseproductid', 'evo_id'], + relatedEntities: [ + { + entityName: 'evo_leasingobject_type', + fields: ['evo_name', 'evo_leasingobject_typeid', 'evo_id'], + many: true, + }, + { + entityName: 'evo_brand', + fields: ['evo_brandid', 'evo_name'], + many: true, + }, + ], + many: true, + }, + { + alias: 'selectRegistration', + entityName: 'evo_addproduct_type', + where: { + statecode: 0, + evo_product_type: 100000001, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: ['evo_addproduct_typeid', 'evo_name'], + many: true, + }, + { + alias: 'selectInsNSIB', + entityName: 'evo_addproduct_type', + where: { + statecode: 0, + evo_product_type: 100000002, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: ['evo_addproduct_typeid', 'evo_name'], + many: true, + }, ]; export default initialOptions; diff --git a/src/core/config/initialTables/tableInsurance.ts b/src/core/config/initialTables/tableInsurance.ts index 630f72c..1f8330d 100644 --- a/src/core/config/initialTables/tableInsurance.ts +++ b/src/core/config/initialTables/tableInsurance.ts @@ -10,6 +10,12 @@ const tableInsurance: ITable = { }, insuranceCompany: { value: null, + filter: options => + options.filter( + x => + x.evo_type_ins_policy && + x.evo_type_ins_policy.includes(100000001), + ), }, insured: { value: null, @@ -28,6 +34,12 @@ const tableInsurance: ITable = { }, insuranceCompany: { value: null, + filter: options => + options.filter( + x => + x.evo_type_ins_policy && + x.evo_type_ins_policy.includes(100000000), + ), }, insured: { value: null, @@ -47,6 +59,12 @@ const tableInsurance: ITable = { insuranceCompany: { value: null, status: Status.Disabled, + filter: options => + options.filter( + x => + x.evo_type_ins_policy && + x.evo_type_ins_policy.includes(100000000), + ), }, insured: { value: null, @@ -67,6 +85,12 @@ const tableInsurance: ITable = { insuranceCompany: { value: null, status: Status.Disabled, + filter: options => + options.filter( + x => + x.evo_type_ins_policy && + x.evo_type_ins_policy.includes(100000000), + ), }, insured: { value: null, diff --git a/src/core/tools/query.ts b/src/core/tools/query.ts index a3b3da8..9dc1e8b 100644 --- a/src/core/tools/query.ts +++ b/src/core/tools/query.ts @@ -43,7 +43,8 @@ const convert = { }; function convertNestedEntity(query: TBaseEntityQuery) { - let entityQuery: string = `${query.entityName}{ + let entityQuery: string = `${ + query.many ? plural(query.entityName) : query.entityName}{ ${convert.fields(query.fields)} ${convert.relatedEntities(query.relatedEntities)} }`; diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 15c1b64..b21759a 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -1,4 +1,6 @@ -import { CRMEntityNames } from "./crmEntityNames"; +import { CRMEntityNames } from './crmEntityNames'; + +interface AccountData {} export interface IAccount { name?: string; @@ -12,6 +14,8 @@ export interface IAccount { ownerid?: string; evo_broker_accountid?: string; evo_client_riskid?: string; + accountidData?: AccountData; + evo_type_ins_policy?: number[]; } export interface ILead { @@ -25,7 +29,7 @@ export interface ILead { export interface IOpportunity { opportunityid?: string; - evo_accountid?: string; + accountid?: string; evo_leadid?: string; evo_client_riskid?: string; ownerid?: string; @@ -67,7 +71,8 @@ export interface IEvoBaseproduct { evo_id?: string; evo_relation?: number; evo_datefrom?: Date; - evo_dateto?: Date; + evo_datefrom_param?: Date; + evo_dateto_param?: Date; evo_leaseobject_types?: IEvoLeasingObjectType[]; evo_brands?: IEvoBrand[]; } diff --git a/src/server/controllers/CalculationController/index.ts b/src/server/controllers/CalculationController/index.ts index 69968cf..3e10b37 100644 --- a/src/server/controllers/CalculationController/index.ts +++ b/src/server/controllers/CalculationController/index.ts @@ -23,30 +23,26 @@ class CalculationController { next: NextFunction, ): Promise => { const { queries, toOptions } = req.body as IGetEntitiesRequest; - // console.log('CalculationController -> queries', queries); - try { - let resEntities = await getEntities(queries); - if (toOptions) { - let entitiesWithOptions: TEntities = {}; - Object.keys(resEntities).forEach(name => { - const targetEntities: TCRMEntity[] = resEntities[name]; + let resEntities = await getEntities(queries); + if (toOptions) { + let entitiesWithOptions: TEntities = {}; + Object.keys(resEntities).forEach(name => { + const targetEntities: TCRMEntity[] = resEntities[name]; - let optionatedOptions = []; - for (let entity of targetEntities) { - optionatedOptions.push( - //@ts-ignore - //TODO - convertEntityToOption(entity, entity.__typename), - ); - } - entitiesWithOptions[name] = optionatedOptions; - }); - res.send({ entities: entitiesWithOptions }); - } - res.send({ entities: resEntities }); - } catch (error) { - throw error; + let optionatedOptions = []; + for (let entity of targetEntities) { + optionatedOptions.push( + //@ts-ignore + //TODO + convertEntityToOption(entity, entity.__typename), + ); + } + entitiesWithOptions[name] = optionatedOptions; + }); + res.send({ entities: entitiesWithOptions }); + return; } + res.send({ entities: resEntities }); }; static calculate = async ( diff --git a/src/server/controllers/CalculationController/prepareData.ts b/src/server/controllers/CalculationController/prepareData.ts index 48be1a3..ccd6029 100644 --- a/src/server/controllers/CalculationController/prepareData.ts +++ b/src/server/controllers/CalculationController/prepareData.ts @@ -1,816 +1,818 @@ -import { IGetCalculationRequest } from 'core/types/Calculation/Requests'; -import { DateTime } from 'luxon'; -import { getEntities } from './crmManager'; -import { PreparedPayments } from 'core/types/Calculation/Prepare'; -import { calcPrice } from 'client/stores/CalculationStore/Effects/lib/tools'; -import valuesConstants from 'core/constants/values'; - -export const prepareCalculationData = ({ - values, - tables, - username, -}: IGetCalculationRequest): any => { - const currentDate = DateTime.local().toUTC().toJSDate(); - const entities = getEntities([ - { - entityName: 'evo_coefficient', - alias: 'evo_coefficient_season', - where: { - evo_corfficient_type: 100000000, - statecode: 0, - //TODO: - // evo_datefrom: '<= currentDate', - // evo_dateto: '>= currentDate', - // evo_min_period: `<= ${values.leasingPeriod}`, - // evo_max_period: `>= ${values.leasingPeriod}`, - }, - fields: [ - 'evo_correction_coefficient', - 'evo_graph_type', - 'evo_season_type', - ], - }, - { - alias: 'evo_coefficient_bonus', - entityName: 'evo_coefficient', - where: { - evo_corfficient_type: 100000002, - statecode: 0, - //TODO: - // evo_datefrom: '<= currentDate', - // evo_dateto: '>= currentDate', - }, - fields: [ - 'evo_job_titleid', - 'evo_sot_coefficient_typeid', - 'evo_sot_coefficient', - ], - }, - { - entityName: 'evo_currencychange', - where: { - evo_coursedate: currentDate, - statecode: 0, - }, - fields: ['isocurrencycode', 'evo_currencychange'], - }, - { - entityName: 'evo_sot_coefficient_type', - where: { - statecode: 0, - }, - fields: ['evo_sot_coefficient_typeid', 'evo_id'], - }, - { - entityName: 'evo_addproduct_type', - where: { - statecode: 0, - //TODO: - // evo_datefrom: '<= currentDate', - // evo_dateto: '>= currentDate', - // evo_min_period: `<= ${values.leasingPeriod}`, - // evo_max_period: `>= ${values.leasingPeriod}`, - }, - fields: [ - 'evo_addproduct_typeid', - 'evo_graph_price_withoutnds', - 'evo_cost_service_provider_withoutnds', - 'evo_retro_bonus_withoutnds', - 'evo_prime_cost', - 'evo_graph_price', - { - entityName: 'evo_planpayment', - fields: [ - 'evo_name', - 'evo_cost_equipment_withoutnds', - 'evo_cost_price_telematics_withoutnds', - 'evo_cost_telematics_withoutnds', - ], - }, - ], - }, - { - entityName: 'evo_tarif', - where: { - evo_tarifid: values.Tarif, - }, - fields: ['evo_irr_plan'], - }, - - { - entityName: 'evo_coefficient', - where: { - evo_corfficient_type: 100000001, - statecode: 0, - //TODO: - // evo_datefrom: '<= currentDate', - // evo_dateto: '>= currentDate', - // evo_min_period: `<= ${values.leasingPeriod}`, - // evo_max_period: `>= ${values.leasingPeriod}`, - }, - fields: [ - 'evo_risk_delta', - { - entityName: 'evo_client_risk', - where: { - evo_client_riskid: values.clientRisk, - }, - }, - { - entityName: 'evo_client_type', - where: { - evo_client_typeid: values.clientType, - }, - }, - { - entityName: 'evo_leasingobject_type', - where: { - evo_leasingobject_typeid: values.leaseObjectType, - }, - }, - ], - }, - { - entityName: 'evo_leasingobject_type', - where: { - evo_leasingobject_typeid: values.leaseObjectType, - }, - fields: [ - 'evo_id', - 'evo_expluatation_period1', - 'evo_expluatation_period2', - 'evo_depreciation_rate1', - 'evo_depreciation_rate2', - ], - }, - ]); - - let preparedPayments: PreparedPayments = []; - - for (let i = 0; i <= values.leasingPeriod; i++) { - preparedPayments[i].numberPayment = i + 1; - preparedPayments[i].percentPayment = - i === 0 ? 0 : tables.tablePayments[i].paymentRelation; - preparedPayments[i].sumPayment[i] = 0; - - if (values.tracker && entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.tracker, - ); - - if (evo_addproduct_type && evo_addproduct_type.evo_planpayments) { - const evo_planpayment = evo_addproduct_type.evo_planpayments.find( - x => x.evo_name === (i + 1).toString(), - ); - if (evo_planpayment) { - preparedPayments[i].gpsBasePayment = - (evo_planpayment.evo_cost_price_telematics_withoutnds || 0) + - (evo_planpayment.evo_cost_equipment_withoutnds || 0); - - preparedPayments[i].gpsCostPayment = - evo_planpayment.evo_cost_telematics_withoutnds || 0; - } - } - - if (values.telematics && entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.telematics, - ); - - if (evo_addproduct_type && evo_addproduct_type.evo_planpayments) { - const evo_planpayment = evo_addproduct_type.evo_planpayments.find( - x => x.evo_name === (i + 1).toString(), - ); - if (evo_planpayment) { - preparedPayments[i].tlmBasePayment = - (evo_planpayment.evo_cost_price_telematics_withoutnds || 0) + - (evo_planpayment.evo_cost_equipment_withoutnds || 0); - - preparedPayments[i].tlmCostPayment = - evo_planpayment.evo_cost_telematics_withoutnds || 0; - } - } - } - } - } - - //@ts-ignore - let preparedValues: PreparedValues = {}; - - preparedValues.calcDate = currentDate; - preparedValues.calcType = 100000000; - preparedValues.irrExpected = (values.IRR_Perc as number) / 100; - preparedValues.npvniExpected = 0; - preparedValues.totalExpected = 0; - preparedValues.nmper = values.leasingPeriod; - preparedValues.leasing0K = - values.product === 'LEASING0' - ? ((preparedValues.nmper as number) - 2) * - (0.0234 / ((1 - 1 / 1.0234) ^ ((preparedValues.nmper as number) - 2))) - : 1; - preparedValues.loanRate = (values.creditRate as number) / 100; - preparedValues.balanceHolder = values.balanceHolder; - preparedValues.dogDate = preparedValues.calcDate; - preparedValues.paymentDateNew = undefined; - preparedValues.deliveryTime = values.deliveryTime; - preparedValues.firstPaymentAbs = undefined; - preparedValues.firstPaymentNdsAbs = undefined; - preparedValues.firstPaymentWithNdsAbs = undefined; - preparedValues.lastPayment = (values.lastPaymentPerc as number) / 100; - preparedValues.lastPaymentSum = - (values.lastPaymentRub as number) / (1 + valuesConstants.VAT); - preparedValues.scheduleOfPayments = values.graphType; - preparedValues.comissionRub = - (values.comissionRub as number) / (1 + valuesConstants.VAT); - preparedValues.plTypeId = values.leaseObjectType; - preparedValues.brandId = values.brand; - preparedValues.modelId = values.model; - preparedValues.configurationId = values.configuration; - preparedValues.plYear = values.leaseObjectYear; - preparedValues.carCapacity = values.leaseObjectMotorPower; - preparedValues.motorVolume = values.engineVolume; - preparedValues.plEngineType = values.engineType; - preparedValues.carCarrying = values.maxMass; - preparedValues.bonus = (values.saleBonus as number) / 100; - preparedValues.bonusFix = 0; - preparedValues.transTax = 0; - preparedValues.transIncludeGr = false; - preparedValues.transportTaxGrYear = 0; - preparedValues.transportTaxGr = 0; - - let insuranceKaskoRow = tables.tableInsurance.find( - x => x.policyType === 'КАСКО', - ); - - let insuranceNSRow = tables.tableInsurance.find(x => x.policyType === 'НС'); - - let insuranceDGORow = tables.tableInsurance.find(x => x.policyType === 'ДГО'); - - let insuranceOSAGORow = tables.tableInsurance.find( - x => x.policyType === 'ОСАГО', - ); - - if ( - insuranceKaskoRow && - insuranceNSRow && - insuranceDGORow && - insuranceOSAGORow - ) { - if (insuranceKaskoRow.insured === 100000001) { - preparedValues.insuranceKasko = - insuranceKaskoRow.insCost + - insuranceDGORow.insCost + - insuranceNSRow.insCost; - } else { - preparedValues.insuranceKasko = 0; - } - } - - if (insuranceKaskoRow) { - preparedValues.nmperInsurance = - insuranceKaskoRow.insTerm === 100000001 ? values.leasingPeriod : 12; - } - - if (insuranceOSAGORow) { - preparedValues.insuranceOsago = - insuranceOSAGORow.insured === 100000001 ? insuranceOSAGORow.insCost : 0; - } - preparedValues.insurance = - preparedValues.insuranceOsago + preparedValues.insuranceKasko; - - preparedValues.insuranceKaskoNmper = - preparedValues.nmperInsurance >= 16 - ? (preparedValues.insuranceKasko * preparedValues.nmperInsurance) / 12 - : preparedValues.insuranceKasko; - - preparedValues.insuranceContract = - preparedValues.insuranceKaskoNmper + preparedValues.insuranceOsago; - - preparedValues.repayment = 25.0; - - if (values.firstPaymentPerc < 30) { - switch (values.graphType) { - case 100000003: - if ( - entities.evo_coefficient_season && - entities.evo_coefficient_season.length > 0 - ) { - const evo_coefficient = entities.evo_coefficient_season.find( - x => - x.evo_season_type === values.seasonType && - x.evo_graph_type === 100000003, - ); - if (evo_coefficient) - preparedValues.firstPayment = - (values.firstPaymentPerc + - evo_coefficient.evo_correction_coefficient) / - 100; - } - - break; - - case 100000004: - if ( - entities.evo_coefficient_season && - entities.evo_coefficient_season.length > 0 - ) { - const evo_coefficient = entities.evo_coefficient_season.find( - x => x.evo_graph_type === 100000004, - ); - if (evo_coefficient) - preparedValues.firstPayment = - (values.firstPaymentPerc + - evo_coefficient.evo_correction_coefficient) / - 100; - } - break; - - //TODO: beautify - default: - preparedValues.firstPayment = values.firstPaymentPerc / 100; - break; - } - } else { - preparedValues.firstPayment = values.firstPaymentPerc / 100; - } - - if (entities.evo_currencychange) { - const evo_currencychange_supplier = entities.evo_currencychange.find( - x => x.transactioncurrencyid === values.supplierCurrency, - ); - - if (evo_currencychange_supplier) { - preparedValues.plPrice = - calcPrice( - evo_currencychange_supplier.isocurrencycode, - values.leaseObjectPrice, - evo_currencychange_supplier.evo_currencychange || 0, - ) / - (1 + valuesConstants.VAT); - - preparedValues.discount = - calcPrice( - evo_currencychange_supplier.isocurrencycode, - values.supplierDiscountRub, - evo_currencychange_supplier.evo_currencychange || 0, - ) / - (1 + valuesConstants.VAT); - } - } - - preparedValues.acceptSum = preparedValues.plPrice - preparedValues.discount; - - preparedValues.firstPaymentSum = - preparedValues.firstPayment * preparedValues.plPrice; - - preparedValues.agentsSum = - (values.indAgentRewardSumm / 100) * - preparedValues.acceptSum * - valuesConstants.ESN; - - preparedValues.doubleAgentsSum = - (values.calcDoubleAgentRewardSumm / 100) * - preparedValues.acceptSum * - valuesConstants.ESN; - - preparedValues.deliverySum = - (values.dealerRewardSumm / 100) * preparedValues.acceptSum; - - preparedValues.brokerSum = - (values.calcBrokerRewardSum / 100) * preparedValues.acceptSum; - - preparedValues.brokerOfDeliverySum = - (values.dealerBrokerRewardSumm / 100) * preparedValues.acceptSum; - - preparedValues.financialDeptOfDeliverySum = - (values.finDepartmentRewardSumm / 100) * preparedValues.acceptSum; - - if (values.importerRewardRub > 0) { - preparedValues.importerSum = values.importerRewardRub; - } else { - preparedValues.importerSum = - (values.importerRewardPerc / 100) * preparedValues.acceptSum; - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'EXTRA_BONUS', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_job_titleid === username && - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.extraBonus = evo_coefficient.evo_sot_coefficient; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'DIRECTOR_BONUS', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.directorBonus = evo_coefficient.evo_sot_coefficient; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'MARKET_RATE', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.marketRate = evo_coefficient.evo_sot_coefficient; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'DISTRICT_RATE', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.districtRate = evo_coefficient.evo_sot_coefficient; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'SALARY_RATE', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.salaryRate = evo_coefficient.evo_sot_coefficient; - } - } - - if (entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.technicalCard, - ); - if (evo_addproduct_type) { - if (evo_addproduct_type.evo_graph_price_withoutnds) - preparedValues.rats = evo_addproduct_type.evo_graph_price_withoutnds; - if (evo_addproduct_type.evo_cost_service_provider_withoutnds) - preparedValues.baseRatCost = - evo_addproduct_type.evo_cost_service_provider_withoutnds; - if (evo_addproduct_type.evo_retro_bonus_withoutnds) - preparedValues.retroBonus = - evo_addproduct_type.evo_retro_bonus_withoutnds; - } else { - preparedValues.rats = 0; - preparedValues.baseRatCost = 0; - preparedValues.retroBonus = 0; - } - } - - if (entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.registration, - ); - if (evo_addproduct_type) { - if (evo_addproduct_type.evo_graph_price_withoutnds) - preparedValues.registration = - evo_addproduct_type.evo_graph_price_withoutnds; - if (evo_addproduct_type.evo_cost_service_provider_withoutnds) - preparedValues.baseRegistration = - evo_addproduct_type.evo_cost_service_provider_withoutnds; - } else { - preparedValues.registration = 0; - preparedValues.baseRegistration = 0; - } - } - - if (entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.tracker, - ); - if (evo_addproduct_type) { - if (evo_addproduct_type.evo_graph_price_withoutnds) - preparedValues.trackerCost = - evo_addproduct_type.evo_graph_price_withoutnds; - } else { - preparedValues.trackerCost = 0; - } - } - - if (entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.telematics, - ); - if (evo_addproduct_type) { - if (evo_addproduct_type.evo_graph_price_withoutnds) - preparedValues.tLMCost = evo_addproduct_type.evo_graph_price_withoutnds; - } else { - preparedValues.tLMCost = 0; - } - } - - const nsibBaseValue = - (preparedValues.plPrice + - (preparedValues.insuranceContract * preparedValues.rats + - preparedValues.registration + - preparedValues.trackerCost + - preparedValues.tLMCost + - preparedValues.transportTaxGr + - preparedPayments.map(x => x.tlmCostPayment).reduce((a, b) => a + b, 0) + - preparedPayments - .map(x => x.gpsCostPayment) - .reduce((a, b) => a + b, 0)) * - preparedValues.leasing0K - - preparedValues.firstPaymentSum - - (values.product === 'LEASING0' ? 0 : preparedValues.discount)) * - (1 + valuesConstants.VAT); - - if (nsibBaseValue > valuesConstants.NSIB_MAX) { - preparedValues.nsibBase = valuesConstants.NSIB_MAX; - } else { - preparedValues.nsibBase = nsibBaseValue; - } - - if (entities.evo_addproduct_type) { - const evo_addproduct_type = entities.evo_addproduct_type.find( - x => x.evo_addproduct_typeid === values.insNSIB, - ); - if (evo_addproduct_type) { - if (evo_addproduct_type.evo_graph_price) - preparedValues.nsibBrutto = - (((evo_addproduct_type.evo_graph_price / 100) * - preparedValues.nsibBase) / - 12) * - preparedValues.nmper; - - if (evo_addproduct_type.evo_prime_cost) - preparedValues.nsibNetto = - (((evo_addproduct_type.evo_prime_cost / 100) * - preparedValues.nsibBase) / - 12) * - preparedValues.nmper; - } else { - preparedValues.nsibBrutto = 0; - preparedValues.nsibNetto = 0; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'BONUS_RAT_PR', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_job_titleid === username && - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.ratBonus = - evo_coefficient.evo_sot_coefficient * preparedValues.rats; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'BONUS_NSIB_PR', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_job_titleid === username && - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if (evo_coefficient && evo_coefficient.evo_sot_coefficient) - preparedValues.ratBonus = - evo_coefficient.evo_sot_coefficient * preparedValues.nsibBrutto; - } - } - - if (entities.evo_sot_coefficient_type) { - const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( - x => x.evo_id === 'BONUS_NS_PR', - ); - if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { - const evo_coefficient = entities.evo_coefficient_bonus.find( - x => - x.evo_job_titleid === username && - x.evo_sot_coefficient_typeid === - evo_sot_coefficient_type.evo_sot_coefficient_typeid, - ); - if ( - evo_coefficient && - evo_coefficient.evo_sot_coefficient && - insuranceNSRow - ) - preparedValues.ratBonus = - evo_coefficient.evo_sot_coefficient * insuranceNSRow.insCost; - } - } - - if (values.insDecentral === true) { - if ( - insuranceDGORow && - insuranceDGORow.insCost && - insuranceNSRow && - insuranceNSRow.insCost - ) { - preparedValues.insuranceBonus = - -1 * - (preparedValues.acceptSum * - valuesConstants.KASKO_PR * - valuesConstants.KASKO_BONUS_PR + - (((insuranceDGORow.insCost + insuranceNSRow.insCost) * - valuesConstants.KASKO_BONUS_PR) / - (1 + valuesConstants.VAT)) * - (preparedValues.insuranceKaskoNmper > 12 && - preparedValues.insuranceKaskoNmper < 16 - ? preparedValues.insuranceKaskoNmper / 12 - : 1)); - } - } else { - preparedValues.insuranceBonus = 0; - } - - preparedValues.cityc = values.townRegistration || values.regionRegistration; - - if ( - entities.evo_tarif && - entities.evo_tarif.length > 0 && - entities.evo_tarif[0].evo_irr_plan - ) { - preparedValues.iRR_MSFO_Plan = entities.evo_tarif[0].evo_irr_plan / 100; - } - - if (entities.evo_coefficient && entities.evo_coefficient.length > 0) { - const evo_coefficient_delta = entities.evo_coefficient.filter( - x => - x.evo_client_risks && - x.evo_client_risks.length > 0 && - x.evo_client_types && - x.evo_client_types.length > 0 && - x.evo_leasingobject_types && - x.evo_leasingobject_types.length > 0, - ); - if ( - evo_coefficient_delta && - evo_coefficient_delta.length > 0 && - evo_coefficient_delta[0].evo_risk_delta - ) { - preparedValues.npvniDelta = evo_coefficient_delta[0].evo_risk_delta; - } else { - preparedValues.npvniDelta = 0; - } - } - - if ( - entities.evo_leasingobject_type && - entities.evo_leasingobject_type.length > 0 && - entities.evo_leasingobject_type[0].evo_id - ) { - let deprecation_rate = 1; - - if ( - (entities.evo_leasingobject_type[0].evo_id === '1' && - (values.engineType === 100000000 || values.engineType === 100000004) && - values.engineVolume <= 3.5) || - (entities.evo_leasingobject_type[0].evo_id === '2' && - (values.engineType === 100000000 || - values.engineType === 100000004 || - values.engineType === 100000001) && - values.maxMass <= 3500) || - (entities.evo_leasingobject_type[0].evo_id !== '1' && - entities.evo_leasingobject_type[0].evo_id !== '2') - ) { - if (entities.evo_leasingobject_type[0].evo_expluatation_period1) - preparedValues.nmperDeprecation = - entities.evo_leasingobject_type[0].evo_expluatation_period1; - if (entities.evo_leasingobject_type[0].evo_depreciation_rate1) - deprecation_rate = - entities.evo_leasingobject_type[0].evo_depreciation_rate1; - } else { - if (entities.evo_leasingobject_type[0].evo_expluatation_period2) - preparedValues.nmperDeprecation = - entities.evo_leasingobject_type[0].evo_expluatation_period2; - if (entities.evo_leasingobject_type[0].evo_depreciation_rate2) - deprecation_rate = - entities.evo_leasingobject_type[0].evo_depreciation_rate2; - } - if ( - preparedValues.nmperDeprecation === 85 || - preparedValues.nmperDeprecation === 61 - ) { - preparedValues.deprecationTime = deprecation_rate * 3; - } else { - preparedValues.deprecationTime = deprecation_rate; - } - } - - const { - plPrice, - insurance, - rats, - registration, - trackerCost, - tLMCost, - transportTaxGr, - leasing0K, - nsibBrutto, - insuranceContract, - comissionRub, - discount, - baseRegistration, - nsibNetto, - nmper, - firstPaymentSum, - } = preparedValues; - - preparedValues.calculationCost = - plPrice + - (insurance + rats + registration + trackerCost + tLMCost + transportTaxGr) * - leasing0K; - - preparedValues.priceUpTotal = - plPrice + - trackerCost + - tLMCost + - preparedPayments.map(x => x.tlmCostPayment).reduce((a, b) => a + b, 0) + - preparedPayments.map(x => x.gpsCostPayment).reduce((a, b) => a + b, 0) + - registration + - insuranceContract + - rats + - nsibBrutto + - transportTaxGr; - - preparedValues.acquisitionExpenses = - plPrice + - insurance - - comissionRub - - discount + - trackerCost + - tLMCost + - baseRegistration + - rats; - - preparedValues.npvBase = - plPrice + - ((nsibNetto * 12) / nmper + - insurance + - baseRegistration + - trackerCost + - tLMCost + - rats - - discount - - comissionRub - - firstPaymentSum); - - preparedValues.niAtInception = - preparedValues.acquisitionExpenses - firstPaymentSum; - - preparedValues.dogCredit = - plPrice + - (insurance + rats + registration + trackerCost + tLMCost + transportTaxGr) * - leasing0K - - firstPaymentSum + - (nsibNetto * 12) / nmper - - (values.product === 'LEASING0' ? 0 : discount); - - preparedValues.dogCreditLeasing = - plPrice + - insurance + - registration + - trackerCost + - tLMCost + - rats - - discount - - comissionRub - - firstPaymentSum; - - return { - preparedPayments, - preparedValues, - }; -}; +// import { IGetCalculationRequest } from 'core/types/Calculation/Requests'; +// import { DateTime } from 'luxon'; +// import { getEntities } from './crmManager'; +// import { PreparedPayments } from 'core/types/Calculation/Prepare'; +// import { calcPrice } from 'client/stores/CalculationStore/Effects/lib/tools'; +// import valuesConstants from 'core/constants/values'; + +// export const prepareCalculationData = ({ +// values, +// tables, +// username, +// }: IGetCalculationRequest): any => { +// const currentDate = DateTime.local().toUTC().toJSDate(); +// const entities = getEntities([ +// { +// entityName: 'evo_coefficient', +// alias: 'evo_coefficient_season', +// where: { +// evo_corfficient_type: 100000000, +// statecode: 0, +// //TODO: +// // evo_datefrom: '<= currentDate', +// // evo_dateto: '>= currentDate', +// // evo_min_period: `<= ${values.leasingPeriod}`, +// // evo_max_period: `>= ${values.leasingPeriod}`, +// }, +// fields: [ +// 'evo_correction_coefficient', +// 'evo_graph_type', +// 'evo_season_type', +// ], +// }, +// { +// alias: 'evo_coefficient_bonus', +// entityName: 'evo_coefficient', +// where: { +// evo_corfficient_type: 100000002, +// statecode: 0, +// //TODO: +// // evo_datefrom: '<= currentDate', +// // evo_dateto: '>= currentDate', +// }, +// fields: [ +// 'evo_job_titleid', +// 'evo_sot_coefficient_typeid', +// 'evo_sot_coefficient', +// ], +// }, +// { +// entityName: 'evo_currencychange', +// where: { +// evo_coursedate: currentDate, +// statecode: 0, +// }, +// fields: ['isocurrencycode', 'evo_currencychange'], +// }, +// { +// entityName: 'evo_sot_coefficient_type', +// where: { +// statecode: 0, +// }, +// fields: ['evo_sot_coefficient_typeid', 'evo_id'], +// }, +// { +// entityName: 'evo_addproduct_type', +// where: { +// statecode: 0, +// //TODO: +// // evo_datefrom: '<= currentDate', +// // evo_dateto: '>= currentDate', +// // evo_min_period: `<= ${values.leasingPeriod}`, +// // evo_max_period: `>= ${values.leasingPeriod}`, +// }, +// fields: [ +// 'evo_addproduct_typeid', +// 'evo_graph_price_withoutnds', +// 'evo_cost_service_provider_withoutnds', +// 'evo_retro_bonus_withoutnds', +// 'evo_prime_cost', +// 'evo_graph_price', +// { +// entityName: 'evo_planpayment', +// fields: [ +// 'evo_name', +// 'evo_cost_equipment_withoutnds', +// 'evo_cost_price_telematics_withoutnds', +// 'evo_cost_telematics_withoutnds', +// ], +// }, +// ], +// }, +// { +// entityName: 'evo_tarif', +// where: { +// evo_tarifid: values.Tarif, +// }, +// fields: ['evo_irr_plan'], +// }, + +// { +// entityName: 'evo_coefficient', +// where: { +// evo_corfficient_type: 100000001, +// statecode: 0, +// //TODO: +// // evo_datefrom: '<= currentDate', +// // evo_dateto: '>= currentDate', +// // evo_min_period: `<= ${values.leasingPeriod}`, +// // evo_max_period: `>= ${values.leasingPeriod}`, +// }, +// fields: [ +// 'evo_risk_delta', +// { +// entityName: 'evo_client_risk', +// where: { +// evo_client_riskid: values.clientRisk, +// }, +// }, +// { +// entityName: 'evo_client_type', +// where: { +// evo_client_typeid: values.clientType, +// }, +// }, +// { +// entityName: 'evo_leasingobject_type', +// where: { +// evo_leasingobject_typeid: values.leaseObjectType, +// }, +// }, +// ], +// }, +// { +// entityName: 'evo_leasingobject_type', +// where: { +// evo_leasingobject_typeid: values.leaseObjectType, +// }, +// fields: [ +// 'evo_id', +// 'evo_expluatation_period1', +// 'evo_expluatation_period2', +// 'evo_depreciation_rate1', +// 'evo_depreciation_rate2', +// ], +// }, +// ]); + +// let preparedPayments: PreparedPayments = []; + +// for (let i = 0; i <= values.leasingPeriod; i++) { +// preparedPayments[i].numberPayment = i + 1; +// preparedPayments[i].percentPayment = +// i === 0 ? 0 : tables.tablePayments[i].paymentRelation; +// preparedPayments[i].sumPayment[i] = 0; + +// if (values.tracker && entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.tracker, +// ); + +// if (evo_addproduct_type && evo_addproduct_type.evo_planpayments) { +// const evo_planpayment = evo_addproduct_type.evo_planpayments.find( +// x => x.evo_name === (i + 1).toString(), +// ); +// if (evo_planpayment) { +// preparedPayments[i].gpsBasePayment = +// (evo_planpayment.evo_cost_price_telematics_withoutnds || 0) + +// (evo_planpayment.evo_cost_equipment_withoutnds || 0); + +// preparedPayments[i].gpsCostPayment = +// evo_planpayment.evo_cost_telematics_withoutnds || 0; +// } +// } + +// if (values.telematics && entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.telematics, +// ); + +// if (evo_addproduct_type && evo_addproduct_type.evo_planpayments) { +// const evo_planpayment = evo_addproduct_type.evo_planpayments.find( +// x => x.evo_name === (i + 1).toString(), +// ); +// if (evo_planpayment) { +// preparedPayments[i].tlmBasePayment = +// (evo_planpayment.evo_cost_price_telematics_withoutnds || 0) + +// (evo_planpayment.evo_cost_equipment_withoutnds || 0); + +// preparedPayments[i].tlmCostPayment = +// evo_planpayment.evo_cost_telematics_withoutnds || 0; +// } +// } +// } +// } +// } + +// //@ts-ignore +// let preparedValues: PreparedValues = {}; + +// preparedValues.calcDate = currentDate; +// preparedValues.calcType = 100000000; +// preparedValues.irrExpected = (values.IRR_Perc as number) / 100; +// preparedValues.npvniExpected = 0; +// preparedValues.totalExpected = 0; +// preparedValues.nmper = values.leasingPeriod; +// preparedValues.leasing0K = +// values.product === 'LEASING0' +// ? ((preparedValues.nmper as number) - 2) * +// (0.0234 / ((1 - 1 / 1.0234) ^ ((preparedValues.nmper as number) - 2))) +// : 1; +// preparedValues.loanRate = (values.creditRate as number) / 100; +// preparedValues.balanceHolder = values.balanceHolder; +// preparedValues.dogDate = preparedValues.calcDate; +// preparedValues.paymentDateNew = undefined; +// preparedValues.deliveryTime = values.deliveryTime; +// preparedValues.firstPaymentAbs = undefined; +// preparedValues.firstPaymentNdsAbs = undefined; +// preparedValues.firstPaymentWithNdsAbs = undefined; +// preparedValues.lastPayment = (values.lastPaymentPerc as number) / 100; +// preparedValues.lastPaymentSum = +// (values.lastPaymentRub as number) / (1 + valuesConstants.VAT); +// preparedValues.scheduleOfPayments = values.graphType; +// preparedValues.comissionRub = +// (values.comissionRub as number) / (1 + valuesConstants.VAT); +// preparedValues.plTypeId = values.leaseObjectType; +// preparedValues.brandId = values.brand; +// preparedValues.modelId = values.model; +// preparedValues.configurationId = values.configuration; +// preparedValues.plYear = values.leaseObjectYear; +// preparedValues.carCapacity = values.leaseObjectMotorPower; +// preparedValues.motorVolume = values.engineVolume; +// preparedValues.plEngineType = values.engineType; +// preparedValues.carCarrying = values.maxMass; +// preparedValues.bonus = (values.saleBonus as number) / 100; +// preparedValues.bonusFix = 0; +// preparedValues.transTax = 0; +// preparedValues.transIncludeGr = false; +// preparedValues.transportTaxGrYear = 0; +// preparedValues.transportTaxGr = 0; + +// let insuranceKaskoRow = tables.tableInsurance.find( +// x => x.policyType === 'КАСКО', +// ); + +// let insuranceNSRow = tables.tableInsurance.find(x => x.policyType === 'НС'); + +// let insuranceDGORow = tables.tableInsurance.find(x => x.policyType === 'ДГО'); + +// let insuranceOSAGORow = tables.tableInsurance.find( +// x => x.policyType === 'ОСАГО', +// ); + +// if ( +// insuranceKaskoRow && +// insuranceNSRow && +// insuranceDGORow && +// insuranceOSAGORow +// ) { +// if (insuranceKaskoRow.insured === 100000001) { +// preparedValues.insuranceKasko = +// insuranceKaskoRow.insCost + +// insuranceDGORow.insCost + +// insuranceNSRow.insCost; +// } else { +// preparedValues.insuranceKasko = 0; +// } +// } + +// if (insuranceKaskoRow) { +// preparedValues.nmperInsurance = +// insuranceKaskoRow.insTerm === 100000001 ? values.leasingPeriod : 12; +// } + +// if (insuranceOSAGORow) { +// preparedValues.insuranceOsago = +// insuranceOSAGORow.insured === 100000001 ? insuranceOSAGORow.insCost : 0; +// } +// preparedValues.insurance = +// preparedValues.insuranceOsago + preparedValues.insuranceKasko; + +// preparedValues.insuranceKaskoNmper = +// preparedValues.nmperInsurance >= 16 +// ? (preparedValues.insuranceKasko * preparedValues.nmperInsurance) / 12 +// : preparedValues.insuranceKasko; + +// preparedValues.insuranceContract = +// preparedValues.insuranceKaskoNmper + preparedValues.insuranceOsago; + +// preparedValues.repayment = 25.0; + +// if (values.firstPaymentPerc < 30) { +// switch (values.graphType) { +// case 100000003: +// if ( +// entities.evo_coefficient_season && +// entities.evo_coefficient_season.length > 0 +// ) { +// const evo_coefficient = entities.evo_coefficient_season.find( +// x => +// x.evo_season_type === values.seasonType && +// x.evo_graph_type === 100000003, +// ); +// if (evo_coefficient) +// preparedValues.firstPayment = +// (values.firstPaymentPerc + +// evo_coefficient.evo_correction_coefficient) / +// 100; +// } + +// break; + +// case 100000004: +// if ( +// entities.evo_coefficient_season && +// entities.evo_coefficient_season.length > 0 +// ) { +// const evo_coefficient = entities.evo_coefficient_season.find( +// x => x.evo_graph_type === 100000004, +// ); +// if (evo_coefficient) +// preparedValues.firstPayment = +// (values.firstPaymentPerc + +// evo_coefficient.evo_correction_coefficient) / +// 100; +// } +// break; + +// //TODO: beautify +// default: +// preparedValues.firstPayment = values.firstPaymentPerc / 100; +// break; +// } +// } else { +// preparedValues.firstPayment = values.firstPaymentPerc / 100; +// } + +// if (entities.evo_currencychange) { +// const evo_currencychange_supplier = entities.evo_currencychange.find( +// x => x.transactioncurrencyid === values.supplierCurrency, +// ); + +// if (evo_currencychange_supplier) { +// preparedValues.plPrice = +// calcPrice( +// evo_currencychange_supplier.isocurrencycode, +// values.leaseObjectPrice, +// evo_currencychange_supplier.evo_currencychange || 0, +// ) / +// (1 + valuesConstants.VAT); + +// preparedValues.discount = +// calcPrice( +// evo_currencychange_supplier.isocurrencycode, +// values.supplierDiscountRub, +// evo_currencychange_supplier.evo_currencychange || 0, +// ) / +// (1 + valuesConstants.VAT); +// } +// } + +// preparedValues.acceptSum = preparedValues.plPrice - preparedValues.discount; + +// preparedValues.firstPaymentSum = +// preparedValues.firstPayment * preparedValues.plPrice; + +// preparedValues.agentsSum = +// (values.indAgentRewardSumm / 100) * +// preparedValues.acceptSum * +// valuesConstants.ESN; + +// preparedValues.doubleAgentsSum = +// (values.calcDoubleAgentRewardSumm / 100) * +// preparedValues.acceptSum * +// valuesConstants.ESN; + +// preparedValues.deliverySum = +// (values.dealerRewardSumm / 100) * preparedValues.acceptSum; + +// preparedValues.brokerSum = +// (values.calcBrokerRewardSum / 100) * preparedValues.acceptSum; + +// preparedValues.brokerOfDeliverySum = +// (values.dealerBrokerRewardSumm / 100) * preparedValues.acceptSum; + +// preparedValues.financialDeptOfDeliverySum = +// (values.finDepartmentRewardSumm / 100) * preparedValues.acceptSum; + +// if (values.importerRewardRub > 0) { +// preparedValues.importerSum = values.importerRewardRub; +// } else { +// preparedValues.importerSum = +// (values.importerRewardPerc / 100) * preparedValues.acceptSum; +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'EXTRA_BONUS', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_job_titleid === username && +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.extraBonus = evo_coefficient.evo_sot_coefficient; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'DIRECTOR_BONUS', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.directorBonus = evo_coefficient.evo_sot_coefficient; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'MARKET_RATE', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.marketRate = evo_coefficient.evo_sot_coefficient; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'DISTRICT_RATE', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.districtRate = evo_coefficient.evo_sot_coefficient; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'SALARY_RATE', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.salaryRate = evo_coefficient.evo_sot_coefficient; +// } +// } + +// if (entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.technicalCard, +// ); +// if (evo_addproduct_type) { +// if (evo_addproduct_type.evo_graph_price_withoutnds) +// preparedValues.rats = evo_addproduct_type.evo_graph_price_withoutnds; +// if (evo_addproduct_type.evo_cost_service_provider_withoutnds) +// preparedValues.baseRatCost = +// evo_addproduct_type.evo_cost_service_provider_withoutnds; +// if (evo_addproduct_type.evo_retro_bonus_withoutnds) +// preparedValues.retroBonus = +// evo_addproduct_type.evo_retro_bonus_withoutnds; +// } else { +// preparedValues.rats = 0; +// preparedValues.baseRatCost = 0; +// preparedValues.retroBonus = 0; +// } +// } + +// if (entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.registration, +// ); +// if (evo_addproduct_type) { +// if (evo_addproduct_type.evo_graph_price_withoutnds) +// preparedValues.registration = +// evo_addproduct_type.evo_graph_price_withoutnds; +// if (evo_addproduct_type.evo_cost_service_provider_withoutnds) +// preparedValues.baseRegistration = +// evo_addproduct_type.evo_cost_service_provider_withoutnds; +// } else { +// preparedValues.registration = 0; +// preparedValues.baseRegistration = 0; +// } +// } + +// if (entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.tracker, +// ); +// if (evo_addproduct_type) { +// if (evo_addproduct_type.evo_graph_price_withoutnds) +// preparedValues.trackerCost = +// evo_addproduct_type.evo_graph_price_withoutnds; +// } else { +// preparedValues.trackerCost = 0; +// } +// } + +// if (entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.telematics, +// ); +// if (evo_addproduct_type) { +// if (evo_addproduct_type.evo_graph_price_withoutnds) +// preparedValues.tLMCost = evo_addproduct_type.evo_graph_price_withoutnds; +// } else { +// preparedValues.tLMCost = 0; +// } +// } + +// const nsibBaseValue = +// (preparedValues.plPrice + +// (preparedValues.insuranceContract * preparedValues.rats + +// preparedValues.registration + +// preparedValues.trackerCost + +// preparedValues.tLMCost + +// preparedValues.transportTaxGr + +// preparedPayments.map(x => x.tlmCostPayment).reduce((a, b) => a + b, 0) + +// preparedPayments +// .map(x => x.gpsCostPayment) +// .reduce((a, b) => a + b, 0)) * +// preparedValues.leasing0K - +// preparedValues.firstPaymentSum - +// (values.product === 'LEASING0' ? 0 : preparedValues.discount)) * +// (1 + valuesConstants.VAT); + +// if (nsibBaseValue > valuesConstants.NSIB_MAX) { +// preparedValues.nsibBase = valuesConstants.NSIB_MAX; +// } else { +// preparedValues.nsibBase = nsibBaseValue; +// } + +// if (entities.evo_addproduct_type) { +// const evo_addproduct_type = entities.evo_addproduct_type.find( +// x => x.evo_addproduct_typeid === values.insNSIB, +// ); +// if (evo_addproduct_type) { +// if (evo_addproduct_type.evo_graph_price) +// preparedValues.nsibBrutto = +// (((evo_addproduct_type.evo_graph_price / 100) * +// preparedValues.nsibBase) / +// 12) * +// preparedValues.nmper; + +// if (evo_addproduct_type.evo_prime_cost) +// preparedValues.nsibNetto = +// (((evo_addproduct_type.evo_prime_cost / 100) * +// preparedValues.nsibBase) / +// 12) * +// preparedValues.nmper; +// } else { +// preparedValues.nsibBrutto = 0; +// preparedValues.nsibNetto = 0; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'BONUS_RAT_PR', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_job_titleid === username && +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.ratBonus = +// evo_coefficient.evo_sot_coefficient * preparedValues.rats; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'BONUS_NSIB_PR', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_job_titleid === username && +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if (evo_coefficient && evo_coefficient.evo_sot_coefficient) +// preparedValues.ratBonus = +// evo_coefficient.evo_sot_coefficient * preparedValues.nsibBrutto; +// } +// } + +// if (entities.evo_sot_coefficient_type) { +// const evo_sot_coefficient_type = entities.evo_sot_coefficient_type.find( +// x => x.evo_id === 'BONUS_NS_PR', +// ); +// if (evo_sot_coefficient_type && entities.evo_coefficient_bonus) { +// const evo_coefficient = entities.evo_coefficient_bonus.find( +// x => +// x.evo_job_titleid === username && +// x.evo_sot_coefficient_typeid === +// evo_sot_coefficient_type.evo_sot_coefficient_typeid, +// ); +// if ( +// evo_coefficient && +// evo_coefficient.evo_sot_coefficient && +// insuranceNSRow +// ) +// preparedValues.ratBonus = +// evo_coefficient.evo_sot_coefficient * insuranceNSRow.insCost; +// } +// } + +// if (values.insDecentral === true) { +// if ( +// insuranceDGORow && +// insuranceDGORow.insCost && +// insuranceNSRow && +// insuranceNSRow.insCost +// ) { +// preparedValues.insuranceBonus = +// -1 * +// (preparedValues.acceptSum * +// valuesConstants.KASKO_PR * +// valuesConstants.KASKO_BONUS_PR + +// (((insuranceDGORow.insCost + insuranceNSRow.insCost) * +// valuesConstants.KASKO_BONUS_PR) / +// (1 + valuesConstants.VAT)) * +// (preparedValues.insuranceKaskoNmper > 12 && +// preparedValues.insuranceKaskoNmper < 16 +// ? preparedValues.insuranceKaskoNmper / 12 +// : 1)); +// } +// } else { +// preparedValues.insuranceBonus = 0; +// } + +// preparedValues.cityc = values.townRegistration || values.regionRegistration; + +// if ( +// entities.evo_tarif && +// entities.evo_tarif.length > 0 && +// entities.evo_tarif[0].evo_irr_plan +// ) { +// preparedValues.iRR_MSFO_Plan = entities.evo_tarif[0].evo_irr_plan / 100; +// } + +// if (entities.evo_coefficient && entities.evo_coefficient.length > 0) { +// const evo_coefficient_delta = entities.evo_coefficient.filter( +// x => +// x.evo_client_risks && +// x.evo_client_risks.length > 0 && +// x.evo_client_types && +// x.evo_client_types.length > 0 && +// x.evo_leasingobject_types && +// x.evo_leasingobject_types.length > 0, +// ); +// if ( +// evo_coefficient_delta && +// evo_coefficient_delta.length > 0 && +// evo_coefficient_delta[0].evo_risk_delta +// ) { +// preparedValues.npvniDelta = evo_coefficient_delta[0].evo_risk_delta; +// } else { +// preparedValues.npvniDelta = 0; +// } +// } + +// if ( +// entities.evo_leasingobject_type && +// entities.evo_leasingobject_type.length > 0 && +// entities.evo_leasingobject_type[0].evo_id +// ) { +// let deprecation_rate = 1; + +// if ( +// (entities.evo_leasingobject_type[0].evo_id === '1' && +// (values.engineType === 100000000 || values.engineType === 100000004) && +// values.engineVolume <= 3.5) || +// (entities.evo_leasingobject_type[0].evo_id === '2' && +// (values.engineType === 100000000 || +// values.engineType === 100000004 || +// values.engineType === 100000001) && +// values.maxMass <= 3500) || +// (entities.evo_leasingobject_type[0].evo_id !== '1' && +// entities.evo_leasingobject_type[0].evo_id !== '2') +// ) { +// if (entities.evo_leasingobject_type[0].evo_expluatation_period1) +// preparedValues.nmperDeprecation = +// entities.evo_leasingobject_type[0].evo_expluatation_period1; +// if (entities.evo_leasingobject_type[0].evo_depreciation_rate1) +// deprecation_rate = +// entities.evo_leasingobject_type[0].evo_depreciation_rate1; +// } else { +// if (entities.evo_leasingobject_type[0].evo_expluatation_period2) +// preparedValues.nmperDeprecation = +// entities.evo_leasingobject_type[0].evo_expluatation_period2; +// if (entities.evo_leasingobject_type[0].evo_depreciation_rate2) +// deprecation_rate = +// entities.evo_leasingobject_type[0].evo_depreciation_rate2; +// } +// if ( +// preparedValues.nmperDeprecation === 85 || +// preparedValues.nmperDeprecation === 61 +// ) { +// preparedValues.deprecationTime = deprecation_rate * 3; +// } else { +// preparedValues.deprecationTime = deprecation_rate; +// } +// } + +// const { +// plPrice, +// insurance, +// rats, +// registration, +// trackerCost, +// tLMCost, +// transportTaxGr, +// leasing0K, +// nsibBrutto, +// insuranceContract, +// comissionRub, +// discount, +// baseRegistration, +// nsibNetto, +// nmper, +// firstPaymentSum, +// } = preparedValues; + +// preparedValues.calculationCost = +// plPrice + +// (insurance + rats + registration + trackerCost + tLMCost + transportTaxGr) * +// leasing0K; + +// preparedValues.priceUpTotal = +// plPrice + +// trackerCost + +// tLMCost + +// preparedPayments.map(x => x.tlmCostPayment).reduce((a, b) => a + b, 0) + +// preparedPayments.map(x => x.gpsCostPayment).reduce((a, b) => a + b, 0) + +// registration + +// insuranceContract + +// rats + +// nsibBrutto + +// transportTaxGr; + +// preparedValues.acquisitionExpenses = +// plPrice + +// insurance - +// comissionRub - +// discount + +// trackerCost + +// tLMCost + +// baseRegistration + +// rats; + +// preparedValues.npvBase = +// plPrice + +// ((nsibNetto * 12) / nmper + +// insurance + +// baseRegistration + +// trackerCost + +// tLMCost + +// rats - +// discount - +// comissionRub - +// firstPaymentSum); + +// preparedValues.niAtInception = +// preparedValues.acquisitionExpenses - firstPaymentSum; + +// preparedValues.dogCredit = +// plPrice + +// (insurance + rats + registration + trackerCost + tLMCost + transportTaxGr) * +// leasing0K - +// firstPaymentSum + +// (nsibNetto * 12) / nmper - +// (values.product === 'LEASING0' ? 0 : discount); + +// preparedValues.dogCreditLeasing = +// plPrice + +// insurance + +// registration + +// trackerCost + +// tLMCost + +// rats - +// discount - +// comissionRub - +// firstPaymentSum; + +// return { +// preparedPayments, +// preparedValues, +// }; +// }; + +export {};