diff --git a/package.json b/package.json index d13b844..661e0da 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "cross-fetch": "^3.0.6", "express": "^4.17.1", "express-http-proxy": "^1.6.2", + "express-ntlm": "^2.5.2", "graphql": "^15.4.0", "helmet": "^4.1.0", "http-errors": "^1.8.0", @@ -69,7 +70,7 @@ "agentkeepalive": "^4.1.3", "dotenv": "^8.2.0", "faker": "^5.1.0", - "http-proxy-middleware": "^1.0.5", + "http-proxy-middleware": "^1.0.6", "rimraf": "^3.0.2", "webpack-cli": "^4.0.0", "webpack-node-externals": "^2.5.1" diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index 328fbf1..727e133 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -1418,8 +1418,8 @@ const sections: ISections[] = [ title: 'Телематика', Component: Select, props: { - name: 'selectTelematics', - valueName: 'telematics', + name: 'selectTelematic', + valueName: 'telematic', }, }, { diff --git a/src/client/Containers/Calculation/index.jsx b/src/client/Containers/Calculation/index.jsx index 42d1754..95e4d4d 100644 --- a/src/client/Containers/Calculation/index.jsx +++ b/src/client/Containers/Calculation/index.jsx @@ -11,71 +11,130 @@ import Modal from 'client/Elements/Modal'; import Results from './Results'; import Sections from './Sections'; import { gql } from '@apollo/client'; +import { currentDate } from 'client/common/constants'; +import { getUser } from 'client/tools/user'; const Calculation = () => { const [status, setStatus] = useState(LoadingStatus.loading); const { calculationStore } = useStores(); //TODO: move to external file useEffect(() => { - Promise.all([ - CalculationService.getEntities({ - queries: initialOptions, - }), - CalculationService.crmgqlquery({ - query: gql` - query($statecode: Int) { - evo_impairment_group: evo_impairment_groups(statecode: $statecode) { - evo_impairment_groupid - evo_name + getUser().then(({ UserName, DomainName }) => { + Promise.all([ + CalculationService.getEntities({ + queries: initialOptions, + }), + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $currentDate: DateTime, $username: String) { + evo_impairment_group: evo_impairment_groups( + statecode: $statecode + ) { + evo_impairment_groupid + evo_name + } + evo_currencychange: evo_currencychanges( + statecode: $statecode + evo_coursedate_param: { eq: $currentDate } + ) { + evo_currencychange + evo_ref_transactioncurrency + } + evo_coefficient: evo_coefficients( + statecode: $statecode + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + ) { + evo_correction_coefficient + evo_graph_type + evo_season_type + evo_job_titleid + evo_sot_coefficient_typeid + evo_sot_coefficient + evo_corfficient_type + evo_min_period + evo_max_period + evo_graph_type + evo_season_type + evo_correction_coefficient + evo_client_riskid + evo_client_typeid + evo_risk_delta + evo_leasingobject_types { + evo_name + evo_id + evo_leasingobject_typeid + } + } + evo_sot_coefficient_type: evo_sot_coefficient_types( + statecode: $statecode + ) { + evo_id + evo_name + evo_sot_coefficient_typeid + } + systemuser(domainname: $username) { + evo_job_titleid + businessunitid + firstname + lastname + fullname + } + evo_job_title: evo_job_titles(statecode: $statecode) { + evo_id + evo_name + evo_job_titleid + } } - evo_currencychange: evo_currencychanges(statecode: $statecode) { - evo_currencychange - evo_ref_transactioncurrency - } - } - `, - variables: { statecode: 0 }, - }), - CalculationService.getEntities({ - queries: [ - { - alias: 'insuranceCompany', - entityName: 'account', - where: { evo_account_type: 100000002, statecode: 0 }, - fields: ['accountid', 'name', 'evo_type_ins_policy'], - many: true, + `, + variables: { + statecode: 0, + currentDate, + username: `${DomainName}\\${UserName}`, }, - ], - }), - ]) - .then( - ([ - { entities: initialOptions }, - { entities: staticEntities }, - { entities: insuranceCompanies }, - ]) => { - calculationStore.applyOptions(initialOptions); - calculationStore.applyStaticData(staticEntities); - 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, - ); + }), + CalculationService.getEntities({ + queries: [ + { + alias: 'insuranceCompany', + entityName: 'account', + where: { evo_account_type: 100000002, statecode: 0 }, + fields: ['accountid', 'name', 'evo_type_ins_policy'], + many: true, + }, + ], + }), + ]) + .then( + ([ + { entities: initialOptions }, + { entities: staticEntities }, + { entities: insuranceCompanies }, + ]) => { + calculationStore.applyOptions(initialOptions); + calculationStore.applyStaticData(staticEntities); + calculationStore.setTableColumns('tableInsurance')({ + options: { ...insuranceCompanies }, + }); - setStatus(LoadingStatus.ready); - }, - ) - .catch(err => { - setStatus(LoadingStatus.error); - throw err; - }); + //TODO: move to external file + var supplierCurrency = calculationStore.options.selectSupplierCurrency.find( + x => x.isocurrencycode === 'RUB', + ); + calculationStore.setValue( + 'supplierCurrency', + supplierCurrency.transactioncurrencyid, + ); + + setStatus(LoadingStatus.ready); + }, + ) + .catch(err => { + setStatus(LoadingStatus.error); + throw err; + }); + }); + //TODO: makes 2 requests, need 1 }, []); if (status === LoadingStatus.loading) { diff --git a/src/client/services/CalculationService.ts b/src/client/services/CalculationService.ts index f712018..e916670 100644 --- a/src/client/services/CalculationService.ts +++ b/src/client/services/CalculationService.ts @@ -1,4 +1,5 @@ import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client'; +import axios from 'axios'; import { API_HOSTNAME } from 'client/common/constants'; import { CRM_GRAPHQL_PROXY_URL, CRM_GRAPHQL_URL } from 'core/constants/urls'; import { convertEntityToOption } from 'core/tools/entities'; @@ -7,15 +8,19 @@ import { IGetEntitiesRequest, IRequestToCRMGQL, } from 'core/types/Calculation/Requests'; -import { IGetEntitiesResponse } from 'core/types/Calculation/Responses'; +import { + IGetEntitiesResponse, + IGetUserResponse, +} from 'core/types/Calculation/Responses'; import { IBaseOption } from 'core/types/Calculation/Store/options'; import { TCRMEntity } from 'core/types/Entities/crmEntities'; -import { TEntities, CRMEntityNames } from 'core/types/Entities/crmEntityNames'; +import { TEntities } from 'core/types/Entities/crmEntityNames'; import { isPlural, singular } from 'pluralize'; const client = new ApolloClient({ uri: CRM_GRAPHQL_URL, cache: new InMemoryCache(), + link: new HttpLink({ uri: process.env.NODE_ENV !== 'development' @@ -25,8 +30,8 @@ const client = new ApolloClient({ '/proxy', CRM_GRAPHQL_PROXY_URL, ), - fetch, }), + defaultOptions: { query: { fetchPolicy: 'no-cache', @@ -36,6 +41,14 @@ const client = new ApolloClient({ }); class CalculationService { + static getUser = (): Promise => + new Promise((resolve, reject) => { + axios.get('/api/users/getUser').then(res => { + console.log('User', res.data); + resolve(res.data); + }); + }); + static crmgqlquery = ({ query, toOptions, @@ -60,8 +73,9 @@ class CalculationService { resEntities[targetName]; if (toOptions) - //@ts-ignore if (toOptions.includes(targetName)) { + //@ts-ignore + //@ts-ignore if (Array.isArray(targetEnt)) { let optionatedEntities: (TCRMEntity & IBaseOption)[] = []; for (let entity of targetEnt) { @@ -76,9 +90,7 @@ class CalculationService { //@ts-ignore resEntities[ //@ts-ignore - isPlural(targetName) - ? singular(targetName) - : targetName + isPlural(targetName) ? singular(targetName) : targetName ] = optionatedEntities; } else { const entityOption = convertEntityToOption( @@ -116,6 +128,7 @@ class CalculationService { }); const convertedQuery = convertJSONToGQLQuery(queries); + console.log('CalculationService -> convertedQuery', convertedQuery); await client .query({ query: gql` diff --git a/src/client/services/prepareData.ts b/src/client/services/prepareData.ts index ccd6029..1008b28 100644 --- a/src/client/services/prepareData.ts +++ b/src/client/services/prepareData.ts @@ -1,818 +1,707 @@ -// 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 {}; +import { calcPrice } from 'client/stores/CalculationStore/Effects/lib/tools'; +import valuesConstants from 'core/constants/values'; +import { + PreparedPayments, + PreparedValues, +} from 'core/types/Calculation/Prepare'; +import { IGetCalculationRequest } from 'core/types/Calculation/Requests'; +import { DateTime } from 'luxon'; + +export const prepareCalculationData = ({ + calculationStore, + username, +}: IGetCalculationRequest): any => { + const currentDate = DateTime.local().toUTC().toJSDate(); + + let preparedPayments: PreparedPayments = []; + + const { values, options, tables } = calculationStore; + + const tracker = options.selectTracker?.find(x => x.evo_id === values.tracker); + + const telematic = options.selectTelematic?.find( + x => x.evo_id === values.telematics, + ); + + for (let i = 0; i <= values.leasingPeriod; i++) { + preparedPayments[i].numberPayment = i + 1; + preparedPayments[i].percentPayment = + i === 0 ? 0 : tables.tablePayments.rows[i].paymentRelation?.value; + preparedPayments[i].sumPayment = 0; + + if (tracker) { + if (tracker.evo_planpayments && tracker.evo_planpayments.length > 0) { + const evo_planpayment = tracker.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 (telematic) { + if (telematic.evo_planpayments && telematic.evo_planpayments.length > 0) { + const evo_planpayment = telematic.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; + } + } + } + } + + 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.rows.find( + x => x.policyType === 'КАСКО', + ); + + let insuranceNSRow = tables.tableInsurance.rows.find( + x => x.policyType === 'НС', + ); + + let insuranceDGORow = tables.tableInsurance.rows.find( + x => x.policyType === 'ДГО', + ); + + let insuranceOSAGORow = tables.tableInsurance.rows.find( + x => x.policyType === 'ОСАГО', + ); + + if (insuranceKaskoRow?.insured === 100000001) { + preparedValues.insuranceKasko = + insuranceKaskoRow?.insCost?.value + + insuranceDGORow?.insCost?.value + + insuranceNSRow?.insCost?.value; + } else { + preparedValues.insuranceKasko = 0; + } + + preparedValues.nmperInsurance = + insuranceKaskoRow?.insTerm === 100000001 ? values.leasingPeriod : 12; + + preparedValues.insuranceOsago = + insuranceOSAGORow?.insured === 100000001 + ? insuranceOSAGORow?.insCost?.value + : 0; + + preparedValues.insurance = + (preparedValues.insuranceOsago || 0) + (preparedValues.insuranceKasko || 0); + + preparedValues.insuranceKaskoNmper = + preparedValues.nmperInsurance || 0 >= 16 + ? (preparedValues.insuranceKasko || + 0 * (preparedValues.nmperInsurance || 0)) / 12 + : preparedValues.insuranceKasko; + + preparedValues.insuranceContract = + (preparedValues.insuranceKaskoNmper || 0) + + (preparedValues.insuranceOsago || 0); + + preparedValues.repayment = 25.0; + + if (values.firstPaymentPerc < 30) { + const evo_coefficient_season = calculationStore + .getStaticData('evo_coefficient') + .filter( + x => + x.evo_corfficient_type === 100000000 && + x.evo_min_period && + x.evo_min_period <= values.leasingPeriod && + x.evo_max_period && + x.evo_max_period >= values.leasingPeriod, + ); + switch (values.graphType) { + case 100000003: + if (evo_coefficient_season && evo_coefficient_season.length > 0) { + const evo_coefficient = 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 (evo_coefficient_season && evo_coefficient_season.length > 0) { + const evo_coefficient = 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 (values.supplierCurrency === 'RUB') { + preparedValues.plPrice = + values.leaseObjectPrice / (1 + valuesConstants.VAT); + preparedValues.discount = + values.supplierDiscountRub / (1 + valuesConstants.VAT); + } else { + const evo_currencychanges = calculationStore.getStaticData( + 'evo_currencychange', + ); + + if (evo_currencychanges && evo_currencychanges.length > 0) { + const evo_currencychange_supplier = evo_currencychanges.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 || 0) - (preparedValues.discount || 0); + + preparedValues.firstPaymentSum = + (preparedValues.firstPayment || 0) * (preparedValues.plPrice || 0); + + 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; + } + + const evo_coefficient_bonuses = calculationStore + .getStaticData('evo_coefficient') + .filter( + x => + x.evo_corfficient_type === 100000002 && + x.evo_sot_coefficient_typeid && + x.evo_job_titleid, + ); + const systemuser = calculationStore.getStaticData('systemuser'); + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'EXTRA_BONUS'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_job_titleid === systemuser[0].evo_job_titleid && + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.extraBonus = evo_coefficient.evo_sot_coefficient || 0; + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'DIRECTOR_BONUS'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.directorBonus = evo_coefficient.evo_sot_coefficient || 0; + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'MARKET_RATE'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.marketRate = evo_coefficient.evo_sot_coefficient || 0; + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'DISTRICT_RATE'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.districtRate = evo_coefficient.evo_sot_coefficient || 0; + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'SALARY_RATE'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.salaryRate = evo_coefficient.evo_sot_coefficient || 0; + } + } + + const technicalCard = options.selectTechnicalCard?.find( + x => x.evo_id === values.technicalCard, + ); + + if (technicalCard) { + preparedValues.rats = technicalCard.evo_graph_price_withoutnds || 0; + preparedValues.baseRatCost = + technicalCard.evo_cost_service_provider_withoutnds || 0; + preparedValues.retroBonus = technicalCard.evo_retro_bonus_withoutnds || 0; + } + + const selectedRegistration = options.selectRegistration?.find( + x => x.evo_id === values.registration, + ); + + if (selectedRegistration) { + preparedValues.registration = + selectedRegistration.evo_graph_price_withoutnds || 0; + preparedValues.baseRegistration = + selectedRegistration.evo_cost_service_provider_withoutnds || 0; + } + + if (tracker) { + preparedValues.trackerCost = tracker.evo_graph_price_withoutnds || 0; + } + + if (telematic) { + preparedValues.tLMCost = telematic.evo_graph_price_withoutnds || 0; + } + + const nsibBaseValue = + ((preparedValues.plPrice || 0) + + (preparedValues.insuranceContract * (preparedValues.rats || 0) + + (preparedValues.registration || 0) + + (preparedValues.trackerCost || 0) + + (preparedValues.tLMCost || 0) + + preparedValues.transportTaxGr + + preparedPayments + .map(x => x.tlmCostPayment || 0) + .reduce((a, b) => a + b, 0) + + preparedPayments + .map(x => x.gpsCostPayment || 0) + .reduce((a, b) => a + b, 0)) * + preparedValues.leasing0K - + preparedValues.firstPaymentSum - + (values.product === 'LEASING0' ? 0 : preparedValues.discount || 0)) * + (1 + valuesConstants.VAT); + + if (nsibBaseValue > valuesConstants.NSIB_MAX) { + preparedValues.nsibBase = valuesConstants.NSIB_MAX; + } else { + preparedValues.nsibBase = nsibBaseValue; + } + + const selectedInsNSIB = options.selectInsNSIB?.find( + x => x.evo_id === values.insNSIB, + ); + + if (selectedInsNSIB) { + preparedValues.nsibBrutto = + (((selectedInsNSIB.evo_graph_price || 0 / 100) * + preparedValues.nsibBase) / + 12) * + (preparedValues.nmper || 0); + + preparedValues.nsibNetto = + (((selectedInsNSIB.evo_prime_cost || 0 / 100) * preparedValues.nsibBase) / + 12) * + (preparedValues.nmper || 0); + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'BONUS_RAT_PR'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_job_titleid === systemuser[0].evo_job_titleid && + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.ratBonus = + evo_coefficient.evo_sot_coefficient || 0 * (preparedValues.rats || 0); + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'BONUS_NSIB_PR'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_job_titleid === systemuser[0].evo_job_titleid && + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.nsibBonus = + evo_coefficient.evo_sot_coefficient || + 0 * (preparedValues.nsibBrutto || 0); + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = calculationStore + .getStaticData('evo_sot_coefficient_type') + .find(x => x.evo_id === 'BONUS_NS_PR'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_job_titleid === systemuser[0].evo_job_titleid && + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.nsBonus = + evo_coefficient.evo_sot_coefficient || + 0 * insuranceNSRow?.insCost?.value; + } + } + + 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.value + insuranceNSRow.insCost) * + valuesConstants.KASKO_BONUS_PR) / + (1 + valuesConstants.VAT)) * + ((preparedValues.insuranceKaskoNmper || 0) > 12 && + (preparedValues.insuranceKaskoNmper || 0) < 16 + ? (preparedValues.insuranceKaskoNmper || 0) / 12 + : 1)); + } + } else { + preparedValues.insuranceBonus = 0; + } + + preparedValues.cityc = values.townRegistration || values.regionRegistration; + + const tarif = options.selectTarif?.find(x => x.evo_id === values.tarif); + if (tarif) { + preparedValues.iRR_MSFO_Plan = (tarif.evo_irr_plan || 0) / 100; + } + + const evo_coefficient_risk = calculationStore + .getStaticData('evo_coefficient') + ?.find( + x => + x.evo_corfficient_type === 100000001 && + x.evo_min_period && + x.evo_min_period <= values.leasingPeriod && + x.evo_max_period && + x.evo_max_period >= values.leasingPeriod && + x.evo_client_riskid === values.clientRisk && + x.evo_client_typeid === values.clientType && + x.evo_leasingobject_types && + x.evo_leasingobject_types.length > 0 && + x.evo_leasingobject_types.filter( + z => z.evo_leasingobject_typeid === values.leaseObjectType, + ).length > 0, + ); + + if (evo_coefficient_risk) + preparedValues.npvniDelta = evo_coefficient_risk.evo_risk_delta || 0; + + const evo_leasingobject_type = options.selectLeaseObjectType?.find( + x => x.evo_leasingobject_typeid === values.leaseObjectType, + ); + + if (evo_leasingobject_type && evo_leasingobject_type.evo_id) { + let deprecation_rate = 1; + + if ( + (evo_leasingobject_type.evo_id === '1' && + (values.engineType === 100000000 || values.engineType === 100000004) && + values.engineVolume <= 3.5) || + (evo_leasingobject_type.evo_id === '2' && + (values.engineType === 100000000 || + values.engineType === 100000004 || + values.engineType === 100000001) && + values.maxMass <= 3500) || + (evo_leasingobject_type.evo_id !== '1' && + evo_leasingobject_type.evo_id !== '2') + ) { + if (evo_leasingobject_type.evo_expluatation_period1) + preparedValues.nmperDeprecation = + evo_leasingobject_type.evo_expluatation_period1; + if (evo_leasingobject_type.evo_depreciation_rate1) + deprecation_rate = evo_leasingobject_type.evo_depreciation_rate1; + } else { + if (evo_leasingobject_type.evo_expluatation_period2) + preparedValues.nmperDeprecation = + evo_leasingobject_type.evo_expluatation_period2; + if (evo_leasingobject_type.evo_depreciation_rate2) + deprecation_rate = evo_leasingobject_type.evo_depreciation_rate2; + } + if ( + preparedValues.nmperDeprecation === 85 || + preparedValues.nmperDeprecation === 61 + ) { + preparedValues.deprecationTime = deprecation_rate * 3; + } else { + preparedValues.deprecationTime = deprecation_rate; + } + } + + const { + plPrice = 0, + insurance, + rats = 0, + registration = 0, + trackerCost = 0, + tLMCost = 0, + transportTaxGr, + leasing0K, + nsibBrutto = 0, + insuranceContract, + comissionRub, + discount = 0, + baseRegistration = 0, + nsibNetto = 0, + nmper = 0, + firstPaymentSum, + } = preparedValues; + + preparedValues.calculationCost = + plPrice + + (insurance + rats + registration + trackerCost + tLMCost + transportTaxGr) * + leasing0K; + + preparedValues.priceUpTotal = + plPrice + + trackerCost + + tLMCost + + preparedPayments + .map(x => x.tlmCostPayment || 0) + .reduce((a, b) => a + b, 0) + + preparedPayments + .map(x => x.gpsCostPayment || 0) + .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, + }; +}; diff --git a/src/client/tools/user.ts b/src/client/tools/user.ts new file mode 100644 index 0000000..7c96f67 --- /dev/null +++ b/src/client/tools/user.ts @@ -0,0 +1,22 @@ +import CalculationService from 'client/services/CalculationService'; +import { User } from 'core/types/user'; + +export const getUser = async (): Promise => { + if (process.env.NODE_ENV === 'development') { + const savedUser = localStorage.getItem('user'); + if (savedUser) { + const user = JSON.parse(savedUser); + if (user.UserName) { + return user; + } + } + var username = prompt('Enter username'); + const user: User = { UserName: username || '', DomainName: 'EVOLEASING' }; + localStorage.setItem('user', JSON.stringify(user)); + return user; + } + + const { user } = await CalculationService.getUser(); + localStorage.setItem('user', JSON.stringify(user)); + return user; +}; diff --git a/src/core/Data/initialOptions.ts b/src/core/Data/initialOptions.ts index 4af6d25..927c9c7 100644 --- a/src/core/Data/initialOptions.ts +++ b/src/core/Data/initialOptions.ts @@ -204,6 +204,225 @@ const initialOptions: TEntityQuery[] = [ many: true, toOption: true, }, + { + alias: 'selectTracker', + entityName: 'evo_addproduct_type', + where: { + statecode: 0, + evo_product_type: 100000003, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: [ + 'evo_id', + 'evo_addproduct_typeid', + 'evo_name', + 'evo_min_period', + 'evo_max_period', + 'evo_controls_program', + 'evo_accountid', + 'evo_graph_price_withoutnds', + 'evo_cost_service_provider_withoutnds', + 'evo_retro_bonus_withoutnds', + 'evo_prime_cost', + 'evo_graph_price', + ], + relatedEntities: [ + { + entityName: 'evo_planpayment', + fields: [ + 'evo_name', + 'evo_cost_equipment_withoutnds', + 'evo_cost_price_telematics_withoutnds', + 'evo_cost_telematics_withoutnds', + ], + many: true, + }, + ], + many: true, + toOption: true, + }, + { + alias: 'selectTelematic', + entityName: 'evo_addproduct_type', + where: { + statecode: 0, + evo_product_type: 100000004, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: [ + 'evo_id', + 'evo_addproduct_typeid', + 'evo_name', + 'evo_min_period', + 'evo_max_period', + 'evo_controls_program', + 'evo_accountid', + 'evo_graph_price_withoutnds', + 'evo_cost_service_provider_withoutnds', + 'evo_retro_bonus_withoutnds', + 'evo_prime_cost', + 'evo_graph_price', + ], + relatedEntities: [ + { + entityName: 'evo_planpayment', + fields: [ + 'evo_name', + 'evo_cost_equipment_withoutnds', + 'evo_cost_price_telematics_withoutnds', + 'evo_cost_telematics_withoutnds', + ], + many: true, + }, + ], + many: true, + toOption: true, + }, + { + alias: 'selectTechnicalCard', + entityName: 'evo_addproduct_type', + where: { + statecode: 0, + evo_product_type: 100000000, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: [ + 'evo_id', + 'evo_addproduct_typeid', + 'evo_name', + 'evo_min_period', + 'evo_max_period', + 'evo_controls_program', + 'evo_accountid', + 'evo_graph_price_withoutnds', + 'evo_cost_service_provider_withoutnds', + 'evo_retro_bonus_withoutnds', + 'evo_prime_cost', + 'evo_graph_price', + ], + many: true, + toOption: true, + }, + { + alias: 'selectTarif', + entityName: 'evo_tarif', + where: { + statecode: 0, + }, + whereCmp: { + evo_datefrom_param: { + lte: currentDate, + }, + evo_dateto_param: { + gte: currentDate, + }, + }, + fields: [ + 'evo_id', + 'evo_name', + 'evo_tarifid', + 'evo_baseproductid', + 'evo_irr', + 'evo_max_irr', + 'evo_min_profit', + 'evo_min_irr', + 'evo_irr_plan', + 'evo_ins_type', + ], + relatedEntities: [ + { + entityName: 'evo_client_risk', + fields: ['evo_client_riskid', 'evo_name'], + many: true, + }, + { + entityName: 'evo_client_type', + fields: ['evo_client_typeid', 'evo_name'], + many: true, + }, + { + entityName: 'evo_leasingobject_type', + fields: ['evo_leasingobject_typeid', 'evo_name', 'evo_id'], + many: true, + }, + ], + many: true, + toOption: true, + }, + { + alias: 'selectRate', + entityName: 'evo_rate', + where: { + statecode: 0, + }, + //TODO: + // whereCmp: { + // evo_datefrom_param: { + // lte: currentDate, + // }, + // evo_dateto_param: { + // gte: currentDate, + // }, + // }, + fields: [ + 'evo_id', + 'evo_rateid', + 'evo_name', + 'evo_base_rate', + 'evo_coeff_12_23', + 'evo_coeff_24_35', + 'evo_coeff_36_47', + 'evo_coeff_7_11', + 'evo_coeff_48_60', + ], + relatedEntities: [ + { + entityName: 'evo_tarif', + fields: ['evo_tarifid', 'evo_name'], + many: true, + }, + ], + many: true, + toOption: true, + }, + { + alias: 'selectLeaseObjectType', + entityName: 'evo_leasingobject_type', + where: { statecode: 0 }, + fields: [ + 'evo_name', + 'evo_id', + 'evo_leasingobject_typeid', + 'evo_depreciation_rate1', + 'evo_depreciation_rate2', + 'evo_expluatation_period1', + 'evo_expluatation_period2', + 'evo_type_code', + ], + many: true, + toOption: true, + }, ]; export default initialOptions; diff --git a/src/core/Data/propsMap.ts b/src/core/Data/propsMap.ts index 9ce1d33..5d7abe1 100644 --- a/src/core/Data/propsMap.ts +++ b/src/core/Data/propsMap.ts @@ -101,6 +101,14 @@ const propsMap: TEntities<{ name: 'evo_name', value: 'evo_planpaymentid', }, + evo_tarif: { + name: 'evo_name', + value: 'evo_tarifid', + }, + evo_rate: { + name: 'evo_name', + value: 'evo_rateid', + }, }; export default propsMap; diff --git a/src/core/types/Calculation/Prepare.ts b/src/core/types/Calculation/Prepare.ts index 1a75ed3..62b9e77 100644 --- a/src/core/types/Calculation/Prepare.ts +++ b/src/core/types/Calculation/Prepare.ts @@ -1,105 +1,105 @@ import { CRMEntityNames } from '../Entities/crmEntityNames'; export interface PreparedValues { - calcDate: Date; - calcType: number; - irrExpected: number; - npvniExpected: number; - totalExpected: number; - leasing0K: number; - loanRate: number; - balanceHolder: number; - dogDate: Date; + calcDate?: Date; + calcType?: number; + irrExpected?: number; + npvniExpected?: number; + totalExpected?: number; + leasing0K?: number; + loanRate?: number; + balanceHolder?: number; + dogDate?: Date; paymentDateNew?: Date; - deliveryTime: number; - cityc: string; - nmper: number; - firstPayment: number; - firstPaymentSum: number; + deliveryTime?: number; + cityc?: string; + nmper?: number; + firstPayment?: number; + firstPaymentSum?: number; firstPaymentAbs?: number; firstPaymentNdsAbs?: number; firstPaymentWithNdsAbs?: number; - lastPayment: number; - lastPaymentSum: number; - scheduleOfPayments: number; - comissionRub: number; - plPrice: number; - discount: number; - acceptSum: number; - plTypeId: string; - brandId: string; - modelId: string; - configurationId: string; - plYear: number; - carCapacity: number; - motorVolume: number; - plEngineType: number; - carCarrying: number; - carSeats: number; - bonus: number; - bonusFix: number; - marketRate: number; - districtRate: number; - salaryRate: number; - bonusRatPr: number; - bonusNsPr: number; - bonusNsibPr: number; - rats: number; - baseRatCost: number; - retroBonus: number; - registration: number; - baseRegistration: number; - transTax: number; - transIncludeGr: boolean; - trackerCost: number; - insuranceKasko: number; - nmperInsurance: number; - insuranceOsago: number; - insurance: number; - insuranceKaskoNmper: number; - insuranceContract: number; - insuranceBonus: number; - nsibBruttoPr: number; - nsibNettoPr: number; - nsibBase: number; - repayment: number; - npvniDelta: number; - transportTaxGrYear: number; - transportTaxGr: number; - nsibBrutto: number; - nsibNetto: number; - nmperDeprecation: number; - deprecationTime: number; - ratBonus: number; - nsBonus: number; - nsibBonus: number; - niAtInception: number; - agentsSum: number; - doubleAgentsSum: number; - deliverySum: number; - brokerSum: number; - brokerOfDeliverySum: number; - financialDeptOfDeliverySum: number; - importerSum: number; - calculationCost: number; - priceUpTotal: number; - acquisitionExpenses: number; - npvBase: number; - tLMCost: number; - iRR_MSFO_Plan: number; - extraBonus: number; - directorBonus: number; - dogCredit: number; - dogCreditLeasing: number; + lastPayment?: number; + lastPaymentSum?: number; + scheduleOfPayments?: number; + comissionRub?: number; + plPrice?: number; + discount?: number; + acceptSum?: number; + plTypeId?: string; + brandId?: string; + modelId?: string; + configurationId?: string; + plYear?: number; + carCapacity?: number; + motorVolume?: number; + plEngineType?: number; + carCarrying?: number; + carSeats?: number; + bonus?: number; + bonusFix?: number; + marketRate?: number; + districtRate?: number; + salaryRate?: number; + bonusRatPr?: number; + bonusNsPr?: number; + bonusNsibPr?: number; + rats?: number; + baseRatCost?: number; + retroBonus?: number; + registration?: number; + baseRegistration?: number; + transTax?: number; + transIncludeGr?: boolean; + trackerCost?: number; + insuranceKasko?: number; + nmperInsurance?: number; + insuranceOsago?: number; + insurance?: number; + insuranceKaskoNmper?: number; + insuranceContract?: number; + insuranceBonus?: number; + nsibBruttoPr?: number; + nsibNettoPr?: number; + nsibBase?: number; + repayment?: number; + npvniDelta?: number; + transportTaxGrYear?: number; + transportTaxGr?: number; + nsibBrutto?: number; + nsibNetto?: number; + nmperDeprecation?: number; + deprecationTime?: number; + ratBonus?: number; + nsBonus?: number; + nsibBonus?: number; + niAtInception?: number; + agentsSum?: number; + doubleAgentsSum?: number; + deliverySum?: number; + brokerSum?: number; + brokerOfDeliverySum?: number; + financialDeptOfDeliverySum?: number; + importerSum?: number; + calculationCost?: number; + priceUpTotal?: number; + acquisitionExpenses?: number; + npvBase?: number; + tLMCost?: number; + iRR_MSFO_Plan?: number; + extraBonus?: number; + directorBonus?: number; + dogCredit?: number; + dogCreditLeasing?: number; } export interface PaymentRow { - numberPayment: number; - percentPayment: number; - sumPayment: number; - gpsBasePayment: number; - gpsCostPayment: number; - tlmBasePayment: number; - tlmCostPayment: number; + numberPayment?: number; + percentPayment?: number; + sumPayment?: number; + gpsBasePayment?: number; + gpsCostPayment?: number; + tlmBasePayment?: number; + tlmCostPayment?: number; } export type PreparedPayments = PaymentRow[]; diff --git a/src/core/types/Calculation/Requests.ts b/src/core/types/Calculation/Requests.ts index 3856b72..1b276b3 100644 --- a/src/core/types/Calculation/Requests.ts +++ b/src/core/types/Calculation/Requests.ts @@ -1,7 +1,6 @@ +import { ICalculationStore } from 'core/types/Calculation/Store'; import { CRMEntityNames } from 'core/types/Entities/crmEntityNames'; import { TEntityQuery } from '../Entities/query'; -import { ValuesTables } from './Store/tables'; -import { TValue, TValues } from './Store/values'; export interface IGetEntitiesRequest { queries: TEntityQuery[]; @@ -14,7 +13,6 @@ export interface IRequestToCRMGQL { } export interface IGetCalculationRequest { - values: TValues; - tables: ValuesTables; + calculationStore: ICalculationStore; username: string; } diff --git a/src/core/types/Calculation/Responses.ts b/src/core/types/Calculation/Responses.ts index effeca5..ba15ac3 100644 --- a/src/core/types/Calculation/Responses.ts +++ b/src/core/types/Calculation/Responses.ts @@ -1,5 +1,6 @@ import { TCRMEntity } from '../Entities/crmEntities'; import { TEntities } from '../Entities/crmEntityNames'; +import { User } from 'core/types/user'; export interface IGetEntitiesResponse { entities: TEntities; @@ -9,3 +10,7 @@ export interface IGetCalculationResponse { columns: any; postValues: any; } + +export interface IGetUserResponse { + user: User; +} diff --git a/src/core/types/Calculation/Store/elements.ts b/src/core/types/Calculation/Store/elements.ts index b1fb899..05e7f4c 100644 --- a/src/core/types/Calculation/Store/elements.ts +++ b/src/core/types/Calculation/Store/elements.ts @@ -132,7 +132,7 @@ export type ElementsNames = | 'selectRegistration' | 'selectInsNSIB' | 'selectTechnicalCard' - | 'selectTelematics' + | 'selectTelematic' | 'selectTracker'; export enum ElementType { diff --git a/src/core/types/Calculation/Store/tables.ts b/src/core/types/Calculation/Store/tables.ts index 04a1b5c..b6a18df 100644 --- a/src/core/types/Calculation/Store/tables.ts +++ b/src/core/types/Calculation/Store/tables.ts @@ -41,7 +41,3 @@ export interface ITable { export type StoreTables = { [table in TableNames]: ITable; }; - -export type ValuesTables = { - [table in TableNames]: TableProps[]; -}; diff --git a/src/core/types/Calculation/Store/values.ts b/src/core/types/Calculation/Store/values.ts index 9140bf4..c1a32ed 100644 --- a/src/core/types/Calculation/Store/values.ts +++ b/src/core/types/Calculation/Store/values.ts @@ -105,7 +105,7 @@ export type ValuesNames = | 'quoteName' | 'quoteContactGender' | 'quoteRedemptionGraph' - | 'Tarif' + | 'tarif' | 'creditRate' | 'rate' | 'userSession' @@ -118,7 +118,7 @@ export type ValuesNames = | 'registration' | 'insNSIB' | 'technicalCard' - | 'telematics' + | 'telematic' | 'tracker'; export type ComputedValuesNames = diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 4d1a57e..eba3514 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -245,6 +245,7 @@ export interface IEvoAddproductType { evo_cost_telematics?: number; evo_cost_price_telematics?: number; evo_cost_equipment?: number; + evo_controls_program?: number[]; } export interface IEvoTarif { @@ -308,6 +309,9 @@ export interface ISystemUser { systemuserid?: string; evo_job_titleid?: string; statecode?: number; + firstname?: string; + lastname?: string; + fullname?: string; } export interface IEvoSotCoefficientType { @@ -317,6 +321,12 @@ export interface IEvoSotCoefficientType { evo_name?: string; } +export interface IEvoJobTitle { + evo_id?: string; + evo_name?: string; + evo_job_titleid?: string; +} + type BaseEntity = { __typename?: CRMEntityNames; }; @@ -351,4 +361,5 @@ export type TCRMEntity = BaseEntity & IEvoRate & IEvoPlanPayment & ISystemUser & + IEvoJobTitle & IEvoSotCoefficientType; diff --git a/src/core/types/user.ts b/src/core/types/user.ts new file mode 100644 index 0000000..b5717d1 --- /dev/null +++ b/src/core/types/user.ts @@ -0,0 +1,6 @@ +export type User = { + DomainName?: string; + UserName?: string; + Workstation?: string; + Authenticated?: boolean; +}; diff --git a/src/server/controllers/UsersController.ts b/src/server/controllers/UsersController.ts index 86f3bf2..bc6ab2e 100644 --- a/src/server/controllers/UsersController.ts +++ b/src/server/controllers/UsersController.ts @@ -1,10 +1,10 @@ -import { Request, Response } from "express"; +import { Request, Response } from 'express'; class UsersController { static getUser = async (req: Request, res: Response): Promise => { res.send({ //@ts-ignore - user: req.connection.user, + user: req.ntlm, }); }; } diff --git a/src/server/index.ts b/src/server/index.ts index 0ad3192..ab1f1e3 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -3,13 +3,13 @@ import compression from 'compression'; import cors from 'cors'; // import cookieParser from "cookie-parser"; import express from 'express'; -// import nodeSSPI from "express-node-sspi"; import helmet from 'helmet'; import morgan from 'morgan'; import path from 'path'; import 'reflect-metadata'; import { API_PORT } from '../core/constants/urls'; import routes from './routes'; +import ntlm from 'express-ntlm'; const isDevelopmentMode = process.env.NODE_ENV === 'development'; @@ -20,16 +20,15 @@ const buildDir = path.join( const app = express(); -// app.enable("trust proxy"); -// app.set("trust proxy", "loopback"); - +app.use(cors({ origin: isDevelopmentMode && '*', credentials: false })); /** AUTHENTICATION */ -// app.use( -// nodeSSPI({ -// retrieveGroups: true, -// }) -// ); - +if (!isDevelopmentMode) + app.use( + ntlm({ + domain: 'EVOLEASING', + domaincontroller: 'ldap://evoleasing.ru', + }), + ); /** AUTHENTICATION */ /**EXTENTIONS */ @@ -41,8 +40,6 @@ app.use( ); app.use(helmet({ contentSecurityPolicy: { reportOnly: true } })); -app.use(cors({ origin: isDevelopmentMode && '*', credentials: true })); - // app.use(cookieParser()); app.use(compression()); app.use(morgan(isDevelopmentMode ? 'dev' : 'tiny')); diff --git a/src/server/routes/users.ts b/src/server/routes/users.ts index 4ee014d..00d6576 100644 --- a/src/server/routes/users.ts +++ b/src/server/routes/users.ts @@ -3,6 +3,6 @@ import { Router } from "express"; const router = Router(); -router.get("/", UsersController.getUser); +router.get("/getUser", UsersController.getUser); export default router;