84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
/* eslint-disable canonical/sort-keys */
|
|
import type { GetQuoteInputData, GetQuoteProcessData } from '../../load-kp/types';
|
|
import getSums from './get-sums';
|
|
import initializeApollo from '@/apollo/client';
|
|
import defaultValues from '@/config/default-values';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import { gql } from '@apollo/client';
|
|
|
|
const QUERY_GET_QUOTE_AGENTS_DATA = gql`
|
|
query GetQuoteAgentsData($quoteId: Uuid!) {
|
|
quote(quoteId: $quoteId) {
|
|
evo_supplier_accountid
|
|
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 async function getKPData({
|
|
values: { quote: quoteId },
|
|
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
|
const apolloClient = initializeApollo();
|
|
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetQuoteAgentsDataDocument,
|
|
variables: {
|
|
quoteId,
|
|
},
|
|
});
|
|
|
|
const sums = await getSums(quote);
|
|
|
|
return {
|
|
values: {
|
|
dealer: quote?.evo_supplier_accountid,
|
|
dealerBroker: quote?.evo_dealer_broker_accountid,
|
|
dealerBrokerRewardCondition: quote?.evo_dealer_broker_reward_conditionid,
|
|
dealerBrokerRewardSumm: sums?.dealerBrokerRewardSumm ?? defaultValues.dealerBrokerRewardSumm,
|
|
dealerPerson: quote?.evo_dealer_person_accountid,
|
|
dealerRewardCondition: quote?.evo_dealer_reward_conditionid,
|
|
dealerRewardSumm: sums?.dealerRewardSumm ?? defaultValues.dealerRewardSumm,
|
|
|
|
calcBroker: quote?.evo_broker_accountid,
|
|
calcBrokerRewardCondition: quote?.evo_broker_reward_conditionid,
|
|
calcBrokerRewardSum: sums?.calcBrokerRewardSum ?? defaultValues.calcBrokerRewardSum,
|
|
calcDoubleAgent: quote?.evo_double_agent_accountid,
|
|
calcDoubleAgentRewardCondition: quote?.evo_double_agent_reward_conditionid,
|
|
calcDoubleAgentRewardSumm:
|
|
sums?.calcDoubleAgentRewardSumm ?? defaultValues.calcDoubleAgentRewardSumm,
|
|
calcFinDepartment: quote?.evo_fin_department_accountid,
|
|
finDepartmentRewardCondtion: quote?.evo_fin_department_reward_conditionid,
|
|
finDepartmentRewardSumm:
|
|
sums?.finDepartmentRewardSumm ?? defaultValues.finDepartmentRewardSumm,
|
|
indAgent: quote?.evo_agent_accountid,
|
|
indAgentRewardCondition: quote?.evo_agent_reward_conditionid,
|
|
indAgentRewardSumm: sums?.indAgentRewardSumm ?? defaultValues.indAgentRewardSumm,
|
|
},
|
|
};
|
|
}
|