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