diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts index 5cba121..2e1fa8c 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts @@ -55,6 +55,7 @@ const query = gql` selectRegionRegistration: evo_regions(statecode: $statecode) { evo_name evo_regionid + evo_fias_id } selectAccount: accounts( evo_account_type: $account_account_type diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts index 3571b19..3233e50 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts @@ -12,6 +12,12 @@ const query = gql` evo_double_agent_accountid evo_broker_accountid evo_fin_department_accountid + accountidData { + evo_address_legalidData { + evo_region_fias_id + evo_city_fias_id + } + } } selectOpportunity: opportunities( statecode: $statecode @@ -24,6 +30,12 @@ const query = gql` evo_client_riskid parentaccountid evo_programsolution + accountidData { + evo_address_legalidData { + evo_region_fias_id + evo_city_fias_id + } + } } } `; diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index ee58d6b..35a7333 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -79,6 +79,44 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ })), ); + let regionRegistration = quote.evo_regionid, + townRegistration = quote.evo_townid; + + let accountidData; + if (lead) { + const selected_lead = calculationStore.options.selectLead?.find( + x => x.value === lead, + ); + if (selected_lead && selected_lead.accountidData) { + accountidData = selected_lead.accountidData; + } + } + + if (opportunity) { + const selected_opportunity = calculationStore.options.selectOpportunity?.find( + x => x.value === opportunity, + ); + if (selected_opportunity && selected_opportunity.accountidData) { + accountidData = selected_opportunity.accountidData; + } + } + + let evo_region_fias_id, evo_city_fias_id; + if (accountidData) { + const { evo_address_legalidData } = accountidData; + evo_region_fias_id = evo_address_legalidData.evo_region_fias_id; + evo_city_fias_id = evo_address_legalidData.evo_city_fias_id; + } + + if (evo_region_fias_id) { + const region = calculationStore.options.selectRegionRegistration?.find( + x => x.evo_fias_id === evo_region_fias_id, + ); + if (region) { + regionRegistration = region.evo_regionid; + } + } + const { entities: options } = await CrmService.crmgqlquery({ query: optionsQuery, variables: { @@ -96,7 +134,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ findepartment_accountid: quote.evo_fin_department_accountid || NIL, evo_gps_brandid: quote.evo_gps_brandid || NIL, - evo_regionid: quote.evo_regionid || NIL, + evo_regionid: regionRegistration || NIL, }, toOptions: [ 'selectModel', @@ -156,6 +194,15 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ }, ]); + if (evo_city_fias_id) { + const city = calculationStore.options.selectTownRegistration?.find( + x => x.evo_fias_id === evo_city_fias_id, + ); + if (city) { + townRegistration = city.evo_townid; + } + } + const evo_planpayments = quote.evo_graphs.sort( (a, b) => b.createdon - a.createdon, )[0].evo_planpayments; @@ -228,7 +275,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ if (evo_programsolution === 100000000) { const midClientRisk = calculationStore.options.selectClientRisk?.find( - x => x.evo_id === 2, + x => x.evo_id === '2', ); if (midClientRisk) { clientRisk = midClientRisk.evo_client_riskid; @@ -250,6 +297,8 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ recalcWithRevision, leaseObjectCount, clientRisk, + regionRegistration, + townRegistration, }); message.success({ diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts index 8fcd15f..c618cf5 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts @@ -61,8 +61,6 @@ const mapKPtoValues: TValues = { finDepartmentRewardSumm: 'evo_fin_department_reward_total', GPSBrand: 'evo_gps_brandid', GPSModel: 'evo_gps_modelid', - regionRegistration: 'evo_regionid', - townRegistration: 'evo_townid', infuranceOPF: 'evo_ins_legal_form', insKaskoType: 'evo_insurance_type', insKaskoPriceLeasePeriod: 'evo_kasko_price_leasperiod', diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/optionsQuery.js b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/optionsQuery.js index 7dc6125..48203a8 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/optionsQuery.js +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/optionsQuery.js @@ -129,6 +129,7 @@ export default gql` ) { evo_name evo_townid + evo_fias_id } } `; diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js index 3955525..008934c 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js @@ -29,6 +29,8 @@ export default gql` evo_quotename evo_rateid evo_client_riskid + evo_regionid + evo_townid } } `; diff --git a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts index c283096..d2555f4 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts @@ -1117,6 +1117,7 @@ export default [ ) { evo_name evo_townid + evo_fias_id } } `, diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index bf52cc3..7ef302f 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -15,6 +15,12 @@ export interface IAccount { evo_type_ins_policy?: number[]; customerid?: string; evo_kpp?: string; + evo_address_legalidData?: IEvoAddress; +} + +export interface IEvoAddress { + evo_region_fias_id?: string; + evo_city_fias_id?: string; } export interface ILead { @@ -76,6 +82,8 @@ export interface IQuote { evo_max_mass?: number; evo_seats?: number; evo_year?: number; + evo_regionid?: string; + evo_townid?: string; } interface IEvoGraph { @@ -184,12 +192,14 @@ export interface IEvoGPSModel { export interface IEvoRegion { evo_name?: string; evo_regionid?: string; + evo_fias_id?: string; statecode?: number; } export interface IEvoTown { evo_name?: string; evo_townid?: string; statecode?: number; + evo_fias_id?: string; } export interface IEvoContact { parentcustomerid?: string;