diff --git a/apps/web/process/insurance/validation.ts b/apps/web/process/insurance/validation.ts index cbfa5ec..49c3a74 100644 --- a/apps/web/process/insurance/validation.ts +++ b/apps/web/process/insurance/validation.ts @@ -11,10 +11,13 @@ import { z } from 'zod'; export function createValidationSchema({ apolloClient }: ValidationContext) { return ValuesSchema.pick({ brand: true, + firstPaymentPerc: true, insDecentral: true, + leaseObjectType: true, leasingPeriod: true, leasingWithoutKasko: true, partialVAT: true, + plPriceRub: true, product: true, quote: true, recalcWithRevision: true, @@ -37,6 +40,9 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { fingap: fingapRisks, partialVAT, product: productId, + leaseObjectType: leaseObjectTypeId, + firstPaymentPerc, + plPriceRub, }, ctx ) => { @@ -234,6 +240,30 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { path: ['cbxPartialVAT'], }); } + + let evo_leasingobject_type: CRMTypes.GetLeaseObjectTypeQuery['evo_leasingobject_type'] = + null; + + if (leaseObjectTypeId) { + const { data } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + ({ evo_leasingobject_type } = data); + } + + if ( + evo_leasingobject_type?.evo_id === '1' && + firstPaymentPerc < 25 && + plPriceRub > 20_000_000 && + insurance.values.kasko.insured === 100_000_001 + ) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'При дорогом авто и авансе меньше 25% нельзя включать КАСКО в график', + path: ['tbxLeaseObjectPrice'], + }); + } } ); }