From fd116f89bb32a505d0dba57d9100b7763ad5bb4b Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 30 Jan 2023 13:38:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8F=20selectProduct=20(=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83=20=D0=9A=D0=9F?= =?UTF-8?q?)=20=20=20=20*=20=D0=B5=D1=81=D0=BB=D0=B8=20=20recalcWithRevisi?= =?UTF-8?q?on=3DTrue,=20=D1=82=D0=BE=20=D0=B2=20=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20selectProduct=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D1=8B=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=20=20=20*?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20quote.evo=5Fbaseprodu?= =?UTF-8?q?ctid=20=D0=B8=D0=B7=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=9F=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20select?= =?UTF-8?q?Quote=20+=20=D0=B4=D0=B0=D1=82=D1=8C=20=D0=B2=D0=BE=D0=B7=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B1?= =?UTF-8?q?=D0=B8=D1=80=D0=B0=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BA=D1=82,=20=20=20=20*=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=81=20=D0=BEquote.evo=5Fbaseprodu?= =?UTF-8?q?ctid=20=D0=B8=D0=B7=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=9F=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20select?= =?UTF-8?q?Quote=20=D0=BF=D0=BE=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B8=20evo=5Fe?= =?UTF-8?q?vo=5Fbaseproduct=5Fevo=5Fbaseproduct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/graphql/crm.types.ts | 25 ++++- .../process/configurator/reactions/filters.ts | 104 ++++++++++++++++++ .../process/init/get-data/get-main-data.js | 32 ++++-- 3 files changed, 147 insertions(+), 14 deletions(-) diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index f80a04e..1120c14 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -139,7 +139,7 @@ export type GetProduct_ProcessConfiguratorQueryVariables = Exact<{ }>; -export type GetProduct_ProcessConfiguratorQuery = { __typename?: 'Query', evo_baseproduct: { __typename?: 'evo_baseproduct', evo_calculation_method: Array | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null } | null }; +export type GetProduct_ProcessConfiguratorQuery = { __typename?: 'Query', evo_baseproduct: { __typename?: 'evo_baseproduct', evo_calculation_method: Array | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null, evo_baseproducts: Array<{ __typename?: 'evo_baseproduct', evo_baseproductid: string | null } | null> | null } | null }; export type GetSubsidy_ProcessConfiguratorQueryVariables = Exact<{ subsidyId: Scalars['Uuid']; @@ -167,6 +167,20 @@ export type GetDealerPersons_ProcessConfiguratorQueryVariables = Exact<{ export type GetDealerPersons_ProcessConfiguratorQuery = { __typename?: 'Query', dealerPersons: Array<{ __typename?: 'account', accountid: string | null, label: string | null, value: string | null } | null> | null }; +export type GetQuote_ProcessConfiguratorQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetQuote_ProcessConfiguratorQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_baseproductid: string | null } | null }; + +export type GetProducts_ProcessConfiguratorQueryVariables = Exact<{ + currentDate: InputMaybe; +}>; + + +export type GetProducts_ProcessConfiguratorQuery = { __typename?: 'Query', evo_baseproducts: Array<{ __typename?: 'evo_baseproduct', evo_baseproductid: string | null } | null> | null }; + export type GetTarifs_ProcessConfiguratorQueryVariables = Exact<{ currentDate: InputMaybe; }>; @@ -195,12 +209,17 @@ export type GetInsuranceDataQueryVariables = Exact<{ export type GetInsuranceDataQuery = { __typename?: 'Query', osago: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null, kasko: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null, fingap: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null }; -export type GetMainOptionsQueryVariables = Exact<{ +export type GetMainOptionsQueryVariables = Exact<{ [key: string]: never; }>; + + +export type GetMainOptionsQuery = { __typename?: 'Query', selectSupplierCurrency: Array<{ __typename?: 'transactioncurrency', currencysymbol: string | null, label: string | null, value: string | null } | null> | null, selectLeaseObjectType: Array<{ __typename?: 'evo_leasingobject_type', label: string | null, value: string | null } | null> | null, selectGPSBrand: Array<{ __typename?: 'evo_gps_brand', label: string | null, value: string | null } | null> | null }; + +export type GetProductsQueryVariables = Exact<{ currentDate: InputMaybe; }>; -export type GetMainOptionsQuery = { __typename?: 'Query', selectSupplierCurrency: Array<{ __typename?: 'transactioncurrency', currencysymbol: string | null, label: string | null, value: string | null } | null> | null, selectProduct: Array<{ __typename?: 'evo_baseproduct', label: string | null, value: string | null } | null> | null, selectLeaseObjectType: Array<{ __typename?: 'evo_leasingobject_type', label: string | null, value: string | null } | null> | null, selectGPSBrand: Array<{ __typename?: 'evo_gps_brand', label: string | null, value: string | null } | null> | null }; +export type GetProductsQuery = { __typename?: 'Query', selectProduct: Array<{ __typename?: 'evo_baseproduct', label: string | null, value: string | null } | null> | null }; export type GetSubsidiesQueryVariables = Exact<{ currentDate: InputMaybe; diff --git a/apps/web/process/configurator/reactions/filters.ts b/apps/web/process/configurator/reactions/filters.ts index 00116be..cf96c23 100644 --- a/apps/web/process/configurator/reactions/filters.ts +++ b/apps/web/process/configurator/reactions/filters.ts @@ -1,5 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { gql } from '@apollo/client'; +import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; import type * as CRMTypes from 'graphql/crm.types'; import { reaction } from 'mobx'; import { SEASON_TYPES } from 'process/payments/lib/seasons-constants'; @@ -8,6 +10,8 @@ import { diff } from 'radash'; import { normalizeOptions } from 'tools'; import { QUERY_GET_TARIF } from '../lib/query'; +dayjs.extend(utc); + const QUERY_GET_LEASE_OBJECT_TYPES = gql` query GetLeaseObjectTypes_ProcessConfigurator { evo_leasingobject_types(statecode: 0) { @@ -25,6 +29,9 @@ const QUERY_GET_PRODUCT = gql` evo_leasingobject_typeid } evo_calculation_method + evo_baseproducts { + evo_baseproductid + } } } `; @@ -75,6 +82,27 @@ const QUERY_GET_DEALER_PERSONS = gql` } `; +const QUERY_GET_QUOTE = gql` + query GetQuote_ProcessConfigurator($quoteId: Uuid!) { + quote(quoteId: $quoteId) { + evo_baseproductid + } + } +`; + +const QUERY_GET_PRODUCTS = gql` + query GetProducts_ProcessConfigurator($currentDate: DateTime) { + evo_baseproducts( + statecode: 0 + evo_relation: [100000000] + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + ) { + evo_baseproductid + } + } +`; + export default function commonReactions({ store, apolloClient }: ReactionsContext) { const { $calculation } = store; @@ -388,4 +416,80 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex } } ); + + /* eslint-disable max-len */ + /** + * Добавить фильтр для поля selectProduct (работает на загрузку КП) + * если recalcWithRevision=True, то в списке поля selectProduct должны отображаться + * записи quote.evo_baseproductid из поля Предложение selectQuote + дать возможность выбирать продукт, + * связанный с оquote.evo_baseproductid из поля Предложение selectQuote по связи evo_evo_baseproduct_evo_baseproduct + /* eslint-enable */ + reaction( + () => $calculation.element('selectQuote').getValue(), + async (quoteId) => { + const currentDate = dayjs().utc(false).toISOString(); + + const { + data: { evo_baseproducts }, + } = await apolloClient.query< + CRMTypes.GetProducts_ProcessConfiguratorQuery, + CRMTypes.GetProducts_ProcessConfiguratorQueryVariables + >({ + query: QUERY_GET_PRODUCTS, + variables: { + currentDate, + }, + }); + + if (!$calculation.element('cbxRecalcWithRevision').getValue()) { + $calculation.element('selectProduct').setOptions(normalizeOptions(evo_baseproducts)); + + return; + } + + let quote: CRMTypes.GetQuote_ProcessConfiguratorQuery['quote'] = null; + + if (quoteId) { + const { data } = await apolloClient.query< + CRMTypes.GetQuote_ProcessConfiguratorQuery, + CRMTypes.GetQuote_ProcessConfiguratorQueryVariables + >({ + query: QUERY_GET_QUOTE, + variables: { + quoteId, + }, + }); + + ({ quote } = data); + } + + if (quote?.evo_baseproductid) { + const { + data: { evo_baseproduct }, + } = await apolloClient.query< + CRMTypes.GetProduct_ProcessConfiguratorQuery, + CRMTypes.GetProduct_ProcessConfiguratorQueryVariables + >({ + query: QUERY_GET_PRODUCT, + variables: { + productId: quote?.evo_baseproductid, + }, + }); + + const allowedProducts = evo_baseproduct?.evo_baseproducts?.map( + (product) => product?.evo_baseproductid + ); + + const filteredSelectProductOptions = normalizeOptions( + evo_baseproducts?.filter((product) => + allowedProducts?.includes(product?.evo_baseproductid) + ) + ); + + $calculation.element('selectProduct').setOptions(filteredSelectProductOptions); + } else { + $calculation.element('selectProduct').setOptions(normalizeOptions(evo_baseproducts)); + } + } + ); } diff --git a/apps/web/process/init/get-data/get-main-data.js b/apps/web/process/init/get-data/get-main-data.js index 3c990aa..ee0279a 100644 --- a/apps/web/process/init/get-data/get-main-data.js +++ b/apps/web/process/init/get-data/get-main-data.js @@ -8,23 +8,13 @@ import { useStore } from 'stores/hooks'; dayjs.extend(utc); const QUERY_GET_MAIN_OPTIONS = gql` - query GetMainOptions($currentDate: DateTime) { + query GetMainOptions { selectSupplierCurrency: transactioncurrencies { label: currencyname currencysymbol value: transactioncurrencyid } - selectProduct: evo_baseproducts( - statecode: 0 - evo_relation: [100000000] - evo_datefrom_param: { lte: $currentDate } - evo_dateto_param: { gte: $currentDate } - ) { - label: evo_name - value: evo_baseproductid - } - selectLeaseObjectType: evo_leasingobject_types(statecode: 0) { label: evo_name value: evo_leasingobject_typeid @@ -37,6 +27,20 @@ const QUERY_GET_MAIN_OPTIONS = gql` } `; +const QUERY_GET_PRODUCTS = gql` + query GetProducts($currentDate: DateTime) { + selectProduct: evo_baseproducts( + statecode: 0 + evo_relation: [100000000] + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + ) { + label: evo_name + value: evo_baseproductid + } + } +`; + const QUERY_GET_SUBSIDIES = gql` query GetSubsidies($currentDate: DateTime) { evo_subsidies( @@ -107,6 +111,12 @@ const currentDate = dayjs().utc(false).toISOString(); function getMainData(query, onCompleted) { query({ query: QUERY_GET_MAIN_OPTIONS, + }).then(({ data }) => { + onCompleted(data); + }); + + query({ + query: QUERY_GET_PRODUCTS, variables: { currentDate, },