diff --git a/pages/index.jsx b/pages/index.jsx index e289fad..89c42e8 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -6,7 +6,14 @@ import Output from 'Components/Output'; import Head from 'next/head'; import * as agentsReactions from 'process/agents/reactions'; import * as calculateReactions from 'process/calculate/reactions'; -import { getInsuranceData, getMainData, getOwnerData } from 'process/init/get-data'; +import { + getAddProductTypes, + getBrands, + getDealers, + getInsuranceData, + getMainData, + getOwnerData, +} from 'process/init/get-data'; import * as leadOpportunityReactions from 'process/lead-opportunity/reactions'; import paymentsReactions from 'process/payments/reactions'; import { useEffect } from 'react'; @@ -57,6 +64,18 @@ function Home() { store.$calculation.$options.setManyOptions(options); }); + getBrands(apolloClient).then(({ options }) => { + store.$calculation.$options.setManyOptions(options); + }); + + getDealers(apolloClient).then(({ options }) => { + store.$calculation.$options.setManyOptions(options); + }); + + getAddProductTypes(apolloClient).then(({ options }) => { + store.$calculation.$options.setManyOptions(options); + }); + getInsuranceData(apolloClient).then(({ tables }) => { store.$tables.insurance.setManyRowOptions(tables.insurance); }); diff --git a/process/init/__generated__/GetBrands.ts b/process/init/__generated__/GetBrands.ts new file mode 100644 index 0000000..475bcc6 --- /dev/null +++ b/process/init/__generated__/GetBrands.ts @@ -0,0 +1,18 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetBrands +// ==================================================== + +export interface GetBrands_selectBrand { + __typename: "evo_brand"; + label: string | null; + value: any | null; +} + +export interface GetBrands { + selectBrand: (GetBrands_selectBrand | null)[] | null; +} diff --git a/process/init/__generated__/GetDealers.ts b/process/init/__generated__/GetDealers.ts new file mode 100644 index 0000000..c19a20d --- /dev/null +++ b/process/init/__generated__/GetDealers.ts @@ -0,0 +1,21 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetDealers +// ==================================================== + +export interface GetDealers_selectDealer { + __typename: "account"; + label: string | null; + value: any | null; +} + +export interface GetDealers { + /** + * Контрагенты. statecode по умолчанию 0 + */ + selectDealer: (GetDealers_selectDealer | null)[] | null; +} diff --git a/process/init/__generated__/GetMainOptions.ts b/process/init/__generated__/GetMainOptions.ts index 6b4a60f..46923a0 100644 --- a/process/init/__generated__/GetMainOptions.ts +++ b/process/init/__generated__/GetMainOptions.ts @@ -26,18 +26,6 @@ export interface GetMainOptions_selectLeaseObjectType { value: any | null; } -export interface GetMainOptions_selectBrand { - __typename: "evo_brand"; - label: string | null; - value: any | null; -} - -export interface GetMainOptions_selectDealer { - __typename: "account"; - label: string | null; - value: any | null; -} - export interface GetMainOptions_selectGPSBrand { __typename: "evo_gps_brand"; label: string | null; @@ -51,11 +39,6 @@ export interface GetMainOptions { selectSupplierCurrency: (GetMainOptions_selectSupplierCurrency | null)[] | null; selectProduct: (GetMainOptions_selectProduct | null)[] | null; selectLeaseObjectType: (GetMainOptions_selectLeaseObjectType | null)[] | null; - selectBrand: (GetMainOptions_selectBrand | null)[] | null; - /** - * Контрагенты. statecode по умолчанию 0 - */ - selectDealer: (GetMainOptions_selectDealer | null)[] | null; selectGPSBrand: (GetMainOptions_selectGPSBrand | null)[] | null; } diff --git a/process/init/get-data.ts b/process/init/get-data.ts index 5154df7..f4acf2c 100644 --- a/process/init/get-data.ts +++ b/process/init/get-data.ts @@ -6,6 +6,8 @@ import utc from 'dayjs/plugin/utc'; import { getDomainName } from 'services/user/tools'; import type { User } from 'services/user/types'; import type { GetAddproductTypes } from './__generated__/GetAddproductTypes'; +import type { GetBrands } from './__generated__/GetBrands'; +import type { GetDealers } from './__generated__/GetDealers'; import type { GetInsuranceData } from './__generated__/GetInsuranceData'; import type { GetMainOptions } from './__generated__/GetMainOptions'; import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData'; @@ -27,6 +29,19 @@ const QUERY_GET_OWNER_DATA = gql` } `; +export async function getOwnerData(apolloClient: ApolloClient, user: User) { + const { data: ownerData } = await apolloClient.query({ + query: QUERY_GET_OWNER_DATA, + variables: { + domainname: getDomainName(user), + }, + }); + + return { + options: ownerData, + }; +} + const QUERY_GET_MAIN_OPTIONS = gql` query GetMainOptions($currentDate: DateTime) { selectSupplierCurrency: transactioncurrencies { @@ -50,16 +65,6 @@ const QUERY_GET_MAIN_OPTIONS = gql` value: evo_leasingobject_typeid } - selectBrand: evo_brands(statecode: 0) { - label: evo_name - value: evo_brandid - } - - selectDealer: accounts(evo_account_type: [100000001], statecode: 0, evo_legal_form: 100000001) { - label: name - value: accountid - } - selectGPSBrand: evo_gps_brands(statecode: 0) { label: evo_name value: evo_gps_brandid @@ -90,61 +95,6 @@ const QUERY_GET_REGIONS = gql` } `; -const QUERY_GET_ADDPRODUCT_TYPES = gql` - query GetAddproductTypes { - evo_addproduct_types(statecode: 0) { - label: evo_name - value: evo_addproduct_typeid - evo_graph_price - evo_product_type - } - } -`; - -const QUERY_GET_INSURANCE_DATA = gql` - query GetInsuranceData($evo_account_type: [Int!]) { - osago: accounts( - evo_account_type: $evo_account_type - evo_type_ins_policy: [100000001] - statecode: 0 - ) { - value: accountid - label: name - } - - kasko: accounts( - evo_account_type: $evo_account_type - evo_type_ins_policy: [100000000] - statecode: 0 - ) { - value: accountid - label: name - } - - fingap: accounts( - evo_account_type: $evo_account_type - evo_type_ins_policy: [100000002] - statecode: 0 - ) { - value: accountid - label: name - } - } -`; - -export async function getOwnerData(apolloClient: ApolloClient, user: User) { - const { data: ownerData } = await apolloClient.query({ - query: QUERY_GET_OWNER_DATA, - variables: { - domainname: getDomainName(user), - }, - }); - - return { - options: ownerData, - }; -} - export async function getMainData(apolloClient: ApolloClient) { // prettier-ignore const { data: mainOptions } = await apolloClient.query({ @@ -160,7 +110,6 @@ export async function getMainData(apolloClient: ApolloClient) { currentDate: dayjs().utc().toISOString(), }, }); - const selectSubsidy = subsidies.evo_subsidies?.filter( (x) => x?.evo_subsidy_type && [100_000_000, 100_000_001].includes(x?.evo_subsidy_type) ); @@ -177,6 +126,76 @@ export async function getMainData(apolloClient: ApolloClient) { const selectObjectRegionRegistration = regions.evo_regions; const selectLegalClientRegion = regions.evo_regions; + return { + options: { + ...mainOptions, + selectSubsidy, + selectImportProgram, + selectRegionRegistration, + selectObjectRegionRegistration, + selectLegalClientRegion, + }, + }; +} + +const QUERY_GET_BRANDS = gql` + query GetBrands { + selectBrand: evo_brands(statecode: 0) { + label: evo_name + value: evo_brandid + } + } +`; + +export async function getBrands(apolloClient: ApolloClient) { + const { + data: { selectBrand }, + } = await apolloClient.query({ + query: QUERY_GET_BRANDS, + }); + + return { + options: { + selectBrand, + }, + }; +} + +const QUERY_GET_DEALERS = gql` + query GetDealers { + selectDealer: accounts(evo_account_type: [100000001], statecode: 0, evo_legal_form: 100000001) { + label: name + value: accountid + } + } +`; + +export async function getDealers(apolloClient: ApolloClient) { + const { + data: { selectDealer }, + } = await apolloClient.query({ + query: QUERY_GET_DEALERS, + }); + + return { + options: { + selectDealer, + }, + }; +} + +const QUERY_GET_ADDPRODUCT_TYPES = gql` + query GetAddproductTypes { + evo_addproduct_types(statecode: 0) { + label: evo_name + value: evo_addproduct_typeid + evo_graph_price + evo_product_type + } + } +`; + +export async function getAddProductTypes(apolloClient: ApolloClient) { const { data: addproductTypes } = await apolloClient.query({ query: QUERY_GET_ADDPRODUCT_TYPES, }); @@ -215,12 +234,6 @@ export async function getMainData(apolloClient: ApolloClient) { return { options: { - ...mainOptions, - selectSubsidy, - selectImportProgram, - selectRegionRegistration, - selectObjectRegionRegistration, - selectLegalClientRegion, selectRegistration, selectTechnicalCard, selectTelematic, @@ -230,6 +243,37 @@ export async function getMainData(apolloClient: ApolloClient) { }; } +const QUERY_GET_INSURANCE_DATA = gql` + query GetInsuranceData($evo_account_type: [Int!]) { + osago: accounts( + evo_account_type: $evo_account_type + evo_type_ins_policy: [100000001] + statecode: 0 + ) { + value: accountid + label: name + } + + kasko: accounts( + evo_account_type: $evo_account_type + evo_type_ins_policy: [100000000] + statecode: 0 + ) { + value: accountid + label: name + } + + fingap: accounts( + evo_account_type: $evo_account_type + evo_type_ins_policy: [100000002] + statecode: 0 + ) { + value: accountid + label: name + } + } +`; + export async function getInsuranceData(apolloClient: ApolloClient) { const { data: insuranceData } = await apolloClient.query({ query: QUERY_GET_INSURANCE_DATA,