поправили фильтрацию selectLeasingWithoutKasko

This commit is contained in:
vchikalkin 2023-02-07 14:57:52 +03:00
parent ea18dfd3d2
commit f264e2366a

View File

@ -6,7 +6,7 @@ import { gql } from '@apollo/client';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { autorun, reaction } from 'mobx';
import { uid } from 'radash';
import { get, pick, uid } from 'radash';
import { normalizeOptions } from 'tools';
import notification from 'ui/elements/notification';
@ -73,22 +73,22 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
}
);
autorun(async () => {
const currentDate = dayjs().utc(false).toISOString();
reaction(
() => {
const { values } = $calculation.$values;
const {
data: { evo_addproduct_types },
} = await apolloClient.query<
CRMTypes.GetLeasingWithoutKaskoOptionsQuery,
CRMTypes.GetLeasingWithoutKaskoOptionsQueryVariables
>({
query: QUERY_GET_LEASING_WITHOUT_KASKO_OPTIONS,
variables: {
currentDate,
},
});
const {
return pick(values, [
'plPriceRub',
'discountRub',
'importProgramSum',
'leasingPeriod',
'addEquipmentPrice',
'leaseObjectType',
'firstPaymentPerc',
'model',
]);
},
async ({
plPriceRub,
discountRub,
importProgramSum,
@ -97,30 +97,44 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
leaseObjectType,
firstPaymentPerc,
model: modelId,
} = $calculation.$values.values;
}) => {
const currentDate = dayjs().utc(false).toISOString();
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)
);
const {
data: { evo_addproduct_types },
} = await apolloClient.query<
CRMTypes.GetLeasingWithoutKaskoOptionsQuery,
CRMTypes.GetLeasingWithoutKaskoOptionsQueryVariables
>({
query: QUERY_GET_LEASING_WITHOUT_KASKO_OPTIONS,
variables: {
currentDate,
},
});
$calculation.element('selectLeasingWithoutKasko').setOptions(normalizeOptions(options));
});
const options = evo_addproduct_types?.filter(
(x) =>
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
x &&
Boolean(x.evo_max_period !== null && x.evo_max_period >= leasingPeriod) &&
Boolean(x.evo_min_period !== null && x.evo_min_period <= leasingPeriod) &&
x.evo_max_price !== null &&
x.evo_max_price >= plPriceRub - discountRub - importProgramSum + addEquipmentPrice &&
x.evo_min_price !== null &&
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 !== null &&
x.evo_min_first_payment_perc <= firstPaymentPerc &&
x.evo_max_first_payment_perc !== null &&
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));
}
);
}