get sums from kp
This commit is contained in:
parent
8960773d43
commit
6b3c01cd84
@ -238,12 +238,19 @@ export type GetCurrencyIsoCodeQueryVariables = Exact<{
|
||||
|
||||
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 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_broker_accountid?: any | null, evo_dealer_broker_reward_conditionid?: any | null, evo_dealer_broker_reward_total?: any | null, evo_agent_accountid?: any | null, evo_agent_reward_conditionid?: any | null, evo_agent_reward_total?: any | null, evo_double_agent_accountid?: any | null, evo_double_agent_reward_conditionid?: any | null, evo_double_agent_reward_total?: any | null, evo_broker_accountid?: any | null, evo_broker_reward_conditionid?: any | null, evo_broker_reward_total?: any | null, evo_fin_department_accountid?: any | null, evo_fin_department_reward_conditionid?: any | null, evo_fin_department_reward_total?: any | null } | null };
|
||||
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 GetRewardConditionsQueryVariables = Exact<{
|
||||
agentid: Scalars['Uuid'];
|
||||
@ -260,13 +267,6 @@ export type GetRewardSummQueryVariables = Exact<{
|
||||
|
||||
export type GetRewardSummQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_reward_summ?: any | 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 GetAgentAccountIdFromLeadQueryVariables = Exact<{
|
||||
leadid: Scalars['Uuid'];
|
||||
}>;
|
||||
@ -302,6 +302,13 @@ export type GetAgentQueryVariables = Exact<{
|
||||
|
||||
export type GetAgentQuery = { __typename?: 'Query', agent?: { __typename?: 'account', label?: string | null, value?: any | 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, evo_calc_reward_rules?: number | null } | null };
|
||||
|
||||
export type GetRewardWithoutOtherAgentQueryVariables = Exact<{
|
||||
conditionId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
97
process/supplier-agent/get-kp-values/get-sums.ts
Normal file
97
process/supplier-agent/get-kp-values/get-sums.ts
Normal file
@ -0,0 +1,97 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import type { Quote } from './index';
|
||||
|
||||
const QUERY_GET_REWARD_RULES = gql`
|
||||
query GetRewardRules($conditionId: Uuid!) {
|
||||
evo_reward_condition(evo_reward_conditionid: $conditionId) {
|
||||
evo_calc_reward_rules
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
async function getRewardSum(
|
||||
conditionId: string | null | undefined,
|
||||
quote: Quote,
|
||||
quoteRewardSummField: keyof Quote,
|
||||
quoteRewardTotalField: keyof Quote
|
||||
) {
|
||||
if (!conditionId) return 0;
|
||||
|
||||
const apolloClient = initializeApollo();
|
||||
const {
|
||||
data: { evo_reward_condition },
|
||||
} = await apolloClient.query<CRMTypes.GetRewardRulesQuery, CRMTypes.GetRewardRulesQueryVariables>(
|
||||
{
|
||||
query: QUERY_GET_REWARD_RULES,
|
||||
variables: {
|
||||
conditionId,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (evo_reward_condition?.evo_calc_reward_rules === 100_000_001) {
|
||||
return quote[quoteRewardSummField];
|
||||
}
|
||||
|
||||
return quote[quoteRewardTotalField];
|
||||
}
|
||||
|
||||
export default async function getSums(quote: Quote) {
|
||||
const [
|
||||
dealerRewardSumm,
|
||||
dealerBrokerRewardSumm,
|
||||
indAgentRewardSumm,
|
||||
calcDoubleAgentRewardSumm,
|
||||
calcBrokerRewardSum,
|
||||
finDepartmentRewardSumm,
|
||||
] = await Promise.all([
|
||||
getRewardSum(
|
||||
quote?.evo_dealer_reward_conditionid,
|
||||
quote,
|
||||
'evo_dealer_reward_summ',
|
||||
'evo_dealer_reward_total'
|
||||
),
|
||||
getRewardSum(
|
||||
quote?.evo_dealer_broker_reward_conditionid,
|
||||
quote,
|
||||
'evo_dealer_broker_reward_summ',
|
||||
'evo_dealer_broker_reward_total'
|
||||
),
|
||||
getRewardSum(
|
||||
quote?.evo_agent_reward_conditionid,
|
||||
quote,
|
||||
'evo_agent_reward_summ',
|
||||
'evo_agent_reward_total'
|
||||
),
|
||||
getRewardSum(
|
||||
quote.evo_double_agent_reward_conditionid,
|
||||
quote,
|
||||
'evo_double_agent_reward_summ',
|
||||
'evo_double_agent_reward_total'
|
||||
),
|
||||
getRewardSum(
|
||||
quote.evo_broker_reward_conditionid,
|
||||
quote,
|
||||
'evo_broker_reward_summ',
|
||||
'evo_broker_reward_total'
|
||||
),
|
||||
getRewardSum(
|
||||
quote.evo_fin_department_reward_conditionid,
|
||||
quote,
|
||||
'evo_fin_department_reward_summ',
|
||||
'evo_fin_department_reward_total'
|
||||
),
|
||||
]);
|
||||
|
||||
return {
|
||||
dealerRewardSumm,
|
||||
dealerBrokerRewardSumm,
|
||||
indAgentRewardSumm,
|
||||
calcDoubleAgentRewardSumm,
|
||||
calcBrokerRewardSum,
|
||||
finDepartmentRewardSumm,
|
||||
};
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import type {
|
||||
GetAgentsDataFromQuoteQuery,
|
||||
GetAgentsDataFromQuoteQueryVariables,
|
||||
} from 'graphql/crm.types';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import type { CalculationValues } from 'stores/calculation/values/types';
|
||||
import getSums from './get-sums';
|
||||
|
||||
const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||
query GetAgentsDataFromQuote($quoteId: Uuid!) {
|
||||
@ -13,55 +11,93 @@ const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||
evo_dealer_person_accountid
|
||||
evo_dealer_reward_conditionid
|
||||
evo_dealer_reward_total
|
||||
evo_dealer_reward_summ
|
||||
evo_dealer_broker_accountid
|
||||
evo_dealer_broker_reward_conditionid
|
||||
evo_dealer_broker_reward_total
|
||||
evo_dealer_broker_reward_summ
|
||||
evo_agent_accountid
|
||||
evo_agent_reward_conditionid
|
||||
evo_agent_reward_total
|
||||
evo_agent_reward_summ
|
||||
evo_double_agent_accountid
|
||||
evo_double_agent_reward_conditionid
|
||||
evo_double_agent_reward_total
|
||||
evo_double_agent_reward_summ
|
||||
evo_broker_accountid
|
||||
evo_broker_reward_conditionid
|
||||
evo_broker_reward_total
|
||||
evo_broker_reward_summ
|
||||
evo_fin_department_accountid
|
||||
evo_fin_department_reward_conditionid
|
||||
evo_fin_department_reward_total
|
||||
evo_fin_department_reward_summ
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export type Quote = NonNullable<CRMTypes.GetAgentsDataFromQuoteQuery['quote']>;
|
||||
|
||||
type InputData = {
|
||||
quoteId: NonNullable<CalculationValues['quote']>;
|
||||
};
|
||||
|
||||
type SupplierData = {
|
||||
type ResultData = {
|
||||
values: Partial<CalculationValues>;
|
||||
};
|
||||
|
||||
export default async function getSupplierAgentsDataFromKP({
|
||||
quoteId,
|
||||
}: InputData): Promise<SupplierData> {
|
||||
}: InputData): Promise<ResultData> {
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
const {
|
||||
data: { quote },
|
||||
} = await apolloClient.query<GetAgentsDataFromQuoteQuery, GetAgentsDataFromQuoteQueryVariables>({
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetAgentsDataFromQuoteQuery,
|
||||
CRMTypes.GetAgentsDataFromQuoteQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_AGENTS_DATA_FROM_QUOTE,
|
||||
variables: {
|
||||
quoteId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!quote) {
|
||||
throw new Error('Quote is empty');
|
||||
}
|
||||
|
||||
const {
|
||||
dealerRewardSumm,
|
||||
dealerBrokerRewardSumm,
|
||||
indAgentRewardSumm,
|
||||
calcDoubleAgentRewardSumm,
|
||||
calcBrokerRewardSum,
|
||||
finDepartmentRewardSumm,
|
||||
} = await getSums(quote);
|
||||
|
||||
return {
|
||||
values: {
|
||||
dealer: quote?.evo_supplier_accountid,
|
||||
dealerPerson: quote?.evo_dealer_person_accountid,
|
||||
dealerRewardCondition: quote?.evo_dealer_reward_conditionid,
|
||||
dealerRewardSumm,
|
||||
dealerBroker: quote?.evo_dealer_broker_accountid,
|
||||
dealerBrokerRewardCondition: quote?.evo_dealer_broker_reward_conditionid,
|
||||
dealerBrokerRewardSumm,
|
||||
|
||||
indAgent: quote?.evo_agent_accountid,
|
||||
indAgentRewardCondition: quote?.evo_agent_reward_conditionid,
|
||||
indAgentRewardSumm,
|
||||
calcDoubleAgent: quote?.evo_double_agent_accountid,
|
||||
calcDoubleAgentRewardCondition: quote?.evo_double_agent_reward_conditionid,
|
||||
calcDoubleAgentRewardSumm,
|
||||
calcBroker: quote?.evo_broker_accountid,
|
||||
calcBrokerRewardCondition: quote?.evo_broker_reward_conditionid,
|
||||
calcBrokerRewardSum,
|
||||
calcFinDepartment: quote?.evo_fin_department_accountid,
|
||||
finDepartmentRewardCondtion: quote?.evo_fin_department_reward_conditionid,
|
||||
finDepartmentRewardSumm,
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import defaultValues from 'config/default-values';
|
||||
import ValuesSchema from 'config/schema/values';
|
||||
import getSupplierAgentsDataFromKP from 'process/supplier-agent/get-data-from-kp';
|
||||
import getSupplierAgentsDataFromKP from 'process/supplier-agent/get-kp-values';
|
||||
import { z } from 'zod';
|
||||
import { t } from '../server';
|
||||
|
||||
@ -24,11 +24,7 @@ const quoteRouter = t.router({
|
||||
});
|
||||
|
||||
return {
|
||||
values: {
|
||||
...defaultValues,
|
||||
...input.values,
|
||||
...values,
|
||||
},
|
||||
values: Object.assign(defaultValues, values),
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user