From 25723a193991ae82cc0cc6d738bc6002f6a87152 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 4 Jul 2024 16:43:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D1=80=D0=B5=D0=B0=D0=BA=D1=86=D0=B8=D1=8E:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Если Тип предмета лизингаselectLeaseObjectType = Спецтехника (ID=9) и значение в поле tbxMaxSpeed< 20, то insuredOSAGO = Лизингополучатель (100000000), inscostOSAGO = 0, inscompanyOSAGO = ПРОЧИЕ и закрыты для редактирования --- apps/web/process/insurance/reactions.ts | 55 ++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/apps/web/process/insurance/reactions.ts b/apps/web/process/insurance/reactions.ts index ce01731..8f5938c 100644 --- a/apps/web/process/insurance/reactions.ts +++ b/apps/web/process/insurance/reactions.ts @@ -6,7 +6,7 @@ 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'; +import { comparer, reaction } from 'mobx'; export function common({ store, apolloClient }: ProcessContext) { const { $calculation, $tables, $process } = store; @@ -303,6 +303,59 @@ export function common({ store, apolloClient }: ProcessContext) { } } ); + + debouncedReaction( + () => { + const values = $calculation.$values.getValues(['leaseObjectType', 'maxMass']); + const osago = $tables.insurance.row('osago').getValues(); + + return { ...values, osago }; + }, + async ({ leaseObjectType: leaseObjectTypeId, maxMass, osago }) => { + if (!leaseObjectTypeId) { + $tables.insurance.row('osago').column('insuranceCompany').resetOptions().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' && maxMass < 20 && osago.insured === 100_000_000) { + 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(); + } + } else { + $tables.insurance.row('osago').column('insuranceCompany').resetOptions().unblock(); + } + }, + { + delay: 1, + equals: comparer.structural, + wait: 100, + } + ); } export const validation = createValidationReaction(createValidationSchema);