process kasko results

This commit is contained in:
vchikalkin 2024-07-24 16:43:32 +03:00
parent c67e7a21b5
commit eb56559adb
3 changed files with 200 additions and 0 deletions

View File

@ -1080,6 +1080,54 @@ query GetInsuranceCompanies {
}
}
query GetEltInsuranceRules {
evo_insurance_ruleses {
evo_id
evo_datefrom
evo_dateto
evo_risk
evo_category
evo_min_period
evo_max_period
evo_object_type
evo_use_for
evo_min_price
evo_max_price
evo_min_year
evo_max_year
evo_min_power
evo_max_power
evo_enginie_type
evo_opf
evo_min_mileage
evo_max_mileage
evo_brand
evo_model
evo_region
evo_dealer
evo_rules_type
evo_message
evo_discount
evo_insurer_accountid
evo_brand
evo_model
evo_region
evo_dealer
evo_brands {
evo_brandid
}
evo_models {
evo_modelid
}
accounts {
accountid
}
evo_regions {
evo_regionid
}
}
}
query GetRoles($roleName: String) {
roles(
filterConditionGroup: {

View File

@ -2230,6 +2230,11 @@ export type GetInsuranceCompaniesQueryVariables = Exact<{ [key: string]: never;
export type GetInsuranceCompaniesQuery = { __typename?: 'Query', accounts: Array<{ __typename?: 'account', evo_type_ins_policy: Array<number> | null, evo_evokasko_access: boolean | null, evo_inn: string | null, evo_id_elt_osago: string | null, evo_id_elt: string | null, evo_id_elt_smr: string | null, evo_osago_id: string | null, evo_kasko_category: Array<number> | null, evo_osago_category: Array<number> | null, value: string | null, label: string | null } | null> | null };
export type GetEltInsuranceRulesQueryVariables = Exact<{ [key: string]: never; }>;
export type GetEltInsuranceRulesQuery = { __typename?: 'Query', evo_insurance_ruleses: Array<{ __typename?: 'evo_insurance_rules', evo_id: string | null, evo_datefrom: string | null, evo_dateto: string | null, evo_risk: number | null, evo_category: Array<number> | null, evo_min_period: number | null, evo_max_period: number | null, evo_object_type: number | null, evo_use_for: Array<number> | null, evo_min_price: number | null, evo_max_price: number | null, evo_min_year: number | null, evo_max_year: number | null, evo_min_power: number | null, evo_max_power: number | null, evo_enginie_type: Array<number> | null, evo_opf: Array<number> | null, evo_min_mileage: number | null, evo_max_mileage: number | null, evo_brand: number | null, evo_model: number | null, evo_region: number | null, evo_dealer: number | null, evo_rules_type: number | null, evo_message: string | null, evo_discount: number | null, evo_insurer_accountid: string | null, evo_brands: Array<{ __typename?: 'evo_brand', evo_brandid: string | null } | null> | null, evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null, accounts: Array<{ __typename?: 'account', accountid: string | null } | null> | null, evo_regions: Array<{ __typename?: 'evo_region', evo_regionid: string | null } | null> | null } | null> | null };
export type GetRolesQueryVariables = Exact<{
roleName: InputMaybe<Scalars['String']['input']>;
}>;
@ -2293,4 +2298,5 @@ export const GetLeasingWithoutKaskoTypesDocument = {"kind":"Document","definitio
export const GetOsagoAddproductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOsagoAddproductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filterConditionGroup"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"andFilterConditions"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionInt"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"statecode","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"IntValue","value":"0"}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionDateTime"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"evo_datefrom","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionDateTime"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"evo_dateto","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionInt"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"evo_product_type","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"IntValue","value":"100000008"}}]}}]}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_visible_calc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"createdon"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_power"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_power"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_seats_count"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_seats_count"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_mass"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_mass"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}}]}}]}}]} as unknown as DocumentNode<GetOsagoAddproductTypesQuery, GetOsagoAddproductTypesQueryVariables>;
export const GetInsuranceCompanyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetInsuranceCompany"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"accountId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"account"},"name":{"kind":"Name","value":"insurance"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"accountid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"accountId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_osago_with_kasko"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_region_calc"}},{"kind":"Field","name":{"kind":"Name","value":"accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_fact_part"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_plan_part"}}]}}]}}]} as unknown as DocumentNode<GetInsuranceCompanyQuery, GetInsuranceCompanyQueryVariables>;
export const GetInsuranceCompaniesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetInsuranceCompanies"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"accounts"},"name":{"kind":"Name","value":"insurances"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_type_ins_policy"}},{"kind":"Field","name":{"kind":"Name","value":"evo_evokasko_access"}},{"kind":"Field","name":{"kind":"Name","value":"evo_inn"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id_elt_osago"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id_elt"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id_elt_smr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_osago_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_category"}},{"kind":"Field","name":{"kind":"Name","value":"evo_osago_category"}}]}}]}}]} as unknown as DocumentNode<GetInsuranceCompaniesQuery, GetInsuranceCompaniesQueryVariables>;
export const GetEltInsuranceRulesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetEltInsuranceRules"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_insurance_ruleses"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_datefrom"}},{"kind":"Field","name":{"kind":"Name","value":"evo_dateto"}},{"kind":"Field","name":{"kind":"Name","value":"evo_risk"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_object_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_use_for"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_year"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_year"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_power"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_power"}},{"kind":"Field","name":{"kind":"Name","value":"evo_enginie_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_opf"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_mileage"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_mileage"}},{"kind":"Field","name":{"kind":"Name","value":"evo_brand"}},{"kind":"Field","name":{"kind":"Name","value":"evo_model"}},{"kind":"Field","name":{"kind":"Name","value":"evo_region"}},{"kind":"Field","name":{"kind":"Name","value":"evo_dealer"}},{"kind":"Field","name":{"kind":"Name","value":"evo_rules_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_message"}},{"kind":"Field","name":{"kind":"Name","value":"evo_discount"}},{"kind":"Field","name":{"kind":"Name","value":"evo_insurer_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_brand"}},{"kind":"Field","name":{"kind":"Name","value":"evo_model"}},{"kind":"Field","name":{"kind":"Name","value":"evo_region"}},{"kind":"Field","name":{"kind":"Name","value":"evo_dealer"}},{"kind":"Field","name":{"kind":"Name","value":"evo_brands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brandid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_models"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_modelid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"accounts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_regions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_regionid"}}]}}]}}]}}]} as unknown as DocumentNode<GetEltInsuranceRulesQuery, GetEltInsuranceRulesQueryVariables>;
export const GetRolesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRoles"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"roleName"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"roles"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filterConditionGroup"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"andFilterConditions"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionString"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"name","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"roleName"}}}]}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemusers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"fullname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"domainname"}}]}}]}}]}}]} as unknown as DocumentNode<GetRolesQuery, GetRolesQueryVariables>;

View File

@ -1,3 +1,5 @@
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable complexity */
import type { ownOsagoRequest } from './request';
import type * as ELT from '@/api/elt/types';
import type { Row } from '@/Components/Calculation/Form/ELT/types';
@ -5,6 +7,9 @@ import { MAX_FRANCHISE, MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values'
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import { defaultRow } from '@/stores/tables/elt/default-values';
import { getCurrentDate } from '@/utils/date';
import dayjs from 'dayjs';
import { sort } from 'radash';
export function convertEltOsagoResponse(response: ELT.ResponseEltOsago, row: Row): Row {
const { message, numCalc, premiumSum = 0, skCalcId } = response;
@ -142,6 +147,147 @@ export async function convertEltKaskoResponse(input: ConvertEltKaskoResponseInpu
error = 'Расчет возможен только через отдел страхования ЛК';
}
const {
data: { evo_insurance_ruleses },
} = await apolloClient.query({
query: CRMTypes.GetEltInsuranceRulesDocument,
});
const leaseObjectCategory = $calculation.element('selectLeaseObjectCategory').getValue();
const leaseObjectPrice = $calculation.element('tbxLeaseObjectPrice').getValue();
const supplierDiscountRub = $calculation.element('tbxSupplierDiscountRub').getValue();
const leaseObjectYear = $calculation.element('tbxLeaseObjectYear').getValue();
const leaseObjectMotorPower = $calculation.element('tbxLeaseObjectMotorPower').getValue();
const engineType = $calculation.element('selectEngineType').getValue();
const tbxMileage = $calculation.element('tbxMileage').getValue();
const brand = $calculation.element('selectBrand').getValue();
const model = $calculation.element('selectModel').getValue();
const selectLeaseObjectUseFor = $calculation.element('selectLeaseObjectUseFor').getValue();
const legalClientRegion = $calculation.element('selectLegalClientRegion').getValue();
const dealerPerson = $calculation.element('selectDealerPerson').getValue();
const cbxLeaseObjectUsed = $calculation.element('cbxLeaseObjectUsed').getValue();
const cost = leaseObjectPrice - supplierDiscountRub;
const currentDate = getCurrentDate();
let lead: CRMTypes.GetLeadQuery['lead'] = null;
const leadid = $calculation.element('selectLead').getValue();
if (leadid) {
const { data } = await apolloClient.query({
query: CRMTypes.GetLeadDocument,
variables: { leadid },
});
({ lead } = data);
}
const insuranceOPF = lead?.evo_inn?.length === 12 ? 100_000_001 : 100_000_000;
const filteredRules = evo_insurance_ruleses?.filter(
(rule) =>
rule?.evo_datefrom &&
rule.evo_dateto &&
new Date(rule.evo_datefrom) <= new Date(currentDate) &&
rule.evo_dateto &&
new Date(rule.evo_dateto) >= new Date(currentDate) &&
rule.evo_insurer_accountid === insuranceCompany?.accountid &&
rule.evo_risk === 100_000_000 &&
leaseObjectCategory &&
rule.evo_category?.includes(leaseObjectCategory) &&
rule.evo_min_period !== null &&
rule.evo_max_period !== null &&
leasingPeriod !== null &&
rule.evo_min_period <= leasingPeriod &&
rule.evo_max_period >= leasingPeriod &&
(rule.evo_object_type === 100_000_000 ||
(rule.evo_object_type === 100_000_001 && cbxLeaseObjectUsed === false) ||
(rule.evo_object_type === 100_000_002 && cbxLeaseObjectUsed === true)) &&
selectLeaseObjectUseFor &&
rule.evo_use_for?.includes(selectLeaseObjectUseFor) &&
rule.evo_min_price !== null &&
rule.evo_max_price !== null &&
cost !== null &&
rule.evo_min_price <= cost &&
rule.evo_max_price >= cost &&
rule.evo_min_year !== null &&
rule.evo_max_year !== null &&
leaseObjectYear !== null &&
rule.evo_min_year <= leaseObjectYear &&
rule.evo_max_year >= leaseObjectYear &&
rule.evo_min_power !== null &&
rule.evo_max_power !== null &&
leaseObjectMotorPower !== null &&
rule.evo_min_power <= leaseObjectMotorPower &&
rule.evo_max_power >= leaseObjectMotorPower &&
engineType &&
rule.evo_enginie_type?.includes(engineType) &&
rule.evo_opf?.includes(insuranceOPF) &&
rule.evo_min_mileage !== null &&
rule.evo_max_mileage !== null &&
tbxMileage !== null &&
rule.evo_min_mileage <= tbxMileage &&
rule.evo_max_mileage >= tbxMileage &&
(rule.evo_brand === 100_000_000 ||
(rule.evo_brand === 100_000_001 &&
rule.evo_brands?.some((x) => x?.evo_brandid === brand)) ||
(rule.evo_brand === 100_000_002 &&
!rule.evo_brands?.some((x) => x?.evo_brandid === brand))) &&
(rule.evo_model === 100_000_000 ||
(rule.evo_model === 100_000_001 &&
rule.evo_models?.some((x) => x?.evo_modelid === model)) ||
(rule.evo_model === 100_000_002 &&
!rule.evo_models?.some((x) => x?.evo_modelid === model))) &&
(rule.evo_region === 100_000_000 ||
(rule.evo_region === 100_000_001 &&
rule.evo_regions?.some((x) => x?.evo_regionid === legalClientRegion)) ||
(rule.evo_region === 100_000_002 &&
!rule.evo_regions?.some((x) => x?.evo_regionid === legalClientRegion))) &&
(rule.evo_dealer === 100_000_000 ||
(rule.evo_dealer === 100_000_001 &&
rule.accounts?.some((x) => x?.accountid === dealerPerson)) ||
(rule.evo_dealer === 100_000_002 &&
!rule.accounts?.some((x) => x?.accountid === dealerPerson)))
);
// Обработка найденных записей по приоритету
const sortedRules = filteredRules
? sort(filteredRules, (x) => dayjs(x?.evo_datefrom).date(), true)
: [];
const selectedRule = sortedRules.find((rule) => rule?.evo_rules_type !== 100_000_000);
if (selectedRule) {
const discount = selectedRule.evo_discount ?? 0;
switch (selectedRule.evo_rules_type) {
// "проверка на мин.тариф"
case 100_000_001: {
const newSum = (sum / cost) * 100;
if (newSum < discount) {
sum = 0;
requestId = defaultRow.requestId;
skCalcId = defaultRow.skCalcId;
if (selectedRule.evo_message) error = selectedRule.evo_message;
totalFranchise = 0;
}
break;
}
// "скидка за счет КВ"
case 100_000_002: {
sum = (((sum / cost) * 100 - discount) / 100) * cost;
requestId = defaultRow.requestId;
skCalcId = defaultRow.skCalcId;
if (selectedRule.evo_message) error = selectedRule.evo_message;
totalFranchise = 0;
break;
}
// "акционный тариф"
case 100_000_003: {
sum = (discount / 100) * cost;
requestId = defaultRow.requestId;
skCalcId = defaultRow.skCalcId;
if (selectedRule.evo_message) error = selectedRule.evo_message;
totalFranchise = 0;
break;
}
}
}
return {
...row,
message: error || message,