87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
|
|
import helper from './lib/helper';
|
|
import initializeApollo from '@/apollo/client';
|
|
import defaultValues from '@/config/default-values';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import { gql } from '@apollo/client';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const QUERY_GET_QUOTE_CONFIGURATOR_DATA = gql`
|
|
query GetQuoteConfiguratorData($quoteId: Uuid!) {
|
|
quote(quoteId: $quoteId) {
|
|
evo_baseproductid
|
|
evo_client_typeid
|
|
evo_msfo_irr
|
|
evo_delivery_time
|
|
evo_first_payment_perc
|
|
evo_last_payment_perc
|
|
evo_leasingobject_typeid
|
|
evo_leasingobject_used
|
|
evo_period
|
|
evo_accept_period
|
|
evo_rateid
|
|
}
|
|
}
|
|
`;
|
|
|
|
export async function getKPData({
|
|
values: { quote: quoteId, recalcWithRevision },
|
|
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
|
const apolloClient = initializeApollo();
|
|
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetQuoteConfiguratorDataDocument,
|
|
variables: {
|
|
quoteId,
|
|
},
|
|
});
|
|
|
|
const leasingPeriod = recalcWithRevision
|
|
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
|
|
: quote?.evo_period ?? 0;
|
|
|
|
const { getTarifs, getRates } = helper({ apolloClient });
|
|
|
|
let tarif = defaultValues.tarif;
|
|
if (
|
|
quote?.evo_delivery_time !== null &&
|
|
quote?.evo_delivery_time !== undefined &&
|
|
quote?.evo_first_payment_perc !== undefined &&
|
|
quote?.evo_first_payment_perc !== null &&
|
|
quote?.evo_last_payment_perc !== undefined &&
|
|
quote?.evo_last_payment_perc !== null &&
|
|
quote?.evo_leasingobject_typeid !== undefined &&
|
|
quote?.evo_leasingobject_typeid !== null &&
|
|
quote?.evo_leasingobject_used !== undefined &&
|
|
quote?.evo_leasingobject_used !== null
|
|
) {
|
|
const { evo_tarif } = await getTarifs({
|
|
deliveryTime: quote?.evo_delivery_time,
|
|
firstPaymentPerc: quote?.evo_first_payment_perc,
|
|
lastPaymentPerc: quote?.evo_last_payment_perc,
|
|
leaseObjectType: quote?.evo_leasingobject_typeid,
|
|
leaseObjectUsed: quote?.evo_leasingobject_used,
|
|
leasingPeriod,
|
|
product: quote?.evo_baseproductid,
|
|
});
|
|
|
|
if (evo_tarif?.evo_tarifid) {
|
|
tarif = evo_tarif.evo_tarifid;
|
|
}
|
|
}
|
|
|
|
const { evo_rate } = await getRates({ tarif });
|
|
|
|
return {
|
|
values: {
|
|
IRR_Perc: quote?.evo_msfo_irr ?? defaultValues.IRR_Perc,
|
|
clientType: quote?.evo_client_typeid,
|
|
product: quote?.evo_baseproductid,
|
|
rate: evo_rate?.evo_rateid ?? defaultValues.rate,
|
|
tarif,
|
|
},
|
|
};
|
|
}
|