process/recalc: move priceChange logic to configurator
This commit is contained in:
parent
7df69f92e8
commit
5b847ffa07
@ -1,8 +1,11 @@
|
||||
/* eslint-disable complexity */
|
||||
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 { getKPData as getKPDataPrice } from '@/process/price/get-kp-data';
|
||||
import { getKPData as getKPDataSubsidy } from '@/process/subsidy/get-kp-data';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@ -24,9 +27,8 @@ const QUERY_GET_QUOTE_CONFIGURATOR_DATA = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export async function getKPData({
|
||||
values: { quote: quoteId, recalcWithRevision },
|
||||
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
||||
export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
||||
const { quote: quoteId, recalcWithRevision } = values;
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
const {
|
||||
@ -42,7 +44,7 @@ export async function getKPData({
|
||||
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
|
||||
: quote?.evo_period ?? 0;
|
||||
|
||||
const { getTarifs, getRates } = helper({ apolloClient });
|
||||
const { getTarifs, getRates, getPriceChange } = helper({ apolloClient });
|
||||
|
||||
let tarif = defaultValues.tarif;
|
||||
if (
|
||||
@ -74,10 +76,23 @@ export async function getKPData({
|
||||
|
||||
const { evo_rate } = await getRates({ tarif });
|
||||
|
||||
const kpDataPrice = await getKPDataPrice({ values });
|
||||
const kpDataSubsidy = await getKPDataSubsidy({ values });
|
||||
const { maxPriceChange, minPriceChange } = await getPriceChange({
|
||||
addEquipmentPrice: kpDataPrice.values?.addEquipmentPrice ?? defaultValues.addEquipmentPrice,
|
||||
discountRub: kpDataPrice.values?.discountRub ?? defaultValues.discountRub,
|
||||
importProgramSum: kpDataSubsidy.values?.importProgramSum ?? defaultValues.importProgramSum,
|
||||
leaseObjectType: quote?.evo_leasingobject_typeid ?? defaultValues.leaseObjectType,
|
||||
plPriceRub: kpDataPrice.values?.plPriceRub ?? defaultValues.plPriceRub,
|
||||
recalcWithRevision,
|
||||
});
|
||||
|
||||
return {
|
||||
values: {
|
||||
IRR_Perc: quote?.evo_msfo_irr ?? defaultValues.IRR_Perc,
|
||||
clientType: quote?.evo_client_typeid,
|
||||
maxPriceChange,
|
||||
minPriceChange,
|
||||
product: quote?.evo_baseproductid,
|
||||
rate: evo_rate?.evo_rateid ?? defaultValues.rate,
|
||||
tarif,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import defaultValues from '@/config/default-values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import type { CalculationValues } from '@/stores/calculation/values/types';
|
||||
@ -17,8 +18,63 @@ type GetTarifInputValues = Pick<
|
||||
|
||||
type GetRatesInputValues = Pick<CalculationValues, 'tarif'>;
|
||||
|
||||
type GetPriceChangeInputValues = Pick<
|
||||
CalculationValues,
|
||||
| 'addEquipmentPrice'
|
||||
| 'discountRub'
|
||||
| 'importProgramSum'
|
||||
| 'leaseObjectType'
|
||||
| 'plPriceRub'
|
||||
| 'recalcWithRevision'
|
||||
>;
|
||||
|
||||
export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloClient'>) {
|
||||
return {
|
||||
async getPriceChange({
|
||||
discountRub,
|
||||
importProgramSum,
|
||||
addEquipmentPrice,
|
||||
plPriceRub,
|
||||
recalcWithRevision,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
}: GetPriceChangeInputValues) {
|
||||
if (recalcWithRevision) {
|
||||
return {
|
||||
maxPriceChange: defaultValues.maxPriceChange,
|
||||
minPriceChange: defaultValues.minPriceChange,
|
||||
};
|
||||
}
|
||||
|
||||
let evo_leasingobject_type: CRMTypes.GetLeaseObjectTypeQuery['evo_leasingobject_type'] = null;
|
||||
|
||||
if (leaseObjectTypeId) {
|
||||
const { data } = await apolloClient.query({
|
||||
query: CRMTypes.GetLeaseObjectTypeDocument,
|
||||
variables: { leaseObjectTypeId },
|
||||
});
|
||||
|
||||
({ evo_leasingobject_type } = data);
|
||||
}
|
||||
|
||||
const price = plPriceRub + addEquipmentPrice - importProgramSum;
|
||||
const maxPriceChange =
|
||||
price - discountRub < 800_000
|
||||
? price - discountRub + 50_000
|
||||
: (price - discountRub) *
|
||||
(evo_leasingobject_type?.evo_vehicle_type?.includes(100_000_001) ||
|
||||
evo_leasingobject_type?.evo_vehicle_type?.includes(100_000_005)
|
||||
? 1.01
|
||||
: 1.05);
|
||||
|
||||
const minPriceChange =
|
||||
price - discountRub < 800_000 ? price - discountRub - 50_000 : (price - discountRub) * 0.95;
|
||||
|
||||
return {
|
||||
maxPriceChange,
|
||||
minPriceChange,
|
||||
};
|
||||
},
|
||||
|
||||
async getRates({ tarif: tarifId }: GetRatesInputValues) {
|
||||
const currentDate = dayjs().utc(false).toISOString();
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ dayjs.extend(utc);
|
||||
export default function valuesReactions({ store, apolloClient }: ProcessContext) {
|
||||
const { $calculation, $process } = store;
|
||||
|
||||
const { getTarifs, getRates } = helper({ apolloClient });
|
||||
const { getTarifs, getRates, getPriceChange } = helper({ apolloClient });
|
||||
|
||||
disposableReaction(
|
||||
() => $process.has('LoadKP'),
|
||||
@ -131,6 +131,29 @@ export default function valuesReactions({ store, apolloClient }: ProcessContext)
|
||||
}
|
||||
);
|
||||
|
||||
disposableReaction(
|
||||
() => $process.has('LoadKP'),
|
||||
() =>
|
||||
$calculation.$values.getValues([
|
||||
'discountRub',
|
||||
'addEquipmentPrice',
|
||||
'importProgramSum',
|
||||
'plPriceRub',
|
||||
'leaseObjectType',
|
||||
'recalcWithRevision',
|
||||
]),
|
||||
async (values) => {
|
||||
const { maxPriceChange, minPriceChange } = await getPriceChange(values);
|
||||
|
||||
$calculation.element('tbxMaxPriceChange').setValue(maxPriceChange);
|
||||
$calculation.element('tbxMinPriceChange').setValue(minPriceChange);
|
||||
},
|
||||
{
|
||||
delay: 5,
|
||||
equals: comparer.shallow,
|
||||
}
|
||||
);
|
||||
|
||||
(
|
||||
[
|
||||
'selectProduct',
|
||||
|
||||
@ -1,16 +1,10 @@
|
||||
import type { ProcessContext } from '../types';
|
||||
import { createValidationSchema } from './validation';
|
||||
import type { Elements } from '@/Components/Calculation/config/map/values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { createValidationReaction } from '@/process/tools';
|
||||
import { disposableReaction } from '@/utils/mobx';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { reaction } from 'mobx';
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
export function common({ store, apolloClient }: ProcessContext) {
|
||||
export function common({ store }: ProcessContext) {
|
||||
const { $calculation, $tables } = store;
|
||||
|
||||
reaction(
|
||||
@ -18,53 +12,6 @@ export function common({ store, apolloClient }: ProcessContext) {
|
||||
() => $calculation.element('selectQuote').resetValue()
|
||||
);
|
||||
|
||||
disposableReaction(
|
||||
() => $calculation.element('cbxRecalcWithRevision').getValue() === true,
|
||||
() =>
|
||||
$calculation.$values.getValues([
|
||||
'discountRub',
|
||||
'addEquipmentPrice',
|
||||
'importProgramSum',
|
||||
'plPriceRub',
|
||||
'leaseObjectType',
|
||||
]),
|
||||
async ({
|
||||
discountRub,
|
||||
importProgramSum,
|
||||
addEquipmentPrice,
|
||||
plPriceRub,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
}) => {
|
||||
let evo_leasingobject_type: CRMTypes.GetLeaseObjectTypeQuery['evo_leasingobject_type'] = null;
|
||||
|
||||
if (leaseObjectTypeId) {
|
||||
const { data } = await apolloClient.query({
|
||||
query: CRMTypes.GetLeaseObjectTypeDocument,
|
||||
variables: { leaseObjectTypeId },
|
||||
});
|
||||
|
||||
({ evo_leasingobject_type } = data);
|
||||
}
|
||||
|
||||
const price = plPriceRub + addEquipmentPrice - importProgramSum;
|
||||
const maxPriceChange =
|
||||
price - discountRub < 800_000
|
||||
? price - discountRub + 50_000
|
||||
: (price - discountRub) *
|
||||
(evo_leasingobject_type?.evo_vehicle_type?.includes(100_000_001) ||
|
||||
evo_leasingobject_type?.evo_vehicle_type?.includes(100_000_005)
|
||||
? 1.01
|
||||
: 1.05);
|
||||
|
||||
$calculation.element('tbxMaxPriceChange').setValue(maxPriceChange);
|
||||
|
||||
const minPriceChange =
|
||||
price - discountRub < 800_000 ? price - discountRub - 50_000 : (price - discountRub) * 0.95;
|
||||
|
||||
$calculation.element('tbxMinPriceChange').setValue(minPriceChange);
|
||||
}
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['leaseObjectUsed', 'recalcWithRevision']),
|
||||
({ leaseObjectUsed, recalcWithRevision }) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user