111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
/* eslint-disable canonical/sort-keys */
|
||
|
||
import * as CRMTypes from '@/graphql/crm.types';
|
||
import type { ProcessContext } from '@/process/types';
|
||
import dayjs from 'dayjs';
|
||
import utc from 'dayjs/plugin/utc';
|
||
import { reaction } from 'mobx';
|
||
import { uid } from 'radash';
|
||
import { normalizeOptions } from 'tools';
|
||
import notification from 'ui/elements/notification';
|
||
|
||
dayjs.extend(utc);
|
||
|
||
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: 'Лизинг без КАСКО был сброшен',
|
||
});
|
||
}
|
||
}
|
||
);
|
||
|
||
/**
|
||
* если "Лизинг без КАСКО" (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 = dayjs().utc(false).format('YYYY-MM-DD');
|
||
|
||
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));
|
||
}
|
||
);
|
||
}
|