process/configurator: add getCreditRate function & use in get-kp-data
This commit is contained in:
parent
8dbcf4bb7f
commit
475e9a05ae
@ -21,7 +21,7 @@ export async function getKPData({
|
||||
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
|
||||
: quote?.evo_period ?? 0;
|
||||
|
||||
const { getTarifs, getRates, getPriceChange } = helper({ apolloClient });
|
||||
const { getTarifs, getRates, getPriceChange, getCreditRate } = helper({ apolloClient });
|
||||
|
||||
let tarif = defaultValues.tarif;
|
||||
let evo_tarif: unknown = null;
|
||||
@ -106,6 +106,8 @@ export async function getKPData({
|
||||
tarif,
|
||||
});
|
||||
|
||||
const creditRate = await getCreditRate({ rate: evo_rate?.evo_rateid ?? null });
|
||||
|
||||
return {
|
||||
options: {
|
||||
selectTarif: evo_tarif ? normalizeOptions([evo_tarif]) : [],
|
||||
@ -113,6 +115,7 @@ export async function getKPData({
|
||||
values: {
|
||||
IRR_Perc: quote?.evo_msfo_irr ?? defaultValues.IRR_Perc,
|
||||
clientType: quote?.evo_client_typeid,
|
||||
creditRate,
|
||||
floatingRate: quote?.evo_floating_rate ?? false,
|
||||
irrInfo,
|
||||
maxPriceChange,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
import defaultValues from '@/config/default-values';
|
||||
import { RATE } from '@/constants/values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import type { CalculationValues } from '@/stores/calculation/values/types';
|
||||
@ -22,6 +23,8 @@ type GetTarifInputValues = Pick<
|
||||
|
||||
type GetRatesInputValues = Pick<CalculationValues, 'tarif'>;
|
||||
|
||||
type GetCreditRateInputValues = Pick<CalculationValues, 'rate'>;
|
||||
|
||||
type GetPriceChangeInputValues = Pick<
|
||||
CalculationValues,
|
||||
| 'addEquipmentPrice'
|
||||
@ -34,6 +37,22 @@ type GetPriceChangeInputValues = Pick<
|
||||
|
||||
export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloClient'>) {
|
||||
return {
|
||||
async getCreditRate({ rate: rateId }: GetCreditRateInputValues) {
|
||||
if (!rateId) return RATE;
|
||||
|
||||
const {
|
||||
data: { evo_rate },
|
||||
} = await apolloClient.query({
|
||||
fetchPolicy: 'network-only',
|
||||
query: CRMTypes.GetRateDocument,
|
||||
variables: {
|
||||
rateId,
|
||||
},
|
||||
});
|
||||
|
||||
return evo_rate?.evo_base_rate ?? RATE;
|
||||
},
|
||||
|
||||
async getPriceChange({
|
||||
discountRub,
|
||||
importProgramSum,
|
||||
|
||||
@ -10,7 +10,7 @@ export default function valuesReactions({ store, apolloClient, trpcClient }: Pro
|
||||
let abortController = new AbortController();
|
||||
const { $calculation, $process } = store;
|
||||
|
||||
const { getRates, getPriceChange } = helper({ apolloClient });
|
||||
const { getRates, getPriceChange, getCreditRate } = helper({ apolloClient });
|
||||
|
||||
disposableDebouncedReaction(
|
||||
() => $process.has('LoadKP'),
|
||||
@ -123,32 +123,13 @@ export default function valuesReactions({ store, apolloClient, trpcClient }: Pro
|
||||
}
|
||||
);
|
||||
|
||||
reaction(
|
||||
disposableReaction(
|
||||
() => $process.has('LoadKP'),
|
||||
() => $calculation.element('selectRate').getValue(),
|
||||
async (rateId) => {
|
||||
if (!rateId) {
|
||||
$calculation.element('tbxCreditRate').resetValue();
|
||||
async (rate) => {
|
||||
const creditRate = await getCreditRate({ rate });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
data: { evo_rate },
|
||||
} = await apolloClient.query({
|
||||
fetchPolicy: 'network-only',
|
||||
query: CRMTypes.GetRateDocument,
|
||||
variables: {
|
||||
rateId,
|
||||
},
|
||||
});
|
||||
|
||||
if (evo_rate?.evo_base_rate === null || evo_rate?.evo_base_rate === undefined) {
|
||||
$calculation.element('tbxCreditRate').resetValue();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$calculation.element('tbxCreditRate').setValue(evo_rate?.evo_base_rate);
|
||||
$calculation.element('tbxCreditRate').setValue(creditRate);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user