typescript: replace graphql-codegen 'any' types

This commit is contained in:
Chika 2022-11-05 13:10:07 +03:00
parent 0569d45972
commit 96ab658f93
10 changed files with 187 additions and 109 deletions

View File

@ -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'

View File

@ -21,7 +21,7 @@ const CurrencyAddon = observer(() => {
CRMTypes.GetCurrencySymbolQueryVariables
>(QUERY_GET_CURRENCY_SYMBOL, {
variables: {
currencyid,
currencyid: currencyid!,
},
skip: !currencyid,
});

View File

@ -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<Scalars['DateTime']>;
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
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<Array<Scalars['Int']> | Scalars['Int']>;
evo_account_type: InputMaybe<Array<Scalars['Int']> | 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<Scalars['DateTime']>;
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
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<Scalars['DateTime']>;
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
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<Scalars['String']>;
domainname: InputMaybe<Scalars['String']>;
}>;
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<Scalars['DateTime']>;
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
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<Scalars['DateTime']>;
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
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 };

View File

@ -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);
}
}
);
}

View File

@ -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();
}
}
}
);

View File

@ -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<Quote, QuoteSumFields>,
quoteRewardTotalField: keyof Pick<Quote, QuoteTotalFields>
) {
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,
};
}

View File

@ -38,17 +38,17 @@ const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
export type Quote = NonNullable<CRMTypes.GetAgentsDataFromQuoteQuery['quote']>;
type InputData = {
type GetSupplierAgentsFromKP = {
quoteId: NonNullable<CalculationValues['quote']>;
};
type ResultData = {
type GetSupplierAgentsFromKPResult = {
values: Partial<CalculationValues>;
};
export default async function getSupplierAgentsDataFromKP({
quoteId,
}: InputData): Promise<ResultData> {
}: GetSupplierAgentsFromKP): Promise<GetSupplierAgentsFromKPResult> {
const apolloClient = initializeApollo();
const {

View File

@ -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<object>,
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<object>,
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<object>,
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);
});
}
}
);
}

View File

@ -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'
>;

View File

@ -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();
}
}
);