diff --git a/.graphqlrc.yml b/.graphqlrc.yml index e1114bd..427fcac 100644 --- a/.graphqlrc.yml +++ b/.graphqlrc.yml @@ -9,4 +9,13 @@ generates: config: onlyOperationTypes: true useTypeImports: true + avoidOptionals: + field: true + inputValue: false + object: true + defaultValue: true + scalars: + Uuid: string + Decimal: number + DateTime: string # exclude: './graphql/crm.schema.graphql' diff --git a/Components/Calculation/addons/currency-addon.tsx b/Components/Calculation/addons/currency-addon.tsx index 368f804..afdab0f 100644 --- a/Components/Calculation/addons/currency-addon.tsx +++ b/Components/Calculation/addons/currency-addon.tsx @@ -21,7 +21,7 @@ const CurrencyAddon = observer(() => { CRMTypes.GetCurrencySymbolQueryVariables >(QUERY_GET_CURRENCY_SYMBOL, { variables: { - currencyid, + currencyid: currencyid!, }, skip: !currencyid, }); diff --git a/graphql/crm.types.ts b/graphql/crm.types.ts index fb48cda..f16f6c7 100644 --- a/graphql/crm.types.ts +++ b/graphql/crm.types.ts @@ -11,12 +11,12 @@ export type Scalars = { Int: number; Float: number; /** The `DateTime` scalar represents an ISO-8601 compliant date time type. */ - DateTime: any; + DateTime: string; /** The built-in `Decimal` scalar type. */ - Decimal: any; + Decimal: number; /** The multiplier path scalar represents a valid GraphQL multiplier path string. */ MultiplierPath: any; - Uuid: any; + Uuid: string; }; export type ConditionInput = { @@ -120,219 +120,219 @@ export type GetCurrencySymbolQueryVariables = Exact<{ }>; -export type GetCurrencySymbolQuery = { __typename?: 'Query', transactioncurrency?: { __typename?: 'transactioncurrency', currencysymbol?: string | null } | null }; +export type GetCurrencySymbolQuery = { __typename?: 'Query', transactioncurrency: { __typename?: 'transactioncurrency', currencysymbol: string | null } | null }; export type GetFinGapAddProductTypesQueryVariables = Exact<{ - currentDate?: InputMaybe; + currentDate: InputMaybe; }>; -export type GetFinGapAddProductTypesQuery = { __typename?: 'Query', evo_addproduct_types?: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid?: any | null, evo_name?: string | null, evo_type_calc_cerebellum?: number | null, evo_cost_service_provider_withoutnds?: any | null, evo_addproduct_types?: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid?: any | null } | null> | null } | null> | null }; +export type GetFinGapAddProductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null, evo_name: string | null, evo_type_calc_cerebellum: number | null, evo_cost_service_provider_withoutnds: number | null, evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null } | null> | null } | null> | null }; export type GetAddproductTypesQueryVariables = Exact<{ [key: string]: never; }>; -export type GetAddproductTypesQuery = { __typename?: 'Query', evo_addproduct_types?: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price?: any | null, evo_product_type?: number | null, label?: string | null, value?: any | null } | null> | null }; +export type GetAddproductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price: number | null, evo_product_type: number | null, label: string | null, value: string | null } | null> | null }; export type GetBrandsQueryVariables = Exact<{ [key: string]: never; }>; -export type GetBrandsQuery = { __typename?: 'Query', selectBrand?: Array<{ __typename?: 'evo_brand', label?: string | null, value?: any | null } | null> | null }; +export type GetBrandsQuery = { __typename?: 'Query', selectBrand: Array<{ __typename?: 'evo_brand', label: string | null, value: string | null } | null> | null }; export type GetDealersQueryVariables = Exact<{ [key: string]: never; }>; -export type GetDealersQuery = { __typename?: 'Query', selectDealer?: Array<{ __typename?: 'account', label?: string | null, value?: any | null } | null> | null }; +export type GetDealersQuery = { __typename?: 'Query', selectDealer: Array<{ __typename?: 'account', label: string | null, value: string | null } | null> | null }; export type GetInsuranceDataQueryVariables = Exact<{ - evo_account_type?: InputMaybe | Scalars['Int']>; + evo_account_type: InputMaybe | Scalars['Int']>; }>; -export type GetInsuranceDataQuery = { __typename?: 'Query', osago?: Array<{ __typename?: 'account', value?: any | null, label?: string | null } | null> | null, kasko?: Array<{ __typename?: 'account', value?: any | null, label?: string | null } | null> | null, fingap?: Array<{ __typename?: 'account', value?: any | null, label?: string | null } | null> | null }; +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<{ - currentDate?: InputMaybe; + currentDate: InputMaybe; }>; -export type GetMainOptionsQuery = { __typename?: 'Query', selectSupplierCurrency?: Array<{ __typename?: 'transactioncurrency', currencysymbol?: string | null, label?: string | null, value?: any | null } | null> | null, selectProduct?: Array<{ __typename?: 'evo_baseproduct', label?: string | null, value?: any | null } | null> | null, selectLeaseObjectType?: Array<{ __typename?: 'evo_leasingobject_type', label?: string | null, value?: any | null } | null> | null, selectGPSBrand?: Array<{ __typename?: 'evo_gps_brand', label?: string | null, value?: any | null } | null> | null }; +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 GetSubsidiesQueryVariables = Exact<{ - currentDate?: InputMaybe; + currentDate: InputMaybe; }>; -export type GetSubsidiesQuery = { __typename?: 'Query', evo_subsidies?: Array<{ __typename?: 'evo_subsidy', evo_subsidy_type?: number | null, label?: string | null, value?: any | null } | null> | null }; +export type GetSubsidiesQuery = { __typename?: 'Query', evo_subsidies: Array<{ __typename?: 'evo_subsidy', evo_subsidy_type: number | null, label: string | null, value: string | null } | null> | null }; export type GetRegionsQueryVariables = Exact<{ [key: string]: never; }>; -export type GetRegionsQuery = { __typename?: 'Query', evo_regions?: Array<{ __typename?: 'evo_region', label?: string | null, value?: any | null } | null> | null }; +export type GetRegionsQuery = { __typename?: 'Query', evo_regions: Array<{ __typename?: 'evo_region', label: string | null, value: string | null } | null> | null }; export type GetOwnerDataQueryVariables = Exact<{ - domainname?: InputMaybe; + domainname: InputMaybe; }>; -export type GetOwnerDataQuery = { __typename?: 'Query', selectLead?: Array<{ __typename?: 'lead', label?: string | null, value?: any | null } | null> | null, selectOpportunity?: Array<{ __typename?: 'opportunity', label?: string | null, value?: any | null } | null> | null }; +export type GetOwnerDataQuery = { __typename?: 'Query', selectLead: Array<{ __typename?: 'lead', label: string | null, value: string | null } | null> | null, selectOpportunity: Array<{ __typename?: 'opportunity', label: string | null, value: string | null } | null> | null }; export type GetTransactionCurrenciesQueryVariables = Exact<{ [key: string]: never; }>; -export type GetTransactionCurrenciesQuery = { __typename?: 'Query', transactioncurrencies?: Array<{ __typename?: 'transactioncurrency', isocurrencycode?: string | null, transactioncurrencyid?: any | null } | null> | null }; +export type GetTransactionCurrenciesQuery = { __typename?: 'Query', transactioncurrencies: Array<{ __typename?: 'transactioncurrency', isocurrencycode: string | null, transactioncurrencyid: string | null } | null> | null }; export type GetOpportunityByLeadQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; -export type GetOpportunityByLeadQuery = { __typename?: 'Query', lead?: { __typename?: 'lead', evo_opportunityidData?: { __typename?: 'opportunity', label?: string | null, value?: any | null } | null } | null }; +export type GetOpportunityByLeadQuery = { __typename?: 'Query', lead: { __typename?: 'lead', evo_opportunityidData: { __typename?: 'opportunity', label: string | null, value: string | null } | null } | null }; export type GetLeadidByOpportunityQueryVariables = Exact<{ opportunityid: Scalars['Uuid']; }>; -export type GetLeadidByOpportunityQuery = { __typename?: 'Query', opportunity?: { __typename?: 'opportunity', evo_leadid?: any | null } | null }; +export type GetLeadidByOpportunityQuery = { __typename?: 'Query', opportunity: { __typename?: 'opportunity', evo_leadid: string | null } | null }; export type GetQuotesByLeadQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; -export type GetQuotesByLeadQuery = { __typename?: 'Query', quotes?: Array<{ __typename?: 'quote', label?: string | null, value?: any | null } | null> | null }; +export type GetQuotesByLeadQuery = { __typename?: 'Query', quotes: Array<{ __typename?: 'quote', label: string | null, value: string | null } | null> | null }; export type GetLeadUrlQueryVariables = Exact<{ id: Scalars['Uuid']; }>; -export type GetLeadUrlQuery = { __typename?: 'Query', entity?: { __typename?: 'lead', link?: string | null } | null }; +export type GetLeadUrlQuery = { __typename?: 'Query', entity: { __typename?: 'lead', link: string | null } | null }; export type GetOpportunityUrlQueryVariables = Exact<{ id: Scalars['Uuid']; }>; -export type GetOpportunityUrlQuery = { __typename?: 'Query', entity?: { __typename?: 'opportunity', link?: string | null } | null }; +export type GetOpportunityUrlQuery = { __typename?: 'Query', entity: { __typename?: 'opportunity', link: string | null } | null }; export type GetQuoteUrlQueryVariables = Exact<{ id: Scalars['Uuid']; }>; -export type GetQuoteUrlQuery = { __typename?: 'Query', entity?: { __typename?: 'quote', link?: string | null } | null }; +export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null }; export type GetCurrencyChangesQueryVariables = Exact<{ - currentDate?: InputMaybe; + currentDate: InputMaybe; }>; -export type GetCurrencyChangesQuery = { __typename?: 'Query', evo_currencychanges?: Array<{ __typename?: 'evo_currencychange', evo_currencychange?: any | null, evo_ref_transactioncurrency?: any | null } | null> | null }; +export type GetCurrencyChangesQuery = { __typename?: 'Query', evo_currencychanges: Array<{ __typename?: 'evo_currencychange', evo_currencychange: number | null, evo_ref_transactioncurrency: string | null } | null> | null }; export type GetCurrencyIsoCodeQueryVariables = Exact<{ id: Scalars['Uuid']; }>; -export type GetCurrencyIsoCodeQuery = { __typename?: 'Query', transactioncurrency?: { __typename?: 'transactioncurrency', isocurrencycode?: string | null } | null }; +export type GetCurrencyIsoCodeQuery = { __typename?: 'Query', transactioncurrency: { __typename?: 'transactioncurrency', isocurrencycode: string | null } | null }; export type GetRewardRulesQueryVariables = Exact<{ conditionId: Scalars['Uuid']; }>; -export type GetRewardRulesQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_calc_reward_rules?: number | null } | null }; +export type GetRewardRulesQuery = { __typename?: 'Query', evo_reward_condition: { __typename?: 'evo_reward_condition', evo_calc_reward_rules: number | null } | null }; export type GetAgentsDataFromQuoteQueryVariables = Exact<{ quoteId: Scalars['Uuid']; }>; -export type GetAgentsDataFromQuoteQuery = { __typename?: 'Query', quote?: { __typename?: 'quote', evo_supplier_accountid?: any | null, evo_dealer_person_accountid?: any | null, evo_dealer_reward_conditionid?: any | null, evo_dealer_reward_total?: any | null, evo_dealer_reward_summ?: any | null, evo_dealer_broker_accountid?: any | null, evo_dealer_broker_reward_conditionid?: any | null, evo_dealer_broker_reward_total?: any | null, evo_dealer_broker_reward_summ?: any | null, evo_agent_accountid?: any | null, evo_agent_reward_conditionid?: any | null, evo_agent_reward_total?: any | null, evo_agent_reward_summ?: any | null, evo_double_agent_accountid?: any | null, evo_double_agent_reward_conditionid?: any | null, evo_double_agent_reward_total?: any | null, evo_double_agent_reward_summ?: any | null, evo_broker_accountid?: any | null, evo_broker_reward_conditionid?: any | null, evo_broker_reward_total?: any | null, evo_broker_reward_summ?: any | null, evo_fin_department_accountid?: any | null, evo_fin_department_reward_conditionid?: any | null, evo_fin_department_reward_total?: any | null, evo_fin_department_reward_summ?: any | null } | null }; +export type GetAgentsDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_supplier_accountid: string | null, evo_dealer_person_accountid: string | null, evo_dealer_reward_conditionid: string | null, evo_dealer_reward_total: number | null, evo_dealer_reward_summ: number | null, evo_dealer_broker_accountid: string | null, evo_dealer_broker_reward_conditionid: string | null, evo_dealer_broker_reward_total: number | null, evo_dealer_broker_reward_summ: number | null, evo_agent_accountid: string | null, evo_agent_reward_conditionid: string | null, evo_agent_reward_total: number | null, evo_agent_reward_summ: number | null, evo_double_agent_accountid: string | null, evo_double_agent_reward_conditionid: string | null, evo_double_agent_reward_total: number | null, evo_double_agent_reward_summ: number | null, evo_broker_accountid: string | null, evo_broker_reward_conditionid: string | null, evo_broker_reward_total: number | null, evo_broker_reward_summ: number | null, evo_fin_department_accountid: string | null, evo_fin_department_reward_conditionid: string | null, evo_fin_department_reward_total: number | null, evo_fin_department_reward_summ: number | null } | null }; export type GetRewardConditionsQueryVariables = Exact<{ agentid: Scalars['Uuid']; - currentDate?: InputMaybe; + currentDate: InputMaybe; }>; -export type GetRewardConditionsQuery = { __typename?: 'Query', evo_reward_conditions?: Array<{ __typename?: 'evo_reward_condition', evo_reward_summ?: any | null, label?: string | null, value?: any | null } | null> | null }; +export type GetRewardConditionsQuery = { __typename?: 'Query', evo_reward_conditions: Array<{ __typename?: 'evo_reward_condition', evo_reward_summ: number | null, label: string | null, value: string | null } | null> | null }; export type GetRewardSummQueryVariables = Exact<{ conditionId: Scalars['Uuid']; }>; -export type GetRewardSummQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_reward_summ?: any | null } | null }; +export type GetRewardSummQuery = { __typename?: 'Query', evo_reward_condition: { __typename?: 'evo_reward_condition', evo_reward_summ: number | null } | null }; export type GetRewardConditionQueryVariables = Exact<{ conditionId: Scalars['Uuid']; }>; -export type GetRewardConditionQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_reward_summ?: any | null, evo_reduce_reward?: boolean | null, evo_min_reward_summ?: any | null } | null }; +export type GetRewardConditionQuery = { __typename?: 'Query', evo_reward_condition: { __typename?: 'evo_reward_condition', evo_reward_summ: number | null, evo_reduce_reward: boolean | null, evo_min_reward_summ: number | null } | null }; export type GetAgentAccountIdFromLeadQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; -export type GetAgentAccountIdFromLeadQuery = { __typename?: 'Query', lead?: { __typename?: 'lead', agentid?: any | null } | null }; +export type GetAgentAccountIdFromLeadQuery = { __typename?: 'Query', lead: { __typename?: 'lead', agentid: string | null } | null }; export type GetDoubleAgentAccountIdQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; -export type GetDoubleAgentAccountIdQuery = { __typename?: 'Query', lead?: { __typename?: 'lead', agentid?: any | null } | null }; +export type GetDoubleAgentAccountIdQuery = { __typename?: 'Query', lead: { __typename?: 'lead', agentid: string | null } | null }; export type GetBrokerAccountIdQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; -export type GetBrokerAccountIdQuery = { __typename?: 'Query', lead?: { __typename?: 'lead', agentid?: any | null } | null }; +export type GetBrokerAccountIdQuery = { __typename?: 'Query', lead: { __typename?: 'lead', agentid: string | null } | null }; export type GetFinDepartmentAccountIdQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; -export type GetFinDepartmentAccountIdQuery = { __typename?: 'Query', lead?: { __typename?: 'lead', agentid?: any | null } | null }; +export type GetFinDepartmentAccountIdQuery = { __typename?: 'Query', lead: { __typename?: 'lead', agentid: string | null } | null }; export type GetAgentQueryVariables = Exact<{ agentid: Scalars['Uuid']; }>; -export type GetAgentQuery = { __typename?: 'Query', agent?: { __typename?: 'account', label?: string | null, value?: any | null } | null }; +export type GetAgentQuery = { __typename?: 'Query', agent: { __typename?: 'account', label: string | null, value: string | null } | null }; export type GetRewardWithoutOtherAgentQueryVariables = Exact<{ conditionId: Scalars['Uuid']; }>; -export type GetRewardWithoutOtherAgentQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_agency_agreementidData?: { __typename?: 'evo_agency_agreement', evo_reward_without_other_agent?: boolean | null } | null } | null }; +export type GetRewardWithoutOtherAgentQuery = { __typename?: 'Query', evo_reward_condition: { __typename?: 'evo_reward_condition', evo_agency_agreementidData: { __typename?: 'evo_agency_agreement', evo_reward_without_other_agent: boolean | null } | null } | null }; export type GetDealerReturnLeasingQueryVariables = Exact<{ dealerId: Scalars['Uuid']; }>; -export type GetDealerReturnLeasingQuery = { __typename?: 'Query', dealer?: { __typename?: 'account', evo_return_leasing_dealer?: boolean | null } | null }; +export type GetDealerReturnLeasingQuery = { __typename?: 'Query', dealer: { __typename?: 'account', evo_return_leasing_dealer: boolean | null } | null }; export type GetDealerPersonQueryVariables = Exact<{ dealerId: Scalars['Uuid']; }>; -export type GetDealerPersonQuery = { __typename?: 'Query', salon_providers?: Array<{ __typename?: 'account', evo_inn?: string | null, evo_kpp?: string | null, label?: string | null, value?: any | null } | null> | null }; +export type GetDealerPersonQuery = { __typename?: 'Query', salon_providers: Array<{ __typename?: 'account', evo_inn: string | null, evo_kpp: string | null, label: string | null, value: string | null } | null> | null }; export type GetBrokerAccountIdFromDealerQueryVariables = Exact<{ dealerId: Scalars['Uuid']; }>; -export type GetBrokerAccountIdFromDealerQuery = { __typename?: 'Query', dealer?: { __typename?: 'account', evo_broker_accountid?: any | null } | null }; +export type GetBrokerAccountIdFromDealerQuery = { __typename?: 'Query', dealer: { __typename?: 'account', evo_broker_accountid: string | null } | null }; diff --git a/process/init/set-values/reactions.ts b/process/init/set-values/reactions.ts index 7422bce..f62d6b8 100644 --- a/process/init/set-values/reactions.ts +++ b/process/init/set-values/reactions.ts @@ -28,10 +28,11 @@ export default function setInitialValuesReactions({ store, apolloClient }: React const transactioncurrency_rub = transactioncurrencies?.find( (x) => x?.isocurrencycode === 'RUB' ); - - $calculation - .element('selectSupplierCurrency') - .setValue(transactioncurrency_rub?.transactioncurrencyid); + if (transactioncurrency_rub) { + $calculation + .element('selectSupplierCurrency') + .setValue(transactioncurrency_rub.transactioncurrencyid); + } } ); } diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts index 4cef9a3..06d2faa 100644 --- a/process/lead-opportunity/reactions/common.ts +++ b/process/lead-opportunity/reactions/common.ts @@ -98,7 +98,9 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex } if (opportunityid) { - const { data } = await apolloClient.query< + const { + data: { opportunity }, + } = await apolloClient.query< CRMTypes.GetLeadidByOpportunityQuery, CRMTypes.GetLeadidByOpportunityQueryVariables >({ @@ -108,7 +110,11 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex }, }); - $calculation.element('selectLead').setValue(data.opportunity?.evo_leadid); + if (opportunity?.evo_leadid) { + $calculation.element('selectLead').setValue(opportunity.evo_leadid); + } else { + $calculation.element('selectLead').resetValue(); + } } } ); diff --git a/process/supplier-agent/get-kp-values/get-sums.ts b/process/supplier-agent/get-kp-values/get-sums.ts index 929dd8b..bc8056c 100644 --- a/process/supplier-agent/get-kp-values/get-sums.ts +++ b/process/supplier-agent/get-kp-values/get-sums.ts @@ -12,11 +12,27 @@ const QUERY_GET_REWARD_RULES = gql` } `; +type QuoteSumFields = + | 'evo_agent_reward_summ' + | 'evo_broker_reward_summ' + | 'evo_dealer_reward_summ' + | 'evo_double_agent_reward_summ' + | 'evo_dealer_broker_reward_summ' + | 'evo_fin_department_reward_summ'; + +type QuoteTotalFields = + | 'evo_agent_reward_total' + | 'evo_broker_reward_total' + | 'evo_dealer_reward_total' + | 'evo_double_agent_reward_total' + | 'evo_dealer_broker_reward_total' + | 'evo_fin_department_reward_total'; + async function getRewardSum( conditionId: string | null | undefined, quote: Quote, - quoteRewardSummField: keyof Quote, - quoteRewardTotalField: keyof Quote + quoteRewardSummField: keyof Pick, + quoteRewardTotalField: keyof Pick ) { if (!conditionId) return 0; @@ -87,11 +103,11 @@ export default async function getSums(quote: Quote) { ]); return { - dealerRewardSumm, - dealerBrokerRewardSumm, - indAgentRewardSumm, - calcDoubleAgentRewardSumm, - calcBrokerRewardSum, - finDepartmentRewardSumm, + dealerRewardSumm: dealerRewardSumm ?? 0, + dealerBrokerRewardSumm: dealerBrokerRewardSumm ?? 0, + indAgentRewardSumm: indAgentRewardSumm ?? 0, + calcDoubleAgentRewardSumm: calcDoubleAgentRewardSumm ?? 0, + calcBrokerRewardSum: calcBrokerRewardSum ?? 0, + finDepartmentRewardSumm: finDepartmentRewardSumm ?? 0, }; } diff --git a/process/supplier-agent/get-kp-values/index.ts b/process/supplier-agent/get-kp-values/index.ts index 09d2d84..37372d4 100644 --- a/process/supplier-agent/get-kp-values/index.ts +++ b/process/supplier-agent/get-kp-values/index.ts @@ -38,17 +38,17 @@ const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql` export type Quote = NonNullable; -type InputData = { +type GetSupplierAgentsFromKP = { quoteId: NonNullable; }; -type ResultData = { +type GetSupplierAgentsFromKPResult = { values: Partial; }; export default async function getSupplierAgentsDataFromKP({ quoteId, -}: InputData): Promise { +}: GetSupplierAgentsFromKP): Promise { const apolloClient = initializeApollo(); const { diff --git a/process/supplier-agent/lib/create-reactions.ts b/process/supplier-agent/lib/create-reactions.ts index 30bffa0..ad91e31 100644 --- a/process/supplier-agent/lib/create-reactions.ts +++ b/process/supplier-agent/lib/create-reactions.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import type { ApolloClient } from '@apollo/client'; import { gql } from '@apollo/client'; -import type * as Values from 'Components/Calculation/config/map/values'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import type * as CRMTypes from 'graphql/crm.types'; @@ -10,6 +9,7 @@ import type RootStore from 'stores/root'; import ValidationHelper from 'stores/validation/helper'; import { normalizeOptions } from 'tools/entity'; import { makeDisposable } from 'tools/mobx'; +import type { AgentsFields, AgentsRewardConditionsFields, AgentsSumFields } from './types'; dayjs.extend(utc); @@ -33,8 +33,8 @@ export function fillAgentRewardReaction( store: RootStore, apolloClient: ApolloClient, agentParams: { - agentField: Values.Elements; - rewardConditionField: Values.Elements; + agentField: AgentsFields; + rewardConditionField: AgentsRewardConditionsFields; } ) { const { $calculation, $process } = store; @@ -42,8 +42,8 @@ export function fillAgentRewardReaction( reaction( () => $calculation.element(agentField).getValue(), - async (agentId) => { - if (!agentId) { + async (agentid) => { + if (!agentid) { $calculation.element(rewardConditionField).reset(); return; @@ -56,7 +56,7 @@ export function fillAgentRewardReaction( >({ query: QUERY_GET_REWARD_CONDITIONS, variables: { - agentid: agentId, + agentid, currentDate: dayjs().toISOString(), }, }); @@ -82,8 +82,8 @@ export function fillAgentRewardSummReaction( store: RootStore, apolloClient: ApolloClient, agentParams: { - rewardConditionField: Values.Elements; - rewardSummField: Values.Elements; + rewardConditionField: AgentsRewardConditionsFields; + rewardSummField: AgentsSumFields; } ) { const { $calculation, $process } = store; @@ -112,7 +112,11 @@ export function fillAgentRewardSummReaction( }, }); - $calculation.element(rewardSummField).setValue(evo_reward_condition?.evo_reward_summ); + if (evo_reward_condition?.evo_reward_summ) { + $calculation.element(rewardSummField).setValue(evo_reward_condition.evo_reward_summ); + } else { + $calculation.element(rewardSummField).resetValue(); + } } ), () => $process.has('LoadKP') @@ -144,8 +148,8 @@ export function validateAgentRewardSumm( store: RootStore, apolloClient: ApolloClient, agentParams: { - rewardConditionField: Values.Elements; - rewardSummField: Values.Elements; + rewardConditionField: AgentsRewardConditionsFields; + rewardSummField: AgentsSumFields; } ) { const { $calculation } = store; @@ -175,42 +179,52 @@ export function validateAgentRewardSumm( }, }); - $calculation - .element(rewardSummField) - .validate({ - invalid: - evo_reward_condition?.evo_reward_summ && - rewardSumm > evo_reward_condition.evo_reward_summ, - message: 'Вознаграждение указано больше условия по агентскому договору!', - }) - .err((removeError) => { - validationHelper.add(removeError); - }); + if (!evo_reward_condition) { + validationHelper.removeErrors(); - $calculation - .element(rewardSummField) - .validate({ - invalid: - !evo_reward_condition?.evo_reduce_reward && - evo_reward_condition?.evo_reward_summ && - rewardSumm < evo_reward_condition.evo_reward_summ, - message: 'Вознаграждение указано меньше условия по агентскому договору!', - }) - .err((removeError) => { - validationHelper.add(removeError); - }); + return; + } - $calculation - .element(rewardSummField) - .validate({ - invalid: - evo_reward_condition?.evo_min_reward_summ && - rewardSumm < evo_reward_condition?.evo_min_reward_summ, - message: 'Вознаграждение указано меньше условия по агентскому договору!', - }) - .err((removeError) => { - validationHelper.add(removeError); - }); + if (evo_reward_condition.evo_reward_summ) { + $calculation + .element(rewardSummField) + .validate({ + invalid: rewardSumm > evo_reward_condition?.evo_reward_summ, + message: 'Вознаграждение указано больше условия по агентскому договору!', + }) + .err((removeError) => { + validationHelper.add(removeError); + }); + } + + if ( + evo_reward_condition?.evo_reduce_reward !== null && + evo_reward_condition.evo_reward_summ + ) { + $calculation + .element(rewardSummField) + .validate({ + invalid: + evo_reward_condition.evo_reduce_reward === false && + rewardSumm < evo_reward_condition.evo_reward_summ, + message: 'Вознаграждение указано меньше условия по агентскому договору!', + }) + .err((removeError) => { + validationHelper.add(removeError); + }); + } + + if (evo_reward_condition?.evo_min_reward_summ !== null) { + $calculation + .element(rewardSummField) + .validate({ + invalid: rewardSumm < evo_reward_condition?.evo_min_reward_summ, + message: 'Вознаграждение указано меньше условия по агентскому договору!', + }) + .err((removeError) => { + validationHelper.add(removeError); + }); + } } ); } diff --git a/process/supplier-agent/lib/types.ts b/process/supplier-agent/lib/types.ts new file mode 100644 index 0000000..e8e213f --- /dev/null +++ b/process/supplier-agent/lib/types.ts @@ -0,0 +1,29 @@ +import type * as Values from 'Components/Calculation/config/map/values'; + +export type AgentsFields = Extract< + Values.Elements, + | 'selectIndAgent' + | 'selectCalcDoubleAgent' + | 'selectCalcBroker' + | 'selectCalcFinDepartment' + | 'selectDealerPerson' + | 'selectDealerBroker' +>; +export type AgentsRewardConditionsFields = Extract< + Values.Elements, + | 'selectIndAgentRewardCondition' + | 'selectCalcDoubleAgentRewardCondition' + | 'selectCalcBrokerRewardCondition' + | 'selectFinDepartmentRewardCondtion' + | 'selectDealerRewardCondition' + | 'selectDealerBrokerRewardCondition' +>; +export type AgentsSumFields = Extract< + Values.Elements, + | 'tbxIndAgentRewardSumm' + | 'tbxCalcDoubleAgentRewardSumm' + | 'tbxCalcBrokerRewardSum' + | 'tbxFinDepartmentRewardSumm' + | 'tbxDealerRewardSumm' + | 'tbxDealerBrokerRewardSumm' +>; diff --git a/process/supplier-agent/reactions/supplier.ts b/process/supplier-agent/reactions/supplier.ts index a8b09d8..d541688 100644 --- a/process/supplier-agent/reactions/supplier.ts +++ b/process/supplier-agent/reactions/supplier.ts @@ -55,7 +55,7 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { }, }); - if (salon_providers?.length) { + if (salon_providers && salon_providers.length > 0) { $calculation.element('selectDealerPerson').setOptions( normalizeOptions( salon_providers.map((dp) => ({ @@ -65,9 +65,12 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { ) ); - if (!$process.has('LoadKP')) { - $calculation.element('selectDealerPerson').setValue(salon_providers[0]?.value); + const value = salon_providers.at(0)?.value; + if (!$process.has('LoadKP') && value) { + $calculation.element('selectDealerPerson').setValue(value); } + } else { + $calculation.element('selectDealerPerson').reset(); } } );