2024-02-17 17:39:31 +03:00

109 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* eslint-disable canonical/sort-keys */
import { notification } from '@/Components/Common/Notification';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import { getCurrentISODate } from '@/utils/date';
import { normalizeOptions } from '@/utils/entity';
import { reaction } from 'mobx';
import { uid } from 'radash';
const NOTIFICATION_KEY = uid(7);
export function common({ store, apolloClient }: ProcessContext) {
const { $calculation, $tables } = store;
reaction(
() => $calculation.element('selectLeasingWithoutKasko').getValue(),
(nextValue, prevValue) => {
if (prevValue && !nextValue) {
notification.warning({
key: NOTIFICATION_KEY,
message: 'Внимание',
description: 'Лизинг без КАСКО был сброшен',
placement: 'bottomRight',
});
}
}
);
/**
* если "Лизинг без КАСКО" (SelectLeasingWithoutKasko) содержит данные,
* то в таблице страхования в строке ФинГАП: Страховая компания insCompany = null и закрыть для редактирования
*/
reaction(
() => $calculation.element('selectLeasingWithoutKasko').getValue(),
(leasingWithoutKasko) => {
if (leasingWithoutKasko) {
$tables.insurance.row('fingap').resetValue('insuranceCompany').block('insuranceCompany');
} else {
$tables.insurance.row('fingap').unblock('insuranceCompany');
}
}
);
reaction(
() =>
$calculation.$values.getValues([
'plPriceRub',
'discountRub',
'importProgramSum',
'leasingPeriod',
'addEquipmentPrice',
'leaseObjectType',
'firstPaymentPerc',
'model',
]),
async ({
plPriceRub,
discountRub,
importProgramSum,
leasingPeriod,
addEquipmentPrice,
leaseObjectType,
firstPaymentPerc,
model: modelId,
}) => {
const currentDate = getCurrentISODate();
const {
data: { evo_addproduct_types },
} = await apolloClient.query({
query: CRMTypes.GetLeasingWithoutKaskoTypesDocument,
variables: {
currentDate,
},
context: {
disableModify: true,
},
});
const price = plPriceRub - discountRub - importProgramSum + addEquipmentPrice;
const options = evo_addproduct_types?.filter(
(x) =>
x &&
Boolean(x.evo_max_period !== null && x.evo_max_period >= leasingPeriod) &&
Boolean(x.evo_min_period !== null && x.evo_min_period <= leasingPeriod) &&
Boolean(x.evo_max_price !== null && x.evo_max_price >= price) &&
Boolean(x.evo_min_price !== null && x.evo_min_price <= price) &&
x.evo_leasingobject_types?.find(
(evo_leasingobject_type) =>
evo_leasingobject_type?.evo_leasingobject_typeid === leaseObjectType
) &&
x.evo_visible_calc &&
Boolean(
x.evo_min_first_payment_perc !== null &&
x.evo_min_first_payment_perc <= firstPaymentPerc
) &&
Boolean(
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));
}
);
}