From bdc360fec0a9beb4641ce17d8bc6b4d836276bc7 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 30 Jan 2023 11:24:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=A2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=84=20selectTarif=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=20=D1=84=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D0=B2=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=D1=85:=20=20=20=20=20=D0=B2=20=D0=BF=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=20=D0=92=D0=B8=D0=B4=20=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20radioGraphType=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0,=20?= =?UTF-8?q?=20=20=20=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D1=83?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D1=8B=20=D0=B2=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20"?= =?UTF-8?q?=D0=9D=D0=B5=D0=B4=D0=BE=D0=BF=D1=83=D1=81=D1=82=D0=B8=D0=BC?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B2=D0=B8=D0=B4=D1=8B=20=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=BE=D0=B2"=20evo=5Fgraphtype=5Fexception.?= =?UTF-8?q?=20=20=20=20=20=D0=95=D1=81=D0=BB=D0=B8=20=D0=B2=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2=D0=B5=20=D0=BF=D1=83=D1=81=D1=82=D0=BE?= =?UTF-8?q?,=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B8=D1=82=20=D0=B4=D0=BE=D0=BF?= =?UTF-8?q?=D1=83=D1=81=D1=82=D0=B8=D0=BC=D1=8B=20=D0=B2=D1=81=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/graphql/crm.types.ts | 14 +++---- apps/web/process/configurator/lib/query.ts | 11 ++++++ .../process/configurator/reactions/filters.ts | 38 +++++++++++++++++++ .../process/configurator/reactions/values.ts | 9 +---- .../process/payments/lib/seasons-constants.ts | 5 +++ apps/web/process/payments/reactions.ts | 31 ++++++++------- 6 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 apps/web/process/configurator/lib/query.ts diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index ba45970..4eeee4d 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -122,6 +122,13 @@ export type GetCurrencySymbolQueryVariables = Exact<{ export type GetCurrencySymbolQuery = { __typename?: 'Query', transactioncurrency: { __typename?: 'transactioncurrency', currencysymbol: string | null } | null }; +export type GetTarif_ProcessConfiguratorQueryVariables = Exact<{ + tarifId: Scalars['Uuid']; +}>; + + +export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array | null } | null }; + export type GetLeaseObjectTypes_ProcessConfiguratorQueryVariables = Exact<{ [key: string]: never; }>; @@ -167,13 +174,6 @@ export type GetTarifs_ProcessConfiguratorQueryVariables = Exact<{ export type GetTarifs_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarifs: Array<{ __typename?: 'evo_tarif', evo_tarifid: string | null, evo_baseproductid: string | null, evo_min_period: number | null, evo_max_period: number | null, evo_delivery_time: Array | null, evo_min_first_payment: number | null, evo_max_first_payment: number | null, evo_min_last_payment: number | null, evo_max_last_payment: number | null, evo_used: boolean | null } | null> | null }; -export type GetTarif_ProcessConfiguratorQueryVariables = Exact<{ - tarifId: Scalars['Uuid']; -}>; - - -export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null } | null }; - export type GetRisksDataFromQuoteQueryVariables = Exact<{ quoteId: Scalars['Uuid']; }>; diff --git a/apps/web/process/configurator/lib/query.ts b/apps/web/process/configurator/lib/query.ts new file mode 100644 index 0000000..14e052e --- /dev/null +++ b/apps/web/process/configurator/lib/query.ts @@ -0,0 +1,11 @@ +/* eslint-disable import/prefer-default-export */ +import { gql } from '@apollo/client'; + +export const QUERY_GET_TARIF = gql` + query GetTarif_ProcessConfigurator($tarifId: Uuid!) { + evo_tarif(evo_tarifid: $tarifId) { + evo_irr + evo_graphtype_exception + } + } +`; diff --git a/apps/web/process/configurator/reactions/filters.ts b/apps/web/process/configurator/reactions/filters.ts index f5c118c..7a9a814 100644 --- a/apps/web/process/configurator/reactions/filters.ts +++ b/apps/web/process/configurator/reactions/filters.ts @@ -4,6 +4,7 @@ import type * as CRMTypes from 'graphql/crm.types'; import { reaction } from 'mobx'; import type { ReactionsContext } from 'process/types'; import { normalizeOptions } from 'tools'; +import { QUERY_GET_TARIF } from '../lib/query'; const QUERY_GET_LEASE_OBJECT_TYPES = gql` query GetLeaseObjectTypes_ProcessConfigurator { @@ -264,4 +265,41 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex $calculation.element('selectDealerPerson').setOptions(normalizeOptions(dealerPersons)); } ); + + /** + * На изменение поля Тариф selectTarif добавляем фильрацию в полях: + в поле Вид графика radioGraphType должны закрываться значения для выбора, + которые указаны в массиве поля "Недопустимые виды графиков" evo_graphtype_exception. + Если в массиве пусто, значит допустимы все значения + */ + reaction( + () => $calculation.element('selectTarif').getValue(), + async (tarifId) => { + let evo_tarif: CRMTypes.GetTarif_ProcessConfiguratorQuery['evo_tarif'] = null; + + if (tarifId) { + const { data } = await apolloClient.query< + CRMTypes.GetTarif_ProcessConfiguratorQuery, + CRMTypes.GetTarif_ProcessConfiguratorQueryVariables + >({ + query: QUERY_GET_TARIF, + variables: { + tarifId, + }, + }); + + ({ evo_tarif } = data); + } + + const filteredGraphTypes = $calculation + .element('radioGraphType') + .getOptions() + .map((type) => ({ + ...type, + disabled: evo_tarif?.evo_graphtype_exception?.includes(type.value), + })); + + $calculation.element('radioGraphType').setOptions(filteredGraphTypes); + } + ); } diff --git a/apps/web/process/configurator/reactions/values.ts b/apps/web/process/configurator/reactions/values.ts index 0314735..ab35e09 100644 --- a/apps/web/process/configurator/reactions/values.ts +++ b/apps/web/process/configurator/reactions/values.ts @@ -7,6 +7,7 @@ import { autorun, reaction } from 'mobx'; import type * as CRMTypes from 'graphql/crm.types'; import type { ReactionsContext } from 'process/types'; import { makeDisposable } from 'tools'; +import { QUERY_GET_TARIF } from '../lib/query'; dayjs.extend(utc); @@ -31,14 +32,6 @@ const QUERY_GET_TARIFS = gql` } `; -const QUERY_GET_TARIF = gql` - query GetTarif_ProcessConfigurator($tarifId: Uuid!) { - evo_tarif(evo_tarifid: $tarifId) { - evo_irr - } - } -`; - export default function valuesReactions({ store, apolloClient }: ReactionsContext) { const { $calculation, $process } = store; diff --git a/apps/web/process/payments/lib/seasons-constants.ts b/apps/web/process/payments/lib/seasons-constants.ts index 889bc29..ea54f9c 100644 --- a/apps/web/process/payments/lib/seasons-constants.ts +++ b/apps/web/process/payments/lib/seasons-constants.ts @@ -13,3 +13,8 @@ export const FORBIDDEN_HIGH_SEASON_START: Record> = { export const SEASONS_PERIOD_NUMBER = 12; export const DEFAULT_SEASONS_VALUES = [100, 75, 50]; + +export const SEASON_TYPES = { + 100_000_001: [100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007], + 100_000_003: [100_000_000, 100_000_001, 100_000_002], +}; diff --git a/apps/web/process/payments/reactions.ts b/apps/web/process/payments/reactions.ts index 8c6206c..d2d053f 100644 --- a/apps/web/process/payments/reactions.ts +++ b/apps/web/process/payments/reactions.ts @@ -4,7 +4,6 @@ import { selectHighSeasonStart, selectSeasonType } from 'config/default-options' import { comparer, reaction, toJS } from 'mobx'; import type { ReactionsContext } from 'process/types'; import { shift } from 'radash'; -import type { CalculationOptions } from 'stores/calculation/options/types'; import type { Row } from 'stores/tables/payments/types'; import ValidationHelper from 'stores/validation/helper'; import { difference } from 'tools/array'; @@ -208,11 +207,6 @@ export default function paymentsReactions({ store }: ReactionsContext) { /** * Дегрессия */ - // TODO: const exeption = tarif?.evo_seasons_type_exception - const degressionSeasonTypes = new Set([ - 100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007, - ]); - const seasonSeasonTypes = new Set([100_000_000, 100_000_001, 100_000_002]); reaction( () => { @@ -221,18 +215,23 @@ export default function paymentsReactions({ store }: ReactionsContext) { return graphType; }, (graphType) => { - let selectSeasonTypeOptions: CalculationOptions['selectSeasonType'] = []; + if (!graphType) { + $calculation.element('selectSeasonType').resetOptions(); - if (graphType === 100_000_001) { - selectSeasonTypeOptions = selectSeasonType.filter((option) => - degressionSeasonTypes.has(option.value) - ); - } else if (graphType === 100_000_003) { - selectSeasonTypeOptions = selectSeasonType.filter((option) => - seasonSeasonTypes.has(option.value) - ); + return; + } + + if (graphType === 100_000_001 || graphType === 100_000_003) { + const allowedSeasonTypes = seasonsConstants.SEASON_TYPES[graphType]; + + const selectSeasonTypeOptions = selectSeasonType.filter((option) => + allowedSeasonTypes.includes(option.value) + ); + + $calculation.element('selectSeasonType').setOptions(selectSeasonTypeOptions); + } else { + $calculation.element('selectSeasonType').resetOptions(); } - $calculation.element('selectSeasonType').setOptions(selectSeasonTypeOptions); } );