prepare data
This commit is contained in:
parent
62b86e7a29
commit
6a33d26de0
@ -1431,7 +1431,57 @@ const sections: ISections[] = [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
elements: [],
|
||||
elements: [
|
||||
{
|
||||
title: 'Регистрация',
|
||||
Component: Select,
|
||||
props: {
|
||||
name: 'selectRegistration',
|
||||
valueName: 'registration',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'НСИБ',
|
||||
Component: Select,
|
||||
props: {
|
||||
name: 'selectInsNSIB',
|
||||
valueName: 'insNSIB',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Карта техпомощи',
|
||||
Component: Select,
|
||||
props: {
|
||||
name: 'selectTechnicalCard',
|
||||
valueName: 'technicalCard',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Программа средства контроля',
|
||||
Component: Radio,
|
||||
props: {
|
||||
name: 'radioRequirementTelematic',
|
||||
valueName: 'requirementTelematic',
|
||||
style: 'button',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Телематика',
|
||||
Component: Select,
|
||||
props: {
|
||||
name: 'selectTelematics',
|
||||
valueName: 'telematics',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Маяк',
|
||||
Component: Select,
|
||||
props: {
|
||||
name: 'selectTracker',
|
||||
valueName: 'tracker',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@ -7,8 +7,8 @@ import {
|
||||
IGetEntitiesOptionsResponse,
|
||||
IGetEntityOptionsResponse,
|
||||
} from 'core/types/Calculation/Responses';
|
||||
import { IGetStaticEntitiesRequest } from './../../core/types/Calculation/Requests';
|
||||
import { IGetStaticEntitiesResponse } from './../../core/types/Calculation/Responses';
|
||||
import { IGetStaticEntitiesRequest } from 'core/types/Calculation/Requests';
|
||||
import { IGetStaticEntitiesResponse } from 'core/types/Calculation/Responses';
|
||||
|
||||
class CalculationService {
|
||||
static getEntitiesOptions = ({
|
||||
|
||||
@ -23,11 +23,11 @@ export const calculatePerc = calculationStore => (
|
||||
.find(x => x.transactioncurrencyid === supplierCurrencyId);
|
||||
const evo_currencychange = calculationStore
|
||||
.getStaticData('evo_currencychange')
|
||||
?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
|
||||
.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
|
||||
const evo_currencychangeValue =
|
||||
(evo_currencychange && evo_currencychange.evo_currencychange) || 0;
|
||||
let price = calcPrice(
|
||||
supplierCurrency?.isocurrencycode,
|
||||
supplierCurrency.isocurrencycode,
|
||||
parseFloat(leaseObjectPrice),
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
@ -47,11 +47,11 @@ export const calculateRub = calculationStore => (
|
||||
.find(x => x.transactioncurrencyid === supplierCurrencyId);
|
||||
const evo_currencychange = calculationStore
|
||||
.getStaticData('evo_currencychange')
|
||||
?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
|
||||
.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId);
|
||||
const evo_currencychangeValue =
|
||||
(evo_currencychange && evo_currencychange.evo_currencychange) || 0;
|
||||
let price = calcPrice(
|
||||
supplierCurrency?.isocurrencycode,
|
||||
supplierCurrency.isocurrencycode,
|
||||
parseFloat(leaseObjectPrice),
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { IBaseOption } from 'core/types/Calculation/Store/options';
|
||||
import { TEntity } from 'core/types/Entities';
|
||||
import { TEntities } from './../types/Entities/entityNames';
|
||||
|
||||
const propsMap: TEntities<IBaseOption> = {
|
||||
const propsMap: TEntities<{ name: keyof TEntity; value: keyof TEntity }> = {
|
||||
account: {
|
||||
name: 'name',
|
||||
value: 'accountid',
|
||||
@ -36,7 +36,7 @@ const propsMap: TEntities<IBaseOption> = {
|
||||
},
|
||||
evo_baseproduct: {
|
||||
name: 'evo_name',
|
||||
value: 'evo_baseproductid',
|
||||
value: 'evo_id',
|
||||
},
|
||||
evo_leasingobject_type: {
|
||||
name: 'evo_name',
|
||||
@ -60,7 +60,7 @@ const propsMap: TEntities<IBaseOption> = {
|
||||
},
|
||||
evo_gps_brand: {
|
||||
name: 'evo_name',
|
||||
value: 'evo_gps_brandid ',
|
||||
value: 'evo_gps_brandid',
|
||||
},
|
||||
evo_gps_model: {
|
||||
name: 'evo_name',
|
||||
|
||||
@ -306,13 +306,21 @@ const initialOptions: TElements<IBaseOption[]> = {
|
||||
|
||||
radioRequirementTelematic: [
|
||||
{
|
||||
name: 'Обязательна',
|
||||
name: 'START',
|
||||
value: 100000000,
|
||||
},
|
||||
{
|
||||
name: 'Не требуется',
|
||||
name: 'START+',
|
||||
value: 100000001,
|
||||
},
|
||||
{
|
||||
name: 'COMFORT',
|
||||
value: 100000002,
|
||||
},
|
||||
{
|
||||
name: 'COMFORT+',
|
||||
value: 100000003,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
7
src/core/constants/values.js
Normal file
7
src/core/constants/values.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default {
|
||||
VAT: 0.2,
|
||||
ESN: 1.271,
|
||||
KASKO_PR: 0.3,
|
||||
KASKO_BONUS_PR: 0.35,
|
||||
NSIB_MAX: 1.2,
|
||||
};
|
||||
116
src/core/types/Calculation/Prepare.ts
Normal file
116
src/core/types/Calculation/Prepare.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import { EntityNames } from './../Entities/entityNames';
|
||||
export interface PreparedValues {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
export interface PaymentRow {
|
||||
numberPayment: number;
|
||||
percentPayment: number;
|
||||
sumPayment: number;
|
||||
gpsBasePayment: number;
|
||||
gpsCostPayment: number;
|
||||
tlmBasePayment: number;
|
||||
tlmCostPayment: number;
|
||||
}
|
||||
|
||||
export type PreparedPayments = PaymentRow[];
|
||||
|
||||
export interface PreparedData {
|
||||
preparedValues: PreparedValues;
|
||||
preparedPayments: PreparedPayments;
|
||||
}
|
||||
|
||||
type EntitiesAliases = 'evo_coefficient_season' | 'evo_coefficient_bonus';
|
||||
|
||||
export type TPrepareEntities<T> = {
|
||||
[entityAlias in EntitiesAliases | EntityNames]?: T;
|
||||
};
|
||||
@ -1,5 +1,7 @@
|
||||
import { TGetEntities } from '../Entities/query';
|
||||
import { TElements } from './../Calculation/Store/elements';
|
||||
import { ValuesTables } from './Store/tables';
|
||||
import { TValue, TValues } from './Store/values';
|
||||
|
||||
export interface IGetEntitiesOptionsRequest {
|
||||
elementsList: TElements<TGetEntities>;
|
||||
@ -12,3 +14,9 @@ export interface IGetEntityOptionsRequest {
|
||||
export interface IGetStaticEntitiesRequest {
|
||||
staticEntitiesList: TGetEntities[];
|
||||
}
|
||||
|
||||
export interface IGetCalculationRequest {
|
||||
values: TValues<TValue>;
|
||||
tables: ValuesTables;
|
||||
username: string;
|
||||
}
|
||||
|
||||
@ -13,3 +13,8 @@ export interface IGetEntityOptionsResponse {
|
||||
export interface IGetStaticEntitiesResponse {
|
||||
staticEntities: TEntities<IOption[]>;
|
||||
}
|
||||
|
||||
export interface IGetCalculationResponse {
|
||||
columns: any;
|
||||
postValues: any;
|
||||
}
|
||||
|
||||
@ -134,7 +134,12 @@ export type ElementsNames =
|
||||
| 'radioInsuranceOPF'
|
||||
| 'lblLead'
|
||||
| 'lblOpportunity'
|
||||
| 'btnCalculate';
|
||||
| 'btnCalculate'
|
||||
| 'selectRegistration'
|
||||
| 'selectInsNSIB'
|
||||
| 'selectTechnicalCard'
|
||||
| 'selectTelematics'
|
||||
| 'selectTracker';
|
||||
|
||||
export enum ElementType {
|
||||
Default,
|
||||
|
||||
@ -40,3 +40,7 @@ export interface ITable {
|
||||
export type StoreTables = {
|
||||
[table in TableNames]: ITable;
|
||||
};
|
||||
|
||||
export type ValuesTables = {
|
||||
[table in TableNames]: TableProps<any>[];
|
||||
};
|
||||
|
||||
@ -121,31 +121,11 @@ export type ValuesNames =
|
||||
| 'importerRewardPerc'
|
||||
| 'importerRewardRub'
|
||||
| 'disableChecks'
|
||||
| 'OSAGO'
|
||||
| 'KASKO'
|
||||
| 'DGO'
|
||||
| 'NS'
|
||||
| 'InsAddEquipment'
|
||||
| 'insuranceCompanyOSAGO'
|
||||
| 'insuranceCompanyKASKO'
|
||||
| 'insuranceCompanyDGO'
|
||||
| 'insuranceCompanyNS'
|
||||
| 'insuranceCompanyAddEquipment'
|
||||
| 'insuredOSAGO'
|
||||
| 'insuredKASKO'
|
||||
| 'insuredDGO'
|
||||
| 'insuredNS'
|
||||
| 'insuredAddEquipment'
|
||||
| 'costOSAGO'
|
||||
| 'costKASKO'
|
||||
| 'costDGO'
|
||||
| 'costNS'
|
||||
| 'costAddEquipment'
|
||||
| 'insuranceTermOSAGO'
|
||||
| 'insuranceTermKASKO'
|
||||
| 'insuranceTermDGO'
|
||||
| 'insuranceTermNS'
|
||||
| 'insuranceTermAddEquipment';
|
||||
| 'registration'
|
||||
| 'insNSIB'
|
||||
| 'technicalCard'
|
||||
| 'telematics'
|
||||
| 'tracker';
|
||||
|
||||
export type ComputedValuesNames =
|
||||
| 'leadName'
|
||||
@ -157,4 +137,4 @@ export type TValues<T> = {
|
||||
[valueName in ValuesNames]?: T;
|
||||
};
|
||||
|
||||
export type TValue = string | number | boolean | undefined | null;
|
||||
export type TValue = any;
|
||||
|
||||
@ -24,7 +24,11 @@ export type EntityNames =
|
||||
| 'evo_statuscode'
|
||||
| 'evo_coefficient'
|
||||
| 'evo_addproduct_type'
|
||||
| 'evo_planpayment';
|
||||
| 'evo_tarif'
|
||||
| 'evo_rate'
|
||||
| 'evo_planpayment'
|
||||
| 'systemuser'
|
||||
| 'evo_sot_coefficient_type';
|
||||
|
||||
export type TEntities<T> = {
|
||||
[entityName in EntityNames]?: T;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { IBaseOption } from '../Calculation/Store/options';
|
||||
|
||||
export interface IAccount extends IBaseOption {
|
||||
name?: string;
|
||||
accountid?: string;
|
||||
evo_inn?: string;
|
||||
evo_account_type?: number;
|
||||
@ -10,6 +11,7 @@ export interface IAccount extends IBaseOption {
|
||||
evo_legal_form?: number;
|
||||
ownerid?: string;
|
||||
evo_broker_accountid?: string;
|
||||
evo_client_riskid?: string;
|
||||
}
|
||||
|
||||
export interface ILead extends IBaseOption {
|
||||
@ -17,6 +19,8 @@ export interface ILead extends IBaseOption {
|
||||
fullname?: string;
|
||||
evo_opportunityid?: string;
|
||||
account?: string;
|
||||
ownerid?: string;
|
||||
statecode?: number;
|
||||
}
|
||||
|
||||
export interface IOpportunity extends IBaseOption {
|
||||
@ -24,6 +28,8 @@ export interface IOpportunity extends IBaseOption {
|
||||
evo_accountid?: string;
|
||||
evo_leadid?: string;
|
||||
evo_client_riskid?: string;
|
||||
ownerid?: string;
|
||||
statecode?: number;
|
||||
}
|
||||
|
||||
export interface IQuote extends IBaseOption {
|
||||
@ -32,6 +38,9 @@ export interface IQuote extends IBaseOption {
|
||||
evo_leadid?: string;
|
||||
evo_recalc_limit?: number;
|
||||
evo_approved_first_payment?: number;
|
||||
ownerid?: string;
|
||||
statecode?: number;
|
||||
evo_statuscodeid?: string;
|
||||
}
|
||||
|
||||
export interface ITransactionCurrency extends IBaseOption {
|
||||
@ -55,12 +64,16 @@ export interface IEvoClientRisk extends IBaseOption {
|
||||
export interface IEvoBaseproduct extends IBaseOption {
|
||||
evo_name?: string;
|
||||
evo_baseproductid?: string;
|
||||
evo_id?: string;
|
||||
evo_relation?: number;
|
||||
evo_datefrom?: Date;
|
||||
evo_dateto?: Date;
|
||||
evo_leaseobject_types?: IEvoLeasingObjectType[];
|
||||
evo_brands?: IEvoBrand[];
|
||||
}
|
||||
|
||||
export interface IEvoLeasingObjectType extends IBaseOption {
|
||||
evo_id?: string;
|
||||
evo_name?: string;
|
||||
evo_leasingobject_typeid?: string;
|
||||
evo_depreciation_rate1?: number;
|
||||
@ -68,6 +81,7 @@ export interface IEvoLeasingObjectType extends IBaseOption {
|
||||
evo_expluatation_period1?: number;
|
||||
evo_expluatation_period2?: number;
|
||||
evo_type_code?: string;
|
||||
evo_baseproduct?: any;
|
||||
}
|
||||
|
||||
export interface IEvoBrand extends IBaseOption {
|
||||
@ -87,6 +101,7 @@ export interface IEvoModel extends IBaseOption {
|
||||
evo_importer_reward_perc?: number;
|
||||
evo_importer_reward_rub?: number;
|
||||
statecode?: number;
|
||||
evo_baseproduct?: any;
|
||||
}
|
||||
|
||||
export interface IEvoEquipment extends IBaseOption {
|
||||
@ -135,6 +150,7 @@ export interface IEvoContact extends IBaseOption {
|
||||
parentcustomerid?: string;
|
||||
contactid?: string;
|
||||
fullname?: string;
|
||||
statecode?: number;
|
||||
}
|
||||
|
||||
export interface IConnection extends IBaseOption {
|
||||
@ -149,11 +165,13 @@ export interface IConnection extends IBaseOption {
|
||||
export interface IEvoConnectionRole extends IBaseOption {
|
||||
evo_name?: string;
|
||||
evo_connection_roleid?: string;
|
||||
statecode?: number;
|
||||
}
|
||||
|
||||
export interface IEvoImpairmentGroup extends IBaseOption {
|
||||
evo_name?: string;
|
||||
evo_impairment_groupid?: string;
|
||||
statecode?: number;
|
||||
}
|
||||
|
||||
export interface IEvoCurrencyChange extends IBaseOption {
|
||||
@ -186,10 +204,11 @@ export interface IEvoCoefficient extends IBaseOption {
|
||||
evo_correction_coefficient?: number;
|
||||
evo_sot_coefficient_typeid?: string;
|
||||
evo_sot_coefficient?: number;
|
||||
evo_client_riskid?: string;
|
||||
evo_client_typeid?: string;
|
||||
evo_client_risks?: IEvoClientRisk[];
|
||||
evo_client_types?: IEvoClientType[];
|
||||
evo_risk_delta?: number;
|
||||
evo_leasingobject_typeid?: string;
|
||||
evo_leasingobject_types?: IEvoLeasingObjectType[];
|
||||
evo_job_titleid?: string;
|
||||
}
|
||||
|
||||
export interface IEvoAddproductType extends IBaseOption {
|
||||
@ -206,11 +225,84 @@ export interface IEvoAddproductType extends IBaseOption {
|
||||
evo_max_period?: number;
|
||||
evo_leasingobject_typeid?: string;
|
||||
evo_accountid?: string;
|
||||
evo_leasingobject_types?: IEvoLeasingObjectType[];
|
||||
evo_graph_price_withoutnds?: number;
|
||||
evo_cost_service_provider_withoutnds?: number;
|
||||
evo_retro_bonus_withoutnds?: number;
|
||||
evo_planpayments?: IEvoPlanPayment[];
|
||||
evo_cost_telematics?: number;
|
||||
evo_cost_price_telematics?: number;
|
||||
evo_cost_equipment?: number;
|
||||
}
|
||||
|
||||
export interface IEvoTarif extends IBaseOption {
|
||||
evo_id?: string;
|
||||
evo_name?: string;
|
||||
evo_tarifid?: string;
|
||||
evo_baseproductid?: string;
|
||||
evo_irr?: number;
|
||||
evo_max_last_payment?: number;
|
||||
evo_max_first_payment?: number;
|
||||
evo_max_period?: number;
|
||||
evo_min_last_payment?: number;
|
||||
evo_min_first_payment?: number;
|
||||
evo_min_period?: number;
|
||||
evo_balance_holder?: number[];
|
||||
evo_transactioncurrencyid?: string;
|
||||
evo_max_irr?: number;
|
||||
evo_min_profit?: number;
|
||||
evo_min_irr?: number;
|
||||
evo_datefrom?: Date;
|
||||
evo_graphtype_exception?: number[];
|
||||
evo_dateto?: Date;
|
||||
evo_irr_plan?: number;
|
||||
evo_used?: boolean;
|
||||
statecode?: number;
|
||||
evo_ins_type?: number;
|
||||
evo_client_risks?: IEvoClientRisk[];
|
||||
evo_leasingobject_types?: IEvoLeasingObjectType[];
|
||||
evo_models?: IEvoModel[];
|
||||
evo_model_exceptions?: IEvoModel[];
|
||||
evo_rates?: IEvoRate[];
|
||||
}
|
||||
|
||||
export interface IEvoRate extends IBaseOption {
|
||||
evo_id?: string;
|
||||
evo_name?: string;
|
||||
evo_rateid?: string;
|
||||
evo_base_rate?: number;
|
||||
evo_coeff_12_23?: number;
|
||||
evo_coeff_24_35?: number;
|
||||
evo_coeff_36_47?: number;
|
||||
evo_coeff_48_60?: number;
|
||||
evo_coeff_7_11?: number;
|
||||
evo_datefrom?: Date;
|
||||
evo_dateto?: Date;
|
||||
statecode?: number;
|
||||
evo_brands?: IEvoBrand[];
|
||||
}
|
||||
|
||||
export interface IEvoPlanPayment extends IBaseOption {
|
||||
evo_planpaymentid?: string;
|
||||
evo_name?: string;
|
||||
evo_cost_telematics_withoutnds?: number;
|
||||
evo_cost_price_telematics_withoutnds?: number;
|
||||
evo_cost_equipment_withoutnds?: number;
|
||||
evo_addproduct_typeid?: string;
|
||||
}
|
||||
|
||||
export interface ISystemUser extends IBaseOption {
|
||||
domainname?: string;
|
||||
systemuserid?: string;
|
||||
evo_job_titleid?: string;
|
||||
statecode?: number;
|
||||
}
|
||||
|
||||
export interface IEvoSotCoefficientType extends IBaseOption {
|
||||
evo_id?: string;
|
||||
statecode?: number;
|
||||
evo_sot_coefficient_typeid?: string;
|
||||
evo_name?: string;
|
||||
}
|
||||
|
||||
export type TEntity = IAccount &
|
||||
@ -238,4 +330,8 @@ export type TEntity = IAccount &
|
||||
IEvoStatusCode &
|
||||
IEvoCoefficient &
|
||||
IEvoAddproductType &
|
||||
IEvoPlanPayment;
|
||||
IEvoTarif &
|
||||
IEvoRate &
|
||||
IEvoPlanPayment &
|
||||
ISystemUser &
|
||||
IEvoSotCoefficientType;
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { TEntity } from './index';
|
||||
import { EntityNames } from './entityNames';
|
||||
|
||||
export type TGetEntities = {
|
||||
entityName: EntityNames;
|
||||
fields?: string[];
|
||||
where?: { [prop: string]: any };
|
||||
whereIn?: { [prop: string]: any };
|
||||
fields?: (keyof TEntity | TGetEntities)[];
|
||||
where?: { [prop in keyof TEntity]: any };
|
||||
whereIn?: { [prop in keyof TEntity]: any | any[] };
|
||||
};
|
||||
|
||||
@ -1,61 +1,28 @@
|
||||
import { Request, Response } from 'express';
|
||||
import entityFakeData from '../../core/fakeData/entityFakes';
|
||||
import { objectToOption } from '../../core/tools/data';
|
||||
import {
|
||||
IGetEntityOptionsRequest,
|
||||
IGetEntitiesOptionsRequest,
|
||||
IGetEntityOptionsRequest,
|
||||
IGetStaticEntitiesRequest,
|
||||
} from './../../core/types/Calculation/Requests';
|
||||
import {
|
||||
IGetEntityOptionsResponse,
|
||||
IGetCalculationResponse,
|
||||
IGetEntitiesOptionsResponse,
|
||||
IGetEntityOptionsResponse,
|
||||
IGetStaticEntitiesResponse,
|
||||
} from './../../core/types/Calculation/Responses';
|
||||
import { IOption } from './../../core/types/Calculation/Store/options';
|
||||
import { TGetEntities } from './../../core/types/Entities/query';
|
||||
import {
|
||||
getEntitiesOptions,
|
||||
getEntityOptions,
|
||||
getStaticEntities,
|
||||
} from './../managers/calculationManager';
|
||||
|
||||
function _getFakeEntities({
|
||||
entityName,
|
||||
fields,
|
||||
where,
|
||||
whereIn,
|
||||
}: TGetEntities): IOption[] {
|
||||
let entities = entityFakeData[entityName];
|
||||
let totalWhere = Object.assign({}, where, whereIn);
|
||||
|
||||
if (entities !== undefined) {
|
||||
if (Object.keys(totalWhere).length > 0)
|
||||
entities = entities.filter(entity => {
|
||||
for (let w in totalWhere) {
|
||||
if (entity[w] !== totalWhere[w]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return entities;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
//TODO: move logic from controller to service
|
||||
class CalculationController {
|
||||
static getEntitiesOptions = async (
|
||||
req: Request,
|
||||
res: Response<IGetEntitiesOptionsResponse>,
|
||||
): Promise<void> => {
|
||||
const { elementsList }: IGetEntitiesOptionsRequest = req.body;
|
||||
|
||||
let entitiesOptions = {};
|
||||
Object.keys(elementsList).forEach(elementName => {
|
||||
const element: TGetEntities = elementsList[elementName];
|
||||
let entityOptions = _getFakeEntities({ ...element });
|
||||
entityOptions = entityOptions.map(opt =>
|
||||
objectToOption(opt, element.entityName),
|
||||
);
|
||||
entitiesOptions[elementName] = entityOptions;
|
||||
});
|
||||
|
||||
const { entitiesOptions } = getEntitiesOptions({ elementsList });
|
||||
res.send({ entitiesOptions });
|
||||
};
|
||||
|
||||
@ -64,12 +31,7 @@ class CalculationController {
|
||||
res: Response<IGetEntityOptionsResponse>,
|
||||
): Promise<void> => {
|
||||
const { query }: IGetEntityOptionsRequest = req.body;
|
||||
|
||||
let entityOptions = _getFakeEntities(query);
|
||||
entityOptions = entityOptions.map(entityOption =>
|
||||
objectToOption(entityOption, query.entityName),
|
||||
);
|
||||
|
||||
const { entityOptions } = getEntityOptions({ query });
|
||||
res.send({
|
||||
entityOptions,
|
||||
});
|
||||
@ -80,15 +42,22 @@ class CalculationController {
|
||||
res: Response<IGetStaticEntitiesResponse>,
|
||||
): Promise<void> => {
|
||||
const { staticEntitiesList }: IGetStaticEntitiesRequest = req.body;
|
||||
let staticEntities = {};
|
||||
staticEntitiesList.forEach(entityQuery => {
|
||||
const entityOptions = _getFakeEntities({ ...entityQuery });
|
||||
staticEntities[entityQuery.entityName] = entityOptions;
|
||||
});
|
||||
const { staticEntities } = getStaticEntities({ staticEntitiesList });
|
||||
res.send({
|
||||
staticEntities,
|
||||
});
|
||||
};
|
||||
|
||||
static calculate = async (
|
||||
req: Request,
|
||||
res: Response<IGetCalculationResponse>,
|
||||
): Promise<void> => {
|
||||
/**
|
||||
* prepare Data
|
||||
* send to core
|
||||
* send to client
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
export default CalculationController;
|
||||
|
||||
902
src/server/managers/calculationManager.ts
Normal file
902
src/server/managers/calculationManager.ts
Normal file
@ -0,0 +1,902 @@
|
||||
import { gqlRequest } from './../../core/connection/crmService';
|
||||
import { convertQueryToGQL } from './../../core/tools/query';
|
||||
import { DateTime } from 'luxon';
|
||||
import valuesConstants from '../../core/constants/values';
|
||||
import { IGetCalculationRequest } from '../../core/types/Calculation/Requests';
|
||||
import entityFakeData from './../../core/fakeData/entityFakes';
|
||||
import { objectToOption } from './../../core/tools/data';
|
||||
import {
|
||||
PreparedData,
|
||||
PreparedValues,
|
||||
TPrepareEntities,
|
||||
PreparedPayments,
|
||||
} from './../../core/types/Calculation/Prepare';
|
||||
import {
|
||||
IGetEntitiesOptionsRequest,
|
||||
IGetEntityOptionsRequest,
|
||||
IGetStaticEntitiesRequest,
|
||||
} from './../../core/types/Calculation/Requests';
|
||||
import { IOption } from './../../core/types/Calculation/Store/options';
|
||||
import { TGetEntities } from './../../core/types/Entities/query';
|
||||
import { calcPrice } from '../../client/stores/CalculationStore/Effects/lib/tools';
|
||||
|
||||
function getEntitiesFromCRM({
|
||||
entityName,
|
||||
fields,
|
||||
where,
|
||||
whereIn,
|
||||
}: TGetEntities): IOption[] {
|
||||
const gqlQuery = convertQueryToGQL({ entityName, fields, where, whereIn });
|
||||
console.log('gqlQuery', gqlQuery);
|
||||
gqlRequest({ query: gqlQuery });
|
||||
|
||||
let entities = entityFakeData[entityName];
|
||||
let totalWhere = Object.assign({}, where, whereIn);
|
||||
|
||||
if (entities !== undefined) {
|
||||
if (Object.keys(totalWhere).length > 0)
|
||||
entities = entities.filter(entity => {
|
||||
for (let w in totalWhere) {
|
||||
if (entity[w] !== totalWhere[w]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return entities;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export const getEntitiesOptions = ({
|
||||
elementsList,
|
||||
}: IGetEntitiesOptionsRequest) => {
|
||||
let entitiesOptions = {};
|
||||
Object.keys(elementsList).forEach(elementName => {
|
||||
const query: TGetEntities = elementsList[elementName];
|
||||
let entityOptions = getEntitiesFromCRM({ ...query });
|
||||
entityOptions = entityOptions.map(opt =>
|
||||
objectToOption(opt, query.entityName),
|
||||
);
|
||||
entitiesOptions[elementName] = entityOptions;
|
||||
});
|
||||
return { entitiesOptions };
|
||||
};
|
||||
|
||||
export const getEntityOptions = ({ query }: IGetEntityOptionsRequest) => {
|
||||
let entityOptions = getEntitiesFromCRM(query);
|
||||
entityOptions = entityOptions.map(entityOption =>
|
||||
objectToOption(entityOption, query.entityName),
|
||||
);
|
||||
return {
|
||||
entityOptions,
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticEntities = ({
|
||||
staticEntitiesList,
|
||||
}: IGetStaticEntitiesRequest) => {
|
||||
let staticEntities = {};
|
||||
staticEntitiesList.forEach(query => {
|
||||
const entityOptions = getEntitiesFromCRM({ ...query });
|
||||
staticEntities[query.entityName] = entityOptions;
|
||||
});
|
||||
return {
|
||||
staticEntities,
|
||||
};
|
||||
};
|
||||
|
||||
export const getEntities = (
|
||||
entitiesList: TPrepareEntities<TGetEntities>,
|
||||
): TPrepareEntities<IOption[]> => {
|
||||
let entitiesOptions = {};
|
||||
Object.keys(entitiesList).forEach(elementName => {
|
||||
const query: TGetEntities = entitiesList[elementName];
|
||||
let entityOptions = getEntitiesFromCRM({ ...query });
|
||||
entitiesOptions[elementName] = entityOptions;
|
||||
});
|
||||
return entitiesOptions;
|
||||
};
|
||||
|
||||
export const prepareCalculationData = ({
|
||||
values,
|
||||
tables,
|
||||
username,
|
||||
}: IGetCalculationRequest): any => {
|
||||
const currentDate = DateTime.local().toUTC().toJSDate();
|
||||
const entities = getEntities({
|
||||
evo_coefficient_season: {
|
||||
entityName: 'evo_coefficient',
|
||||
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',
|
||||
],
|
||||
},
|
||||
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',
|
||||
],
|
||||
},
|
||||
evo_currencychange: {
|
||||
entityName: 'evo_currencychange',
|
||||
where: {
|
||||
evo_coursedate: currentDate,
|
||||
statecode: 0,
|
||||
},
|
||||
fields: ['isocurrencycode', 'evo_currencychange'],
|
||||
},
|
||||
evo_sot_coefficient_type: {
|
||||
entityName: 'evo_sot_coefficient_type',
|
||||
where: {
|
||||
statecode: 0,
|
||||
},
|
||||
fields: ['evo_sot_coefficient_typeid', 'evo_id'],
|
||||
},
|
||||
evo_addproduct_type: {
|
||||
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',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
evo_tarif: {
|
||||
entityName: 'evo_tarif',
|
||||
where: {
|
||||
evo_tarifid: values.Tarif,
|
||||
},
|
||||
fields: ['evo_irr_plan'],
|
||||
},
|
||||
|
||||
evo_coefficient: {
|
||||
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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
evo_leasingobject_type: {
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user