diff --git a/apps/web/process/gibdd/reactions.ts b/apps/web/process/gibdd/reactions.ts index 6425c90..5888121 100644 --- a/apps/web/process/gibdd/reactions.ts +++ b/apps/web/process/gibdd/reactions.ts @@ -227,6 +227,7 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { () => $process.has('LoadKP') ); + // Не дышать на реакцию reaction( () => $calculation.$values.getValues([ @@ -244,20 +245,18 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { typePTS, leaseObjectCategory, leaseObjectType, + // eslint-disable-next-line sonarjs/cognitive-complexity }) => { - if (!objectRegionRegistrationId || !regionRegistrationId) { - $calculation.element('selectRegistration').resetValue(); - - return; - } const currentDate = dayjs().utc(false).format('YYYY-MM-DD'); - const { - data: { evo_region }, - } = await apolloClient.query({ - query: CRMTypes.GetRegionDocument, - variables: { regionId: objectRegionRegistrationId }, - }); + let evo_region: CRMTypes.GetRegionQuery['evo_region']; + if (objectRegionRegistrationId) { + const { data } = await apolloClient.query({ + query: CRMTypes.GetRegionDocument, + variables: { regionId: objectRegionRegistrationId }, + }); + evo_region = data.evo_region; + } const { data: { evo_addproduct_types }, @@ -266,27 +265,50 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { variables: { currentDate }, }); - const options = evo_addproduct_types?.filter( - (x) => - x?.evo_leasingobject_types?.find( + const options = evo_addproduct_types?.filter((x) => { + if ( + !x?.evo_leasingobject_types?.find( (evo_leasingobject_type) => evo_leasingobject_type?.evo_leasingobject_typeid === leaseObjectType - ) && - x.evo_whom_register === objectRegistration && - Boolean( - leaseObjectCategory === 100_000_001 - ? x.evo_towtruck === true || x.evo_towtruck === false - : x.evo_towtruck === false - ) && - x.evo_gibdd_region === (objectRegionRegistrationId === regionRegistrationId) && - Boolean(typePTS && x.evo_pts_type?.includes(typePTS)) && - Boolean( - x.evo_accountid && - evo_region?.accounts?.some( - (evo_region_account) => evo_region_account?.accountid === x.evo_accountid - ) ) - ); + ) { + return false; + } + + if (!objectRegionRegistrationId && !regionRegistrationId) { + return false; + } + + if (!(x?.evo_whom_register === objectRegistration)) { + return false; + } + + if (leaseObjectCategory !== 100_000_001 && x?.evo_towtruck) { + return false; + } + + if (!(x?.evo_gibdd_region === (objectRegionRegistrationId === regionRegistrationId))) { + return false; + } + + if ( + (typePTS && + (!x?.evo_pts_type || + x?.evo_pts_type.filter((evo_pts_type) => evo_pts_type > 0).length === 0)) || + (typePTS && + x?.evo_pts_type?.filter((evo_pts_type) => evo_pts_type > 0).includes(typePTS) === false) + ) { + return false; + } + + if (!x?.evo_accountid) { + return true; + } + + return evo_region?.accounts + ?.map((evo_region_account) => evo_region_account?.accountid) + .includes(x.evo_accountid); + }); $calculation.element('selectRegistration').setOptions(normalizeOptions(options)); } @@ -474,6 +496,22 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { } } ); + + reaction( + () => $calculation.element('radioObjectRegistration').getValue(), + (objectRegistration) => { + if (objectRegistration === 100_000_000) { + $calculation.element('tbxVehicleTaxInYear').resetValue().block(); + $calculation.element('radioTypePTS').resetValue().block(); + } else { + $calculation.element('tbxVehicleTaxInYear').unblock(); + $calculation.element('radioTypePTS').unblock(); + } + }, + { + fireImmediately: true, + } + ); } const key = uid(7);