1301 lines
36 KiB
TypeScript
1301 lines
36 KiB
TypeScript
/* eslint-disable sonarjs/cognitive-complexity */
|
|
import type { CalculateInput, Context } from '../types';
|
|
import type * as CoreTypes from '@/api/core/types';
|
|
import { ESN, NSIB_MAX, VAT } from '@/constants/values';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import helper from '@/process/calculate/lib/helper';
|
|
import { createCurrencyUtility } from '@/utils/currency';
|
|
import { getCurrentISODate } from '@/utils/date';
|
|
import dayjs from 'dayjs';
|
|
import utc from 'dayjs/plugin/utc';
|
|
import { min, sum } from 'radash';
|
|
|
|
dayjs.extend(utc);
|
|
|
|
type Input = {
|
|
context: Context & { unlimited?: boolean };
|
|
input: CalculateInput;
|
|
};
|
|
|
|
type PreparedValuesGetters = {
|
|
[Key in keyof CoreTypes.PreparedValues]: () => Promise<CoreTypes.PreparedValues[Key]>;
|
|
};
|
|
|
|
type AdditionalDataGetters = {
|
|
[Key in keyof CoreTypes.AdditionalData]: () => Promise<CoreTypes.AdditionalData[Key]>;
|
|
};
|
|
|
|
export async function createRequestData({
|
|
context,
|
|
input,
|
|
}: Input): Promise<CoreTypes.RequestCalculate> {
|
|
const { apolloClient, user, unlimited } = context;
|
|
const { values, insurance, payments } = input;
|
|
|
|
const { RUB } = createCurrencyUtility({ apolloClient });
|
|
|
|
let tracker: CRMTypes.GetAddProductTypeQuery['evo_addproduct_type'] = null;
|
|
|
|
if (input.values.tracker) {
|
|
const { data } = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: input.values.tracker },
|
|
});
|
|
tracker = data.evo_addproduct_type;
|
|
}
|
|
|
|
let telematic: CRMTypes.GetAddProductTypeQuery['evo_addproduct_type'] = null;
|
|
if (input.values.telematic) {
|
|
const { data } = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: input.values.telematic },
|
|
});
|
|
telematic = data.evo_addproduct_type;
|
|
}
|
|
|
|
const preparedPayments: CoreTypes.PreparedPayments = {
|
|
rows: payments.values.map((value, index) => {
|
|
const tracker_evo_planpayments = tracker?.evo_planpayments?.[index];
|
|
const telematic_evo_planpayments = telematic?.evo_planpayments?.[index];
|
|
|
|
return {
|
|
gpsBasePayment:
|
|
(tracker_evo_planpayments?.evo_cost_price_telematics_withoutnds || 0) +
|
|
(tracker_evo_planpayments?.evo_cost_equipment_withoutnds || 0),
|
|
gpsCostPayment: tracker_evo_planpayments?.evo_cost_telematics_withoutnds || 0,
|
|
numberPayment: index + 1,
|
|
percentPayment: index === 0 ? 0 : value,
|
|
sumPayment: (payments.sums[index] ?? 0) / (1 + VAT),
|
|
tlmBasePayment:
|
|
(telematic_evo_planpayments?.evo_cost_price_telematics_withoutnds || 0) +
|
|
(telematic_evo_planpayments?.evo_cost_equipment_withoutnds || 0),
|
|
tlmCostPayment: telematic_evo_planpayments?.evo_cost_telematics_withoutnds || 0,
|
|
};
|
|
}),
|
|
};
|
|
|
|
const currentDate = dayjs().utc(false);
|
|
|
|
let systemuser: CRMTypes.GetSystemUserQuery['systemuser'] = null;
|
|
|
|
if (user?.domainName) {
|
|
const { data } = await apolloClient.query({
|
|
query: CRMTypes.GetSystemUserDocument,
|
|
variables: {
|
|
domainname: user.domainName,
|
|
},
|
|
});
|
|
if (data.systemuser) systemuser = data.systemuser;
|
|
}
|
|
|
|
async function getDeprecation() {
|
|
if (values.leaseObjectType) {
|
|
const {
|
|
data: { evo_leasingobject_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetLeaseObjectTypeDocument,
|
|
variables: { leaseObjectTypeId: values.leaseObjectType },
|
|
});
|
|
|
|
if (
|
|
(evo_leasingobject_type?.evo_id === '1' &&
|
|
(values.engineType === 100_000_000 || values.engineType === 100_000_004) &&
|
|
values.engineVolume <= 3.5) ||
|
|
(evo_leasingobject_type?.evo_id === '2' &&
|
|
(values.engineType === 100_000_000 ||
|
|
values.engineType === 100_000_004 ||
|
|
values.engineType === 100_000_001) &&
|
|
values.maxMass <= 3500) ||
|
|
(evo_leasingobject_type?.evo_id !== '1' && evo_leasingobject_type?.evo_id !== '2')
|
|
) {
|
|
return {
|
|
deprecationRate: evo_leasingobject_type?.evo_depreciation_rate1,
|
|
nmperDeprecation: evo_leasingobject_type?.evo_expluatation_period1,
|
|
};
|
|
} else
|
|
return {
|
|
deprecationRate: evo_leasingobject_type?.evo_depreciation_rate2,
|
|
nmperDeprecation: evo_leasingobject_type.evo_expluatation_period2,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
const evo_coefficients = systemuser?.evo_job_titleid
|
|
? (
|
|
await apolloClient.query({
|
|
query: CRMTypes.GetCoefficientsDocument,
|
|
variables: {
|
|
currentDate: getCurrentISODate(),
|
|
},
|
|
})
|
|
).data.evo_coefficients
|
|
: null;
|
|
|
|
const preparedValuesGetters: PreparedValuesGetters = {
|
|
async acceptSum() {
|
|
const plPrice = await this.plPrice();
|
|
const discount = await this.discount();
|
|
|
|
return plPrice - discount;
|
|
},
|
|
|
|
async agentsSum() {
|
|
if (values.indAgentRewardCondition) {
|
|
const {
|
|
data: { evo_reward_condition },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRewardConditionDocument,
|
|
variables: { conditionId: values.indAgentRewardCondition },
|
|
});
|
|
|
|
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
|
return values.indAgentRewardSumm * ESN;
|
|
} else if (
|
|
evo_reward_condition?.evo_agency_agreementidData?.evo_leasingobject_price === 100_000_001
|
|
) {
|
|
const plPriceWithVAT = await this.plPriceWithVAT();
|
|
const discount = await this.discount();
|
|
|
|
return (values.indAgentRewardSumm / 100) * (plPriceWithVAT - discount * (1 + VAT)) * ESN;
|
|
}
|
|
}
|
|
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.indAgentRewardSumm / 100) * acceptSum * ESN;
|
|
},
|
|
|
|
async balanceHolder() {
|
|
return values.balanceHolder;
|
|
},
|
|
|
|
async baseRatCost() {
|
|
if (values.technicalCard) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.technicalCard },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_cost_service_provider_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async baseRegistration() {
|
|
if (values.registration) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.registration },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_cost_service_provider_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async bonus() {
|
|
return values.saleBonus / 100;
|
|
},
|
|
|
|
async bonusCoefficient() {
|
|
return values.bonusCoefficient;
|
|
},
|
|
|
|
async bonusFinGAP() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_job_titleid === systemuser?.evo_job_titleid &&
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'BONUS_FINGAP_PR'
|
|
);
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * insurance.values.fingap.insCost;
|
|
},
|
|
|
|
async bonusFix() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_job_titleid === systemuser?.evo_job_titleid &&
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'BONUS_FIX' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async bonusNsPr() {
|
|
return 0;
|
|
},
|
|
|
|
async bonusNsibPr() {
|
|
return 0;
|
|
},
|
|
|
|
async bonusRatPr() {
|
|
return 0;
|
|
},
|
|
|
|
async brandId() {
|
|
return values.brand;
|
|
},
|
|
|
|
async brokerOfDeliverySum() {
|
|
if (values.dealerBrokerRewardCondition) {
|
|
const {
|
|
data: { evo_reward_condition },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRewardConditionDocument,
|
|
variables: { conditionId: values.dealerBrokerRewardCondition },
|
|
});
|
|
|
|
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
|
return values.dealerBrokerRewardSumm / (1 + VAT);
|
|
} else if (
|
|
evo_reward_condition?.evo_agency_agreementidData?.evo_leasingobject_price === 100_000_001
|
|
) {
|
|
const plPriceWithVAT = await this.plPriceWithVAT();
|
|
const discount = await this.discount();
|
|
|
|
return (values.dealerBrokerRewardSumm / 100) * (plPriceWithVAT - discount * (1 + VAT));
|
|
} else {
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.dealerBrokerRewardSumm / 100) * acceptSum;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async brokerSum() {
|
|
if (values.calcBrokerRewardCondition) {
|
|
const {
|
|
data: { evo_reward_condition },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRewardConditionDocument,
|
|
variables: { conditionId: values.calcBrokerRewardCondition },
|
|
});
|
|
|
|
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
|
return values.calcBrokerRewardSum / (1 + VAT);
|
|
} else if (
|
|
evo_reward_condition?.evo_agency_agreementidData?.evo_leasingobject_price === 100_000_001
|
|
) {
|
|
const discount = await this.discount();
|
|
const plPriceWithVAT = await this.plPriceWithVAT();
|
|
|
|
return (values.calcBrokerRewardSum / 100) * (plPriceWithVAT - discount * (1 + VAT));
|
|
} else {
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.calcBrokerRewardSum / 100) * acceptSum;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async calcDate() {
|
|
return currentDate.toDate();
|
|
},
|
|
|
|
async calcType() {
|
|
return values.calcType;
|
|
},
|
|
|
|
async carCapacity() {
|
|
return values.leaseObjectMotorPower;
|
|
},
|
|
|
|
async carCarrying() {
|
|
return values.maxMass;
|
|
},
|
|
|
|
async carSeats() {
|
|
return 0;
|
|
},
|
|
|
|
async cityc() {
|
|
return values.townRegistration || values.regionRegistration || '';
|
|
},
|
|
|
|
async comissionRub() {
|
|
return values.comissionRub / (1 + VAT);
|
|
},
|
|
|
|
async configurationId() {
|
|
return values.configuration;
|
|
},
|
|
|
|
async deliverySum() {
|
|
if (values.dealerRewardCondition) {
|
|
const {
|
|
data: { evo_reward_condition },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRewardConditionDocument,
|
|
variables: { conditionId: values.dealerRewardCondition },
|
|
});
|
|
|
|
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
|
return values.dealerRewardSumm / (1 + VAT);
|
|
} else if (
|
|
evo_reward_condition?.evo_agency_agreementidData?.evo_leasingobject_price === 100_000_001
|
|
) {
|
|
const discount = await this.discount();
|
|
const plPriceWithVAT = await this.plPriceWithVAT();
|
|
|
|
return (values.dealerRewardSumm / 100) * (plPriceWithVAT - discount * (1 + VAT));
|
|
} else {
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.dealerRewardSumm / 100) * acceptSum;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async deliveryTime() {
|
|
return values.deliveryTime;
|
|
},
|
|
|
|
async deprecationTime() {
|
|
const deprecation = await getDeprecation();
|
|
|
|
if (deprecation?.nmperDeprecation && [85, 61].includes(deprecation?.nmperDeprecation)) {
|
|
return (deprecation.deprecationRate || 0) * 3;
|
|
}
|
|
|
|
return deprecation?.deprecationRate || 0;
|
|
},
|
|
|
|
async directorBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'DIRECTOR_BONUS' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async directorBonusFinGAP() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) => x?.evo_sot_coefficient_typeidData?.evo_id === 'DIRECTOR_BONUS_FINGAP'
|
|
);
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * insurance.values.fingap.insCost;
|
|
},
|
|
|
|
async directorBonusFix() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'DIRECTOR_BONUS_FIX' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async directorBonusNsib() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) => x?.evo_sot_coefficient_typeidData?.evo_id === 'DIRECTOR_BONUS_NSIB'
|
|
);
|
|
|
|
const nsibBrutto = await this.nsibBrutto();
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * nsibBrutto;
|
|
},
|
|
|
|
async directorExtraBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'DIRECTOR_EXTRA_BONUS' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async discount() {
|
|
if (values.supplierCurrency) {
|
|
return (
|
|
((await RUB({
|
|
currencyid: values.supplierCurrency,
|
|
value: values.supplierDiscountRub,
|
|
})) +
|
|
values.importProgramSum) /
|
|
(1 + VAT)
|
|
);
|
|
}
|
|
|
|
return (values.supplierDiscountRub + values.importProgramSum) / (1 + VAT);
|
|
},
|
|
|
|
async districtRate() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'DISTRICT_RATE' &&
|
|
systemuser?.businessunitid &&
|
|
x.evo_businessunits?.find(
|
|
(evo_businessunit) =>
|
|
evo_businessunit?.evo_sale_businessunitid === systemuser?.businessunitid
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async dogDate() {
|
|
return currentDate.toDate();
|
|
},
|
|
|
|
async doubleAgentsSum() {
|
|
if (values.calcDoubleAgentRewardCondition) {
|
|
const {
|
|
data: { evo_reward_condition },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRewardConditionDocument,
|
|
variables: { conditionId: values.calcDoubleAgentRewardCondition },
|
|
});
|
|
|
|
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
|
return values.calcDoubleAgentRewardSumm * ESN;
|
|
} else if (
|
|
evo_reward_condition?.evo_agency_agreementidData?.evo_leasingobject_price === 100_000_001
|
|
) {
|
|
const plPriceWithVAT = await this.plPriceWithVAT();
|
|
const discount = await this.discount();
|
|
|
|
return (
|
|
(values.calcDoubleAgentRewardSumm / 100) * (plPriceWithVAT - discount * (1 + VAT)) * ESN
|
|
);
|
|
} else {
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.calcDoubleAgentRewardSumm / 100) * acceptSum * ESN;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async extraBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_job_titleid === systemuser?.evo_job_titleid &&
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'EXTRA_BONUS' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async financialDeptOfDeliverySum() {
|
|
if (values.finDepartmentRewardCondtion) {
|
|
const {
|
|
data: { evo_reward_condition },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRewardConditionDocument,
|
|
variables: { conditionId: values.finDepartmentRewardCondtion },
|
|
});
|
|
|
|
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
|
return values.finDepartmentRewardSumm / (1 + VAT);
|
|
} else if (
|
|
evo_reward_condition?.evo_agency_agreementidData?.evo_leasingobject_price === 100_000_001
|
|
) {
|
|
const discount = await this.discount();
|
|
const plPriceWithVAT = await this.plPriceWithVAT();
|
|
|
|
return (values.finDepartmentRewardSumm / 100) * (plPriceWithVAT - discount * (1 + VAT));
|
|
} else {
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.finDepartmentRewardSumm / 100) * acceptSum;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async firstPayment() {
|
|
const plPrice = await this.plPrice();
|
|
const importProgramSum = await this.importProgramSum();
|
|
const firstPaymentPercWthtVAT =
|
|
values.firstPaymentRub / (1 + VAT) / (plPrice - importProgramSum);
|
|
|
|
if (firstPaymentPercWthtVAT * 100 < 30) {
|
|
if (values.graphType === 100_000_003 && values.highSeasonStart !== 100_000_000) {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_corfficient_type === 100_000_000 &&
|
|
x.evo_min_period &&
|
|
x.evo_min_period <= values.leasingPeriod &&
|
|
x.evo_max_period &&
|
|
x.evo_max_period >= values.leasingPeriod &&
|
|
x.evo_season_type === values.seasonType &&
|
|
x.evo_graph_type === values.graphType
|
|
);
|
|
|
|
return (
|
|
(firstPaymentPercWthtVAT * 100 + (evo_coefficient?.evo_correction_coefficient || 0)) /
|
|
100
|
|
);
|
|
}
|
|
|
|
if (values.graphType === 100_000_004) {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_corfficient_type === 100_000_000 &&
|
|
x.evo_min_period &&
|
|
x.evo_min_period <= values.leasingPeriod &&
|
|
x.evo_max_period &&
|
|
x.evo_max_period >= values.leasingPeriod &&
|
|
x.evo_graph_type === values.graphType
|
|
);
|
|
|
|
return (
|
|
(firstPaymentPercWthtVAT * 100 + (evo_coefficient?.evo_correction_coefficient || 0)) /
|
|
100
|
|
);
|
|
}
|
|
}
|
|
|
|
return firstPaymentPercWthtVAT;
|
|
},
|
|
|
|
async firstPaymentAbs() {
|
|
return 0;
|
|
},
|
|
|
|
async firstPaymentNdsAbs() {
|
|
return 0;
|
|
},
|
|
async firstPaymentSum() {
|
|
const firstPayment = await this.firstPayment();
|
|
const plPrice = await this.plPrice();
|
|
const importProgramSum = await this.importProgramSum();
|
|
|
|
return firstPayment * (plPrice - importProgramSum);
|
|
},
|
|
|
|
async firstPaymentWithNdsAbs() {
|
|
return 0;
|
|
},
|
|
|
|
async fuelCardSum() {
|
|
if (values.fuelCard) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.fuelCard },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_graph_price_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async fundingRate() {
|
|
if (!values.rate) {
|
|
return 0;
|
|
}
|
|
|
|
const {
|
|
data: { evo_rate },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRateDocument,
|
|
variables: { rateId: values.rate },
|
|
});
|
|
|
|
if (!evo_rate?.evo_finance_rate) {
|
|
return 0;
|
|
}
|
|
|
|
return evo_rate?.evo_finance_rate / 100;
|
|
},
|
|
|
|
async gpsCostPaymentSum() {
|
|
return sum(preparedPayments.rows, (p) => p.gpsCostPayment);
|
|
},
|
|
|
|
async iRR_MSFO_Plan() {
|
|
if (values.tarif) {
|
|
const {
|
|
data: { evo_tarif },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetTarifDocument,
|
|
variables: { tarifId: values.tarif },
|
|
});
|
|
|
|
return (evo_tarif?.evo_irr_plan || 0) / 100;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async importProgramSum() {
|
|
return values.importProgramSum / (1 + VAT);
|
|
},
|
|
|
|
async importerSum() {
|
|
if (values.importerRewardRub > 0) return values.importerRewardRub;
|
|
|
|
const acceptSum = await this.acceptSum();
|
|
|
|
return (values.importerRewardPerc / 100) * acceptSum;
|
|
},
|
|
|
|
async insuranceBonus() {
|
|
return 0;
|
|
},
|
|
|
|
async insuranceBonusLoss() {
|
|
if (values.leasingWithoutKasko) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.leasingWithoutKasko },
|
|
});
|
|
|
|
if (evo_addproduct_type?.evo_evokasko_calc_type === 100_000_001) {
|
|
return (
|
|
((evo_addproduct_type?.evo_loss_kv || 0) *
|
|
(values.plPriceRub -
|
|
values.discountRub -
|
|
values.importProgramSum +
|
|
values.addEquipmentPrice -
|
|
values.firstPaymentRub)) /
|
|
100
|
|
);
|
|
} else {
|
|
return (
|
|
((evo_addproduct_type?.evo_loss_kv || 0) *
|
|
(values.plPriceRub -
|
|
values.discountRub -
|
|
values.importProgramSum +
|
|
values.addEquipmentPrice)) /
|
|
100
|
|
);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async insuranceContract() {
|
|
const insuranceKaskoNmper = await this.insuranceKaskoNmper();
|
|
const insuranceOsago = await this.insuranceOsago();
|
|
|
|
return insuranceKaskoNmper + insuranceOsago;
|
|
},
|
|
|
|
async insuranceEvoKasko() {
|
|
if (values.leasingWithoutKasko) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.leasingWithoutKasko },
|
|
});
|
|
|
|
if (evo_addproduct_type?.evo_evokasko_calc_type === 100_000_001) {
|
|
return (
|
|
(evo_addproduct_type?.evo_cost_service_provider_withoutnds || 0) *
|
|
(values.plPriceRub -
|
|
values.discountRub -
|
|
values.importProgramSum +
|
|
values.addEquipmentPrice -
|
|
values.firstPaymentRub) +
|
|
(evo_addproduct_type?.evo_price_service_provider_withoutnds || 0)
|
|
);
|
|
} else {
|
|
return (
|
|
(evo_addproduct_type?.evo_cost_service_provider_withoutnds || 0) *
|
|
(values.plPriceRub -
|
|
values.discountRub -
|
|
values.importProgramSum +
|
|
values.addEquipmentPrice) +
|
|
(evo_addproduct_type?.evo_price_service_provider_withoutnds || 0)
|
|
);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async insuranceFinGAP() {
|
|
const { insured, insCost } = insurance.values.fingap;
|
|
|
|
return insured === 100_000_001 ? insCost : 0;
|
|
},
|
|
|
|
async insuranceKasko() {
|
|
const { insured, insCost } = insurance.values.kasko;
|
|
|
|
return insured === 100_000_001 ? insCost : 0;
|
|
},
|
|
|
|
async insuranceKaskoNmper() {
|
|
const nmperInsurance = await this.nmperInsurance();
|
|
const insuranceKasko = await this.insuranceKasko();
|
|
|
|
return nmperInsurance >= 16 ? (insuranceKasko * nmperInsurance) / 12 : insuranceKasko;
|
|
},
|
|
|
|
async insuranceOsago() {
|
|
const { insured, insCost } = insurance.values.osago;
|
|
|
|
return insured === 100_000_001 ? insCost : 0;
|
|
},
|
|
|
|
async irrExpected() {
|
|
return values.IRR_Perc / 100;
|
|
},
|
|
|
|
async lastPayment() {
|
|
return values.lastPaymentPerc / 100;
|
|
},
|
|
|
|
async lastPaymentFix() {
|
|
return values.lastPaymentRule !== 100_000_002;
|
|
},
|
|
|
|
async lastPaymentSum() {
|
|
return values.lastPaymentRub / (1 + VAT);
|
|
},
|
|
|
|
async leasing0K() {
|
|
if (values.product) {
|
|
const nmper = await this.nmper();
|
|
const {
|
|
data: { evo_baseproduct },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetProductDocument,
|
|
variables: { productId: values.product },
|
|
});
|
|
|
|
return evo_baseproduct?.evo_id === 'LEASING0'
|
|
? (nmper - 2) * (0.0234 / (1 - 1 / 1.0234) ** (nmper - 2))
|
|
: 1;
|
|
}
|
|
|
|
return 1;
|
|
},
|
|
|
|
async loanRate() {
|
|
return values.creditRate / 100;
|
|
},
|
|
|
|
async loanRatePeriod() {
|
|
if (values.rate) {
|
|
const {
|
|
data: { evo_rate },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetRateDocument,
|
|
variables: { rateId: values.rate },
|
|
});
|
|
|
|
return evo_rate?.evo_credit_period || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async marketRate() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'MARKET_RATE' &&
|
|
systemuser?.businessunitid &&
|
|
x.evo_businessunits?.find(
|
|
(evo_businessunit) =>
|
|
evo_businessunit?.evo_sale_businessunitid === systemuser?.businessunitid
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async modelId() {
|
|
return values.model;
|
|
},
|
|
|
|
async motorVolume() {
|
|
return values.engineVolume;
|
|
},
|
|
|
|
async nmper() {
|
|
return values.leasingPeriod;
|
|
},
|
|
|
|
async nmperDeprecation() {
|
|
return (await getDeprecation())?.nmperDeprecation || 0;
|
|
},
|
|
|
|
async nmperFinGAP() {
|
|
const { insTerm } = insurance.values.fingap;
|
|
|
|
return insTerm === 100_000_001 ? values.leasingPeriod : 12;
|
|
},
|
|
|
|
async nmperInsurance() {
|
|
const { insTerm } = insurance.values.kasko;
|
|
|
|
return insTerm === 100_000_001 ? values.leasingPeriod : 12;
|
|
},
|
|
|
|
async npvniDelta() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_corfficient_type === 100_000_001 &&
|
|
x.evo_min_period &&
|
|
x.evo_min_period <= values.leasingPeriod &&
|
|
x.evo_max_period &&
|
|
x.evo_max_period >= values.leasingPeriod
|
|
);
|
|
|
|
return evo_coefficient?.evo_risk_delta || 0;
|
|
},
|
|
|
|
async npvniExpected() {
|
|
return values.pi / 100;
|
|
},
|
|
|
|
async nsBonus() {
|
|
return 0;
|
|
},
|
|
|
|
async nsibBase() {
|
|
const plPrice = await this.plPrice();
|
|
const firstPaymentSum = await this.firstPaymentSum();
|
|
|
|
const value = (plPrice - firstPaymentSum) * (1 + VAT);
|
|
|
|
return min([NSIB_MAX, value]) ?? NSIB_MAX;
|
|
},
|
|
|
|
async nsibBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_job_titleid === systemuser?.evo_job_titleid &&
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'BONUS_NSIB_PR'
|
|
);
|
|
const nsibBrutto = await this.nsibBrutto();
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * nsibBrutto;
|
|
},
|
|
|
|
async nsibBrutto() {
|
|
if (values.insNSIB) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.insNSIB },
|
|
});
|
|
|
|
const nsibBase = await this.nsibBase();
|
|
const nmper = await this.nmper();
|
|
|
|
return ((((evo_addproduct_type?.evo_graph_price || 0) / 100) * nsibBase) / 12) * nmper;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async nsibBruttoPr() {
|
|
return 0;
|
|
},
|
|
|
|
async nsibNetto() {
|
|
if (values.insNSIB) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.insNSIB },
|
|
});
|
|
|
|
const nsibBase = await this.nsibBase();
|
|
const nmper = await this.nmper();
|
|
|
|
return (
|
|
((((evo_addproduct_type?.evo_cost_service_provider_withoutnds || 0) / 100) * nsibBase) /
|
|
12) *
|
|
nmper
|
|
);
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async nsibNettoPr() {
|
|
return 0;
|
|
},
|
|
|
|
async paymentDateNew() {
|
|
return null;
|
|
},
|
|
|
|
async plEngineType() {
|
|
return values.engineType;
|
|
},
|
|
|
|
async plPrice() {
|
|
if (values.supplierCurrency) {
|
|
return (
|
|
(await RUB({
|
|
currencyid: values.supplierCurrency,
|
|
value: values.leaseObjectPriceWthtVAT,
|
|
})) +
|
|
values.addEquipmentPrice / (1 + VAT)
|
|
);
|
|
}
|
|
|
|
return values.leaseObjectPriceWthtVAT + values.addEquipmentPrice / (1 + VAT);
|
|
},
|
|
|
|
async plPriceVAT() {
|
|
if (values.supplierCurrency) {
|
|
return (
|
|
(await RUB({
|
|
currencyid: values.supplierCurrency,
|
|
value: values.VATInLeaseObjectPrice,
|
|
})) +
|
|
(values.addEquipmentPrice - values.addEquipmentPrice / (1 + VAT))
|
|
);
|
|
}
|
|
|
|
return (
|
|
values.VATInLeaseObjectPrice +
|
|
(values.addEquipmentPrice - values.addEquipmentPrice / (1 + VAT))
|
|
);
|
|
},
|
|
|
|
async plPriceWithVAT() {
|
|
if (values.supplierCurrency) {
|
|
return (
|
|
(await RUB({
|
|
currencyid: values.supplierCurrency,
|
|
value: values.leaseObjectPrice,
|
|
})) + values.addEquipmentPrice
|
|
);
|
|
}
|
|
|
|
return values.leaseObjectPrice + values.addEquipmentPrice;
|
|
},
|
|
|
|
async plTypeId() {
|
|
return values.leaseObjectType;
|
|
},
|
|
|
|
async plYear() {
|
|
return values.leaseObjectYear;
|
|
},
|
|
|
|
async profitExpected() {
|
|
if (values.tarif) {
|
|
const {
|
|
data: { evo_tarif },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetTarifDocument,
|
|
variables: { tarifId: values.tarif },
|
|
});
|
|
|
|
return evo_tarif?.evo_margin_min || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async ratBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_job_titleid === systemuser?.evo_job_titleid &&
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'BONUS_RAT_PR'
|
|
);
|
|
const rats = await this.rats();
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * rats;
|
|
},
|
|
|
|
async rats() {
|
|
if (values.technicalCard) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.technicalCard },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_graph_price_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async regionalDirectorBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'REGIONAL_DIRECTOR_BONUS' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async regionalDirectorBonusFinGAP() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) => x?.evo_sot_coefficient_typeidData?.evo_id === 'REGIONAL_DIRECTOR_BONUS_FINGAP'
|
|
);
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * insurance.values.fingap.insCost;
|
|
},
|
|
|
|
async regionalDirectorBonusFix() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'REGIONAL_DIRECTOR_BONUS_FIX' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async regionalDirectorBonusNsib() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) => x?.evo_sot_coefficient_typeidData?.evo_id === 'REGIONAL_DIRECTOR_BONUS_NSIB'
|
|
);
|
|
const nsibBrutto = await this.nsibBrutto();
|
|
|
|
return (evo_coefficient?.evo_sot_coefficient || 0) * nsibBrutto;
|
|
},
|
|
|
|
async regionalDirectorExtraBonus() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) =>
|
|
x?.evo_sot_coefficient_typeidData?.evo_id === 'REGIONAL_DIRECTOR_EXTRA_BONUS' &&
|
|
values.product &&
|
|
x.evo_baseproducts?.some(
|
|
(evo_baseproduct) => evo_baseproduct?.evo_baseproductid === values.product
|
|
)
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async registration() {
|
|
if (values.registration) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.registration },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_graph_price_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async repayment() {
|
|
return 0.25;
|
|
},
|
|
|
|
async retroBonus() {
|
|
if (values.technicalCard) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.technicalCard },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_retro_bonus_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async salaryRate() {
|
|
const evo_coefficient = evo_coefficients?.find(
|
|
(x) => x?.evo_sot_coefficient_typeidData?.evo_id === 'SALARY_RATE'
|
|
);
|
|
|
|
return evo_coefficient?.evo_sot_coefficient || 0;
|
|
},
|
|
|
|
async scheduleOfPayments() {
|
|
return values.graphType;
|
|
},
|
|
|
|
async subsidyPaymentNumber() {
|
|
if (values.subsidy) {
|
|
const {
|
|
data: { evo_subsidy },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetSubsidyDocument,
|
|
variables: { subsidyId: values.subsidy },
|
|
});
|
|
|
|
return evo_subsidy?.evo_get_subsidy_payment || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async subsidySum() {
|
|
return values.subsidySum / (1 + VAT);
|
|
},
|
|
|
|
async supplierFinancing() {
|
|
return values.supplierFinancing;
|
|
},
|
|
|
|
async tlmCost() {
|
|
if (values.telematic) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.telematic },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_graph_price_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async tlmCostPaymentSum() {
|
|
return sum(preparedPayments.rows, (p) => p.tlmCostPayment);
|
|
},
|
|
|
|
async totalExpected() {
|
|
return values.totalPayments + values.subsidySum;
|
|
},
|
|
|
|
async trackerCost() {
|
|
if (values.tracker) {
|
|
const {
|
|
data: { evo_addproduct_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetAddProductTypeDocument,
|
|
variables: { addproductTypeId: values.tracker },
|
|
});
|
|
|
|
return evo_addproduct_type?.evo_graph_price_withoutnds || 0;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
async transIncludeGr() {
|
|
return values.vehicleTaxInYear > 0;
|
|
},
|
|
|
|
async transTax() {
|
|
return values.vehicleTaxInYear;
|
|
},
|
|
|
|
async transportTaxGr() {
|
|
return values.vehicleTaxInLeasingPeriod;
|
|
},
|
|
async transportTaxGrYear() {
|
|
return values.vehicleTaxInYear;
|
|
},
|
|
};
|
|
|
|
const preparedValuesResult = await Promise.all(
|
|
(Object.keys(preparedValuesGetters) as Array<keyof PreparedValuesGetters>).map(
|
|
async <T extends keyof CoreTypes.PreparedValues>(key: T) => {
|
|
const value = await preparedValuesGetters[key]();
|
|
|
|
return { [key]: value };
|
|
}
|
|
)
|
|
);
|
|
|
|
const preparedValues = Object.assign({}, ...preparedValuesResult) as CoreTypes.PreparedValues;
|
|
|
|
const { getIrr } = helper({ apolloClient });
|
|
const irr = await getIrr(values);
|
|
|
|
const additionalDataGetters: AdditionalDataGetters = {
|
|
async maxAllAgencyPerc() {
|
|
if (values.quote) {
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetQuoteDocument,
|
|
variables: { quoteId: values.quote },
|
|
});
|
|
|
|
return quote?.evo_maximum_percentage_av || null;
|
|
}
|
|
|
|
return null;
|
|
},
|
|
async maxCashflowMSFONominal() {
|
|
return irr.max;
|
|
},
|
|
async minCashflowMSFONominal() {
|
|
return irr.min;
|
|
},
|
|
};
|
|
|
|
const additionalDataResult = await Promise.all(
|
|
(Object.keys(additionalDataGetters) as Array<keyof AdditionalDataGetters>).map(
|
|
async <T extends keyof CoreTypes.AdditionalData>(key: T) => {
|
|
const value = await additionalDataGetters[key]();
|
|
|
|
return { [key]: value };
|
|
}
|
|
)
|
|
);
|
|
|
|
const additionalData = Object.assign({}, ...additionalDataResult) as CoreTypes.AdditionalData;
|
|
|
|
return {
|
|
additionalData,
|
|
flags: {
|
|
DISABLE_CHECKS_RESULTS: unlimited === true && values.disableChecks === true,
|
|
},
|
|
preparedPayments,
|
|
preparedValues,
|
|
};
|
|
}
|