Если в Предложении quote поле "Особые условия страхования" evo_insurance_special_conditions содержит значение "Без КАСКО" 100 000 002, то в таблице страхования необходимо заполнить и закрыть для редактирования следующие поля: insuredOSAGO = Лизингополучатель (100000000) и закрыть для редактирования inscostOSAGO = 0 и закрыть для редактирования inscompanyOSAGO сбросить фильтрацию списка, указать значение "ПРОЧИЕ" и закрыть для редактирования insuredKASKO = Лизингополучатель (100000000) и закрыть для редактирования inscostKASKO = 0 и закрыть для редактирования inscompanyKASKO сбросить фильтрацию списка, указать значение "ПРОЧИЕ" и закрыть для редактирования
422 lines
14 KiB
TypeScript
422 lines
14 KiB
TypeScript
/* eslint-disable sonarjs/cognitive-complexity */
|
||
import { createValidationReaction } from '../tools';
|
||
import type { ProcessContext } from '../types';
|
||
import { createValidationSchema } from './validation';
|
||
import { selectLeaseObjectUseFor } from '@/config/default-options';
|
||
import * as CRMTypes from '@/graphql/crm.types';
|
||
import { normalizeOptions } from '@/utils/entity';
|
||
import { debouncedReaction, disposableReaction } from '@/utils/mobx';
|
||
import { reaction } from 'mobx';
|
||
|
||
export function common({ store, apolloClient }: ProcessContext) {
|
||
const { $calculation, $tables, $process } = store;
|
||
|
||
reaction(
|
||
() => $calculation.element('selectGPSBrand').getValue(),
|
||
async (gpsBrandId) => {
|
||
if (!gpsBrandId) {
|
||
$calculation.element('selectGPSModel').resetValue();
|
||
|
||
return;
|
||
}
|
||
|
||
const {
|
||
data: { evo_gps_models },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetGpsModelsDocument,
|
||
variables: {
|
||
gpsBrandId,
|
||
},
|
||
});
|
||
|
||
if (evo_gps_models) {
|
||
$calculation.element('selectGPSModel').setOptions(normalizeOptions(evo_gps_models));
|
||
}
|
||
}
|
||
);
|
||
|
||
reaction(
|
||
() => $calculation.element('selectLeaseObjectCategory').getValue(),
|
||
(leaseObjectCategory) => {
|
||
switch (leaseObjectCategory) {
|
||
case 100_000_000: {
|
||
$calculation
|
||
.element('selectLeaseObjectUseFor')
|
||
.setOptions(
|
||
selectLeaseObjectUseFor.filter((x) => [100_000_000, 100_000_002].includes(x.value))
|
||
);
|
||
break;
|
||
}
|
||
case 100_000_001: {
|
||
$calculation
|
||
.element('selectLeaseObjectUseFor')
|
||
.setOptions(
|
||
selectLeaseObjectUseFor.filter((x) =>
|
||
[
|
||
100_000_000, 100_000_001, 100_000_002, 100_000_003, 100_000_004, 100_000_005,
|
||
100_000_006, 100_000_007, 100_000_008, 100_000_009, 100_000_010, 100_000_011,
|
||
100_000_012, 100_000_013,
|
||
].includes(x.value)
|
||
)
|
||
);
|
||
break;
|
||
}
|
||
case 100_000_002: {
|
||
$calculation
|
||
.element('selectLeaseObjectUseFor')
|
||
.setOptions(
|
||
selectLeaseObjectUseFor.filter((x) =>
|
||
[
|
||
100_000_002, 100_000_004, 100_000_005, 100_000_006, 100_000_009, 100_000_010,
|
||
100_000_020,
|
||
].includes(x.value)
|
||
)
|
||
);
|
||
break;
|
||
}
|
||
case 100_000_003: {
|
||
$calculation
|
||
.element('selectLeaseObjectUseFor')
|
||
.setOptions(
|
||
selectLeaseObjectUseFor.filter((x) =>
|
||
[
|
||
100_000_002, 100_000_004, 100_000_006, 100_000_007, 100_000_008, 100_000_011,
|
||
100_000_012, 100_000_013,
|
||
].includes(x.value)
|
||
)
|
||
);
|
||
break;
|
||
}
|
||
case 100_000_004: {
|
||
$calculation
|
||
.element('selectLeaseObjectUseFor')
|
||
.setOptions(
|
||
selectLeaseObjectUseFor.filter((x) =>
|
||
[100_000_002, 100_000_009, 100_000_020].includes(x.value)
|
||
)
|
||
);
|
||
break;
|
||
}
|
||
default: {
|
||
$calculation
|
||
.element('selectLeaseObjectUseFor')
|
||
.setOptions(
|
||
selectLeaseObjectUseFor.filter((x) =>
|
||
[
|
||
100_000_014, 100_000_015, 100_000_016, 100_000_017, 100_000_018, 100_000_019,
|
||
].includes(x.value)
|
||
)
|
||
);
|
||
break;
|
||
}
|
||
}
|
||
},
|
||
{
|
||
fireImmediately: true,
|
||
}
|
||
);
|
||
|
||
debouncedReaction(
|
||
() =>
|
||
$calculation.$values.getValues([
|
||
'leasingPeriod',
|
||
'leasingWithoutKasko',
|
||
'dealer',
|
||
'leaseObjectCategory',
|
||
]),
|
||
async ({ leasingPeriod, leasingWithoutKasko, dealer: dealerId, leaseObjectCategory }) => {
|
||
const {
|
||
data: { accounts },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetInsuranceCompaniesDocument,
|
||
});
|
||
|
||
if (leasingWithoutKasko) {
|
||
const otherInsuranceCompany = accounts?.find(
|
||
(x) => x?.evo_type_ins_policy === null && x.label?.includes('ПРОЧИЕ')
|
||
);
|
||
|
||
if (otherInsuranceCompany) {
|
||
$tables.insurance
|
||
.row('kasko')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions([otherInsuranceCompany]))
|
||
.setValue(otherInsuranceCompany.value)
|
||
.block();
|
||
|
||
$tables.insurance.row('kasko').column('insCost').resetValue().block();
|
||
$tables.insurance.row('kasko').column('insTerm').setValue(100_000_000).block();
|
||
$tables.insurance.row('kasko').column('insured').setValue(100_000_000).block();
|
||
}
|
||
} else {
|
||
const defaultKaskoOptions = accounts?.filter((x) =>
|
||
x?.evo_type_ins_policy?.includes(100_000_000)
|
||
);
|
||
$tables.insurance
|
||
.row('kasko')
|
||
.setOptions('insuranceCompany', normalizeOptions(defaultKaskoOptions))
|
||
.unblock('insuranceCompany')
|
||
.unblock('insCost');
|
||
|
||
if (leasingPeriod < 12) {
|
||
$tables.insurance.row('osago').column('insured').setValue(100_000_000).block();
|
||
$tables.insurance.row('kasko').column('insured').setValue(100_000_000).block();
|
||
$tables.insurance.row('kasko').column('insTerm').setValue(100_000_000).block();
|
||
} else if (leasingPeriod === 12 || leasingPeriod > 16) {
|
||
$tables.insurance.row('osago').column('insured').unblock();
|
||
$tables.insurance.row('kasko').column('insTerm').setValue(100_000_000).block();
|
||
$tables.insurance.row('kasko').column('insured').unblock();
|
||
} else if (leasingPeriod > 12 && leasingPeriod < 16) {
|
||
$tables.insurance.row('osago').column('insured').unblock();
|
||
$tables.insurance.row('kasko').column('insTerm').setValue(100_000_001).block();
|
||
$tables.insurance.row('kasko').column('insured').unblock();
|
||
} else {
|
||
$tables.insurance.row('osago').column('insured').unblock();
|
||
$tables.insurance.row('kasko').column('insTerm').block();
|
||
$tables.insurance.row('kasko').column('insured').unblock();
|
||
}
|
||
|
||
/**
|
||
* @see 'apps\web\process\supplier-agent\reactions\leaseback.ts'
|
||
*/
|
||
if (dealerId) {
|
||
const {
|
||
data: { dealer },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetDealerDocument,
|
||
variables: {
|
||
dealerId,
|
||
},
|
||
});
|
||
|
||
if (dealer?.evo_return_leasing_dealer === true) {
|
||
$tables.insurance.row('kasko').column('insured').setValue(100_000_000).block();
|
||
}
|
||
// объединили реакцию для прицепа и возвратного лизинга
|
||
const isTrailer = leaseObjectCategory === 100_000_004;
|
||
if (isTrailer || dealer?.evo_return_leasing_dealer === true) {
|
||
$tables.insurance.row('osago').column('insured').setValue(100_000_000).block();
|
||
}
|
||
}
|
||
}
|
||
},
|
||
{
|
||
delay: 1,
|
||
fireImmediately: true,
|
||
wait: 100,
|
||
}
|
||
);
|
||
|
||
// объединить со строчкой 308
|
||
debouncedReaction(
|
||
() => $calculation.$values.getValues(['leaseObjectCategory', 'leasingWithoutKasko']),
|
||
async ({ leaseObjectCategory, leasingWithoutKasko }) => {
|
||
const {
|
||
data: { accounts },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetInsuranceCompaniesDocument,
|
||
});
|
||
|
||
const isTrailer = leaseObjectCategory === 100_000_004;
|
||
if (isTrailer) {
|
||
const otherInsuranceCompany = accounts?.find(
|
||
(x) => x?.evo_type_ins_policy === null && x.label?.includes('ПРОЧИЕ')
|
||
);
|
||
|
||
if (otherInsuranceCompany) {
|
||
$tables.insurance
|
||
.row('osago')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions([otherInsuranceCompany]))
|
||
.setValue(otherInsuranceCompany.value)
|
||
.block();
|
||
|
||
$tables.insurance.row('osago').column('insCost').resetValue().block();
|
||
}
|
||
} else {
|
||
$tables.insurance.row('osago').column('insCost').unblock();
|
||
$tables.insurance.row('osago').column('insuranceCompany').unblock();
|
||
|
||
const defaultOsagoOptions = accounts?.filter((x) =>
|
||
x?.evo_type_ins_policy?.includes(100_000_001)
|
||
);
|
||
|
||
if (leasingWithoutKasko) {
|
||
const evoKaskoInsuranceOptions = defaultOsagoOptions?.filter(
|
||
(x) => x?.evo_evokasko_access === true
|
||
);
|
||
$tables.insurance
|
||
.row('osago')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions(evoKaskoInsuranceOptions));
|
||
} else {
|
||
$tables.insurance
|
||
.row('osago')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions(defaultOsagoOptions));
|
||
}
|
||
}
|
||
},
|
||
{
|
||
delay: 1,
|
||
wait: 100,
|
||
}
|
||
);
|
||
|
||
disposableReaction(
|
||
() => $process.has('LoadKP'),
|
||
() => $calculation.element('selectBrand').getValue(),
|
||
async (brandId) => {
|
||
if (!brandId) {
|
||
$tables.insurance.row('kasko').column('insuranceCompany').resetValue().unblock();
|
||
|
||
return;
|
||
}
|
||
|
||
const {
|
||
data: { accounts },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetInsuranceCompaniesDocument,
|
||
});
|
||
|
||
const defaultKaskoOptions = accounts?.filter((x) =>
|
||
x?.evo_type_ins_policy?.includes(100_000_000)
|
||
);
|
||
|
||
const {
|
||
data: { evo_brand },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetBrandDocument,
|
||
variables: { brandId },
|
||
});
|
||
|
||
if (evo_brand?.evo_id === 'BRAND49') {
|
||
const renessansCompany = defaultKaskoOptions?.find((x) => x?.evo_inn === '7725497022');
|
||
|
||
if (renessansCompany)
|
||
$tables.insurance
|
||
.row('kasko')
|
||
.column('insuranceCompany')
|
||
.setValue(renessansCompany?.value)
|
||
.block();
|
||
} else {
|
||
$tables.insurance.row('kasko').column('insuranceCompany').resetValue().unblock();
|
||
}
|
||
}
|
||
);
|
||
|
||
// объединить со строчкой 210
|
||
reaction(
|
||
() => $calculation.$values.getValues(['leaseObjectType', 'maxSpeed']),
|
||
async ({ leaseObjectType: leaseObjectTypeId, maxSpeed }) => {
|
||
if (!leaseObjectTypeId) {
|
||
$tables.insurance.row('osago').column('insuranceCompany').unblock();
|
||
$tables.insurance.row('osago').column('insured').unblock();
|
||
$tables.insurance.row('osago').column('insCost').unblock();
|
||
|
||
return;
|
||
}
|
||
|
||
const {
|
||
data: { evo_leasingobject_type },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetLeaseObjectTypeDocument,
|
||
variables: {
|
||
leaseObjectTypeId,
|
||
},
|
||
});
|
||
|
||
const {
|
||
data: { accounts },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetInsuranceCompaniesDocument,
|
||
});
|
||
|
||
if (
|
||
evo_leasingobject_type?.evo_id &&
|
||
['9', '6', '10'].includes(evo_leasingobject_type.evo_id) &&
|
||
maxSpeed < 20
|
||
) {
|
||
const otherInsuranceCompany = accounts?.find(
|
||
(x) => x?.evo_type_ins_policy === null && x.label?.includes('ПРОЧИЕ')
|
||
);
|
||
|
||
if (otherInsuranceCompany) {
|
||
$tables.insurance
|
||
.row('osago')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions([otherInsuranceCompany]))
|
||
.setValue(otherInsuranceCompany.value)
|
||
.block();
|
||
}
|
||
|
||
$tables.insurance.row('osago').column('insured').setValue(100_000_000).block();
|
||
$tables.insurance.row('osago').column('insCost').setValue(0).block();
|
||
} else {
|
||
const defaultOsagoOptions = accounts?.filter((x) =>
|
||
x?.evo_type_ins_policy?.includes(100_000_001)
|
||
);
|
||
|
||
$tables.insurance
|
||
.row('osago')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions(defaultOsagoOptions))
|
||
.unblock();
|
||
|
||
$tables.insurance.row('osago').column('insured').unblock();
|
||
$tables.insurance.row('osago').column('insCost').unblock();
|
||
}
|
||
}
|
||
);
|
||
|
||
reaction(
|
||
() => $calculation.element('selectQuote').getValue(),
|
||
async (quoteId) => {
|
||
if (!quoteId) return;
|
||
|
||
const {
|
||
data: { quote },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetQuoteDocument,
|
||
variables: { quoteId },
|
||
});
|
||
|
||
if (quote?.evo_insurance_special_conditions?.includes(100_000_002)) {
|
||
$tables.insurance.row('osago').column('insured').setValue(100_000_000).block();
|
||
$tables.insurance.row('osago').column('insCost').resetValue().block();
|
||
|
||
$tables.insurance.row('kasko').column('insured').setValue(100_000_000).block();
|
||
$tables.insurance.row('kasko').column('insCost').resetValue().block();
|
||
|
||
const {
|
||
data: { accounts },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetInsuranceCompaniesDocument,
|
||
});
|
||
|
||
const otherInsuranceCompany = accounts?.find(
|
||
(x) => x?.evo_type_ins_policy === null && x.label?.includes('ПРОЧИЕ')
|
||
);
|
||
|
||
if (otherInsuranceCompany) {
|
||
$tables.insurance
|
||
.row('osago')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions([otherInsuranceCompany]))
|
||
.setValue(otherInsuranceCompany.value)
|
||
.block();
|
||
|
||
$tables.insurance
|
||
.row('kasko')
|
||
.column('insuranceCompany')
|
||
.setOptions(normalizeOptions([otherInsuranceCompany]))
|
||
.setValue(otherInsuranceCompany.value)
|
||
.block();
|
||
}
|
||
}
|
||
}
|
||
);
|
||
}
|
||
|
||
export const validation = createValidationReaction(createValidationSchema);
|