diff --git a/apps/web/process/insurance/reactions.ts b/apps/web/process/insurance/reactions.ts index ce01731..bdda8e3 100644 --- a/apps/web/process/insurance/reactions.ts +++ b/apps/web/process/insurance/reactions.ts @@ -303,6 +303,56 @@ export function common({ store, apolloClient }: ProcessContext) { } } ); + + 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' && 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 { + $tables.insurance.row('osago').column('insuranceCompany').unblock(); + $tables.insurance.row('osago').column('insured').unblock(); + $tables.insurance.row('osago').column('insCost').unblock(); + } + } + ); } export const validation = createValidationReaction(createValidationSchema); diff --git a/apps/web/process/insurance/validation.ts b/apps/web/process/insurance/validation.ts index 7ca2a9b..19b36ad 100644 --- a/apps/web/process/insurance/validation.ts +++ b/apps/web/process/insurance/validation.ts @@ -16,6 +16,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { leaseObjectType: true, leasingPeriod: true, leasingWithoutKasko: true, + maxSpeed: true, partialVAT: true, plPriceRub: true, product: true, @@ -42,6 +43,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { leaseObjectType: leaseObjectTypeId, firstPaymentPerc, plPriceRub, + maxSpeed, }, ctx ) => { @@ -251,6 +253,19 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { path: ['tbxLeaseObjectPrice'], }); } + + if ( + evo_leasingobject_type?.evo_id && + ['9'].includes(evo_leasingobject_type?.evo_id) && + maxSpeed < 20 && + insurance.values.osago.insured === 100_000_001 + ) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Нельзя включать в график ОСАГО по Спецтехнике, т.к. полис не требуется', + path: ['insurance'], + }); + } } ); } diff --git a/apps/web/process/leasing-object/validation.ts b/apps/web/process/leasing-object/validation.ts index de74677..8ea0dc1 100644 --- a/apps/web/process/leasing-object/validation.ts +++ b/apps/web/process/leasing-object/validation.ts @@ -17,6 +17,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { leaseObjectType: true, leaseObjectUseFor: true, maxMass: true, + maxSpeed: true, model: true, }).superRefine( async ( @@ -32,6 +33,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { model: modelId, leaseObjectUseFor, configuration, + maxSpeed, }, ctx ) => { @@ -174,6 +176,18 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { path: ['selectLeaseObjectCategory'], }); } + + if ( + evo_leasingobject_type?.evo_id && + ['6', '9', '10'].includes(evo_leasingobject_type?.evo_id) && + !maxSpeed + ) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Не заполнено поле', + path: ['tbxMaxSpeed'], + }); + } } } );