process/configurator: подбор тарифа
This commit is contained in:
parent
156d3a131a
commit
ee538152b4
@ -160,6 +160,20 @@ export type GetDealerPersons_ProcessConfiguratorQueryVariables = Exact<{
|
||||
|
||||
export type GetDealerPersons_ProcessConfiguratorQuery = { __typename?: 'Query', dealerPersons: Array<{ __typename?: 'account', accountid: string | null, label: string | null, value: string | null } | null> | null };
|
||||
|
||||
export type GetTarifs_ProcessConfiguratorQueryVariables = Exact<{
|
||||
currentDate: InputMaybe<Scalars['DateTime']>;
|
||||
}>;
|
||||
|
||||
|
||||
export type GetTarifs_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarifs: Array<{ __typename?: 'evo_tarif', evo_tarifid: string | null, evo_baseproductid: string | null, evo_min_period: number | null, evo_max_period: number | null, evo_delivery_time: Array<number> | null, evo_min_first_payment: number | null, evo_max_first_payment: number | null, evo_min_last_payment: number | null, evo_max_last_payment: number | null, evo_used: boolean | null } | null> | null };
|
||||
|
||||
export type GetTarif_ProcessConfiguratorQueryVariables = Exact<{
|
||||
tarifId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null } | null };
|
||||
|
||||
export type GetRisksDataFromQuoteQueryVariables = Exact<{
|
||||
quoteId: Scalars['Uuid'];
|
||||
}>;
|
||||
@ -215,6 +229,13 @@ export type GetAddproductTypesQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
export type GetAddproductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price: number | null, evo_product_type: number | null, label: string | null, value: string | null } | null> | null };
|
||||
|
||||
export type GetTarifsQueryVariables = Exact<{
|
||||
currentDate: InputMaybe<Scalars['DateTime']>;
|
||||
}>;
|
||||
|
||||
|
||||
export type GetTarifsQuery = { __typename?: 'Query', selectTarif: Array<{ __typename?: 'evo_tarif', label: string | null, value: string | null } | null> | null };
|
||||
|
||||
export type GetOwnerDataQueryVariables = Exact<{
|
||||
domainname: InputMaybe<Scalars['String']>;
|
||||
}>;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
export { default as filters } from './filters';
|
||||
export { default as values } from './values';
|
||||
|
||||
142
apps/web/process/configurator/reactions/values.ts
Normal file
142
apps/web/process/configurator/reactions/values.ts
Normal file
@ -0,0 +1,142 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { gql } from '@apollo/client';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import type { ReactionsContext } from 'process/types';
|
||||
import { makeDisposable } from 'tools';
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
const QUERY_GET_TARIFS = gql`
|
||||
query GetTarifs_ProcessConfigurator($currentDate: DateTime) {
|
||||
evo_tarifs(
|
||||
statecode: 0
|
||||
evo_datefrom_param: { lte: $currentDate }
|
||||
evo_dateto_param: { gte: $currentDate }
|
||||
) {
|
||||
evo_tarifid
|
||||
evo_baseproductid
|
||||
evo_min_period
|
||||
evo_max_period
|
||||
evo_delivery_time
|
||||
evo_min_first_payment
|
||||
evo_max_first_payment
|
||||
evo_min_last_payment
|
||||
evo_max_last_payment
|
||||
evo_used
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_TARIF = gql`
|
||||
query GetTarif_ProcessConfigurator($tarifId: Uuid!) {
|
||||
evo_tarif(evo_tarifid: $tarifId) {
|
||||
evo_irr
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function valuesReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation, $process } = store;
|
||||
|
||||
autorun(
|
||||
async () => {
|
||||
const {
|
||||
product,
|
||||
leasingPeriod,
|
||||
leaseObjectUsed,
|
||||
deliveryTime,
|
||||
firstPaymentPerc,
|
||||
lastPaymentPerc,
|
||||
} = $calculation.$values.values;
|
||||
|
||||
const currentDate = dayjs().utc(false).toISOString();
|
||||
|
||||
let {
|
||||
data: { evo_tarifs = [] },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetTarifs_ProcessConfiguratorQuery,
|
||||
CRMTypes.GetTarifs_ProcessConfiguratorQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_TARIFS,
|
||||
variables: {
|
||||
currentDate,
|
||||
},
|
||||
});
|
||||
|
||||
if (product && leasingPeriod && deliveryTime && evo_tarifs) {
|
||||
evo_tarifs = evo_tarifs?.filter(
|
||||
(tarif) =>
|
||||
tarif &&
|
||||
tarif.evo_baseproductid === product &&
|
||||
tarif.evo_min_period &&
|
||||
tarif.evo_min_period <= leasingPeriod &&
|
||||
tarif.evo_max_period &&
|
||||
tarif.evo_max_period >= leasingPeriod &&
|
||||
tarif.evo_delivery_time?.includes(deliveryTime) &&
|
||||
tarif.evo_min_first_payment &&
|
||||
tarif.evo_min_first_payment <= firstPaymentPerc &&
|
||||
tarif.evo_max_first_payment &&
|
||||
tarif.evo_max_first_payment >= firstPaymentPerc &&
|
||||
tarif.evo_min_last_payment &&
|
||||
tarif.evo_min_last_payment <= lastPaymentPerc &&
|
||||
tarif.evo_max_last_payment &&
|
||||
tarif.evo_max_last_payment >= lastPaymentPerc
|
||||
);
|
||||
} else {
|
||||
$calculation.element('selectTarif').resetValue();
|
||||
}
|
||||
|
||||
if (leaseObjectUsed === true && evo_tarifs) {
|
||||
evo_tarifs = evo_tarifs?.filter((tarif) => {
|
||||
if (leaseObjectUsed === true) {
|
||||
return tarif?.evo_used;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
$calculation.element('selectTarif').setValue(evo_tarifs?.at(0)?.evo_tarifid || null);
|
||||
},
|
||||
{
|
||||
delay: 10,
|
||||
}
|
||||
);
|
||||
|
||||
makeDisposable(
|
||||
() =>
|
||||
reaction(
|
||||
() => $calculation.element('selectTarif').getValue(),
|
||||
async (tarifId) => {
|
||||
if (!tarifId) {
|
||||
$calculation.element('tbxIRR_Perc').resetValue();
|
||||
|
||||
return;
|
||||
}
|
||||
const {
|
||||
data: { evo_tarif },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetTarif_ProcessConfiguratorQuery,
|
||||
CRMTypes.GetTarif_ProcessConfiguratorQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_TARIF,
|
||||
variables: {
|
||||
tarifId,
|
||||
},
|
||||
});
|
||||
|
||||
if (evo_tarif?.evo_irr) {
|
||||
$calculation.element('tbxIRR_Perc').setValue(evo_tarif?.evo_irr);
|
||||
} else {
|
||||
$calculation.element('tbxIRR_Perc').resetValue();
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
() => $process.has('LoadKP')
|
||||
);
|
||||
}
|
||||
@ -89,6 +89,19 @@ const QUERY_GET_ADDPRODUCT_TYPES = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_TARIFS = gql`
|
||||
query GetTarifs($currentDate: DateTime) {
|
||||
selectTarif: evo_tarifs(
|
||||
statecode: 0
|
||||
evo_datefrom_param: { lte: $currentDate }
|
||||
evo_dateto_param: { gte: $currentDate }
|
||||
) {
|
||||
label: evo_name
|
||||
value: evo_tarifid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const currentDate = dayjs().utc(false).toISOString();
|
||||
|
||||
function getMainData(query, onCompleted) {
|
||||
@ -195,6 +208,15 @@ function getMainData(query, onCompleted) {
|
||||
selectLeasingWithoutKasko,
|
||||
});
|
||||
});
|
||||
|
||||
query({
|
||||
query: QUERY_GET_TARIFS,
|
||||
variables: {
|
||||
currentDate,
|
||||
},
|
||||
}).then(({ data }) => {
|
||||
onCompleted(data);
|
||||
});
|
||||
}
|
||||
|
||||
export function useMainData() {
|
||||
|
||||
@ -35,4 +35,5 @@ export default function injectDefaultReactions(context) {
|
||||
leasingObject.common(context);
|
||||
leasingObject.validation(context);
|
||||
configurator.filters(context);
|
||||
configurator.values(context);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user