process/leasing-without-kasko: filter selectLeasingWithoutKasko
This commit is contained in:
parent
5ea1fe3925
commit
2782df536c
File diff suppressed because it is too large
Load Diff
@ -231,6 +231,11 @@ export type GetQuoteUrlQueryVariables = Exact<{
|
||||
|
||||
export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null };
|
||||
|
||||
export type GetLeasingWithoutKaskoOptionsQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetLeasingWithoutKaskoOptionsQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_product_type: number | null, evo_min_period: number | null, evo_max_period: number | null, evo_min_price: number | null, evo_max_price: number | null, evo_visible_calc: boolean | null, evo_min_first_payment_perc: number | null, evo_max_first_payment_perc: number | null, label: string | null, value: string | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null, evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null> | null };
|
||||
|
||||
export type GetPaymentsDataFromQuoteQueryVariables = Exact<{
|
||||
quoteId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
@ -1,9 +1,41 @@
|
||||
import { reaction } from 'mobx';
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { gql } from '@apollo/client';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
import type { ReactionsContext } from 'process/types';
|
||||
import { uid } from 'radash';
|
||||
import { normalizeOptions } from 'tools';
|
||||
import notification from 'ui/elements/notification';
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
const NOTIFICATION_KEY = uid(7);
|
||||
|
||||
const QUERY_GET_LEASING_WITHOUT_KASKO_OPTIONS = gql`
|
||||
query GetLeasingWithoutKaskoOptions {
|
||||
evo_addproduct_types(statecode: 0, evo_product_type: 100000007) {
|
||||
label: evo_name
|
||||
value: evo_addproduct_typeid
|
||||
evo_product_type
|
||||
evo_min_period
|
||||
evo_max_period
|
||||
evo_min_price
|
||||
evo_max_price
|
||||
evo_leasingobject_types {
|
||||
evo_leasingobject_typeid
|
||||
}
|
||||
evo_visible_calc
|
||||
evo_min_first_payment_perc
|
||||
evo_max_first_payment_perc
|
||||
evo_models {
|
||||
evo_modelid
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function commonReactions({ store, apolloClient, queryClient }: ReactionsContext) {
|
||||
const { $calculation, $tables } = store;
|
||||
|
||||
@ -30,4 +62,50 @@ export default function commonReactions({ store, apolloClient, queryClient }: Re
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
autorun(async () => {
|
||||
const {
|
||||
data: { evo_addproduct_types },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetLeasingWithoutKaskoOptionsQuery,
|
||||
CRMTypes.GetLeasingWithoutKaskoOptionsQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_LEASING_WITHOUT_KASKO_OPTIONS,
|
||||
});
|
||||
|
||||
const {
|
||||
plPriceRub,
|
||||
discountRub,
|
||||
importProgramSum,
|
||||
leasingPeriod,
|
||||
addEquipmentPrice,
|
||||
leaseObjectType,
|
||||
firstPaymentPerc,
|
||||
model: modelId,
|
||||
} = $calculation.$values.values;
|
||||
|
||||
const options = evo_addproduct_types?.filter(
|
||||
(x) =>
|
||||
x?.evo_max_period &&
|
||||
x.evo_max_period >= leasingPeriod &&
|
||||
x?.evo_min_period &&
|
||||
x.evo_min_period <= leasingPeriod &&
|
||||
x?.evo_max_price &&
|
||||
x.evo_max_price >= plPriceRub - discountRub - importProgramSum + addEquipmentPrice &&
|
||||
x?.evo_min_price &&
|
||||
x.evo_min_price <= plPriceRub - discountRub - importProgramSum + addEquipmentPrice &&
|
||||
x.evo_leasingobject_types?.find(
|
||||
(evo_leasingobject_type) =>
|
||||
evo_leasingobject_type?.evo_leasingobject_typeid === leaseObjectType
|
||||
) &&
|
||||
x.evo_visible_calc &&
|
||||
x.evo_min_first_payment_perc &&
|
||||
x.evo_min_first_payment_perc <= firstPaymentPerc &&
|
||||
x.evo_max_first_payment_perc &&
|
||||
x.evo_max_first_payment_perc >= firstPaymentPerc &&
|
||||
!x.evo_models?.map((evo_model) => evo_model?.evo_modelid).includes(modelId)
|
||||
);
|
||||
|
||||
$calculation.element('selectLeasingWithoutKasko').setOptions(normalizeOptions(options));
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user