From 21b01d9e185720e9dd04dcc258ea6399de64c286 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 22 Feb 2023 12:47:58 +0300 Subject: [PATCH] process: add gibdd --- apps/web/config/default-options.ts | 54 +++--- apps/web/config/default-values.ts | 2 +- apps/web/config/process/default.ts | 2 + apps/web/graphql/crm.query.graphql | 2 + apps/web/graphql/crm.types.ts | 4 +- apps/web/process/gibdd/index.ts | 1 + apps/web/process/gibdd/reactions.ts | 245 ++++++++++++++++++++++++++++ 7 files changed, 281 insertions(+), 29 deletions(-) create mode 100644 apps/web/process/gibdd/index.ts create mode 100644 apps/web/process/gibdd/reactions.ts diff --git a/apps/web/config/default-options.ts b/apps/web/config/default-options.ts index d571d86..3951f64 100644 --- a/apps/web/config/default-options.ts +++ b/apps/web/config/default-options.ts @@ -70,6 +70,33 @@ export const radioGraphType = [ }, ]; +export const selectObjectCategoryTax = [ + 'M1', + 'M2', + 'M3', + 'M1G', + 'M2G', + 'M3G', + 'N1', + 'N2', + 'N3', + 'N1G', + 'N2G', + 'N3G', + 'O1', + 'O2', + 'O3', + 'O4', + 'L1', + 'L2', + 'L3', + 'L4', + 'L5', +].map((label, i) => ({ + label, + value: 100_000_000 + i, +})); + const defaultOptions: CalculationOptions = { radioLastPaymentRule: [ { @@ -344,32 +371,7 @@ const defaultOptions: CalculationOptions = { value: 100_000_001, }, ], - selectObjectCategoryTax: [ - 'M1', - 'M2', - 'M3', - 'M1G', - 'M2G', - 'M3G', - 'N1', - 'N2', - 'N3', - 'N1G', - 'N2G', - 'N3G', - 'O1', - 'O2', - 'O3', - 'O4', - 'L1', - 'L2', - 'L3', - 'L4', - 'L5', - ].map((label, i) => ({ - label, - value: 100_000_000 + i, - })), + selectObjectCategoryTax, selectObjectTypeTax: [ { label: 'Автобус', diff --git a/apps/web/config/default-values.ts b/apps/web/config/default-values.ts index 936f5c3..7f4dee4 100644 --- a/apps/web/config/default-values.ts +++ b/apps/web/config/default-values.ts @@ -134,7 +134,7 @@ const defaultValues: CalculationValues = { totalPayments: 0, townRegistration: null, tracker: null, - typePTS: 100_000_001, + typePTS: null, VATInLeaseObjectPrice: 0, vehicleTaxInLeasingPeriod: 0, vehicleTaxInYear: 0, diff --git a/apps/web/config/process/default.ts b/apps/web/config/process/default.ts index ea48c8d..66e22e7 100644 --- a/apps/web/config/process/default.ts +++ b/apps/web/config/process/default.ts @@ -3,6 +3,7 @@ import * as calculate from '@/process/calculate'; import * as configurator from '@/process/configurator'; import * as createKP from '@/process/create-kp'; import * as fingap from '@/process/fingap'; +import * as gibdd from '@/process/gibdd'; import { useProcess } from '@/process/hooks'; import * as leadOpportunity from '@/process/lead-opportunity'; import * as leasingObject from '@/process/leasing-object'; @@ -32,4 +33,5 @@ export default function useReactions() { useProcess(usedPl); useProcess(subsidyImportProgram); useProcess(payments); + useProcess(gibdd); } diff --git a/apps/web/graphql/crm.query.graphql b/apps/web/graphql/crm.query.graphql index e04826f..5eb9b67 100644 --- a/apps/web/graphql/crm.query.graphql +++ b/apps/web/graphql/crm.query.graphql @@ -230,6 +230,8 @@ query GetLeaseObjectType($leaseObjectTypeId: Uuid!) { evo_vehicle_type evo_id evo_category + evo_vehicle_type_tax + evo_category_tr } } diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 6eb59f2..125ef4d 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -260,7 +260,7 @@ export type GetLeaseObjectTypeQueryVariables = Exact<{ }>; -export type GetLeaseObjectTypeQuery = { __typename?: 'Query', evo_leasingobject_type: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array | null, evo_id: string | null, evo_category: number | null } | null }; +export type GetLeaseObjectTypeQuery = { __typename?: 'Query', evo_leasingobject_type: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array | null, evo_id: string | null, evo_category: number | null, evo_vehicle_type_tax: number | null, evo_category_tr: Array | null } | null }; export type GetBrandsQueryVariables = Exact<{ [key: string]: never; }>; @@ -492,7 +492,7 @@ export const GetImportProgramDocument = {"kind":"Document","definitions":[{"kind export const GetRegionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRegions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_regions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_regionid"}}]}}]}}]} as unknown as DocumentNode; export const GetGpsBrandsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetGPSBrands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_gps_brands"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_gps_brandid"}}]}}]}}]} as unknown as DocumentNode; export const GetLeaseObjectTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectTypes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_leasingobject_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}}]}}]} as unknown as DocumentNode; -export const GetLeaseObjectTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leasingobject_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category"}}]}}]}}]} as unknown as DocumentNode; +export const GetLeaseObjectTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leasingobject_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type_tax"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category_tr"}}]}}]}}]} as unknown as DocumentNode; export const GetBrandsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetBrands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brands"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_brandid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_brandid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}}]}}]}}]} as unknown as DocumentNode; export const GetBrandDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetBrand"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brand"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_brandid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_importer_reward_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_importer_reward_rub"}}]}}]}}]} as unknown as DocumentNode; export const GetModelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetModels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_models"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_brandid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_modelid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_modelid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/process/gibdd/index.ts b/apps/web/process/gibdd/index.ts new file mode 100644 index 0000000..88c740a --- /dev/null +++ b/apps/web/process/gibdd/index.ts @@ -0,0 +1 @@ +export * as reactions from './reactions'; diff --git a/apps/web/process/gibdd/reactions.ts b/apps/web/process/gibdd/reactions.ts new file mode 100644 index 0000000..3850936 --- /dev/null +++ b/apps/web/process/gibdd/reactions.ts @@ -0,0 +1,245 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import type { ProcessContext } from '../types'; +import { selectObjectCategoryTax } from '@/config/default-options'; +import * as CRMTypes from '@/graphql/crm.types'; +import ValidationHelper from '@/stores/validation/helper'; +import { reaction } from 'mobx'; +import { makeDisposable } from 'tools'; + +export function common({ store, apolloClient }: ProcessContext) { + const { $calculation, $process } = store; + + reaction( + () => $calculation.element('selectLeaseObjectType').getValue(), + async (leaseObjectTypeId) => { + if (!leaseObjectTypeId) { + $calculation.element('radioObjectRegistration').resetValue().unblock(); + + return; + } + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + + if ( + evo_leasingobject_type?.evo_id && + ['6', '9', '10', '11'].includes(evo_leasingobject_type.evo_id) + ) { + $calculation.element('radioObjectRegistration').setValue(100_000_000).block(); + } else { + $calculation.element('radioObjectRegistration').unblock(); + } + } + ); + + reaction( + () => $calculation.$values.getValues(['objectRegistration', 'vehicleTaxInYear']), + ({ objectRegistration, vehicleTaxInYear }) => { + if (objectRegistration === 100_000_001) { + $calculation.element('tbxVehicleTaxInYear').unblock(); + } else { + $calculation.element('tbxVehicleTaxInYear').resetValue().block(); + } + $calculation.element('tbxVehicleTaxInYear').validate({ + invalid: objectRegistration === 100_000_001 && !(vehicleTaxInYear > 0), + message: 'Значение должно быть больше 0', + }); + } + ); + + reaction( + () => $calculation.$values.getValues(['objectRegistration', 'typePTS']), + ({ objectRegistration, typePTS }) => { + if (objectRegistration === 100_000_001) { + $calculation.element('radioTypePTS').unblock(); + } else { + $calculation.element('radioTypePTS').resetValue().block(); + } + $calculation.element('radioTypePTS').validate({ + invalid: objectRegistration === 100_000_001 && !typePTS, + message: 'Не заполнено поле', + }); + } + ); + + reaction( + () => $calculation.$values.getValues(['leasingPeriod', 'vehicleTaxInYear']), + ({ leasingPeriod, vehicleTaxInYear }) => { + if (vehicleTaxInYear > 0) { + $calculation + .element('tbxVehicleTaxInLeasingPeriod') + .setValue((vehicleTaxInYear / 12) * leasingPeriod); + } else { + $calculation.element('tbxVehicleTaxInLeasingPeriod').resetValue(); + } + } + ); + + makeDisposable( + () => + reaction( + () => + $calculation.$values.getValues([ + 'leaseObjectType', + 'objectCategoryTax', + 'objectRegistration', + ]), + async ({ leaseObjectType: leaseObjectTypeId, objectRegistration, objectCategoryTax }) => { + if (objectRegistration === 100_000_001) { + if (objectCategoryTax && [100_000_006, 100_000_009].includes(objectCategoryTax)) { + $calculation.element('selectObjectTypeTax').setValue(100_000_002); + } else if (leaseObjectTypeId) { + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + + if (evo_leasingobject_type?.evo_vehicle_type_tax) { + $calculation + .element('selectObjectTypeTax') + .setValue(evo_leasingobject_type?.evo_vehicle_type_tax); + } else { + $calculation.element('selectObjectTypeTax').resetValue(); + } + } + } else { + $calculation.element('selectObjectTypeTax').resetValue(); + } + } + ), + () => $process.has('LoadKP') + ); + + reaction( + () => + $calculation.$values.getValues([ + 'leaseObjectType', + 'leaseObjectCategory', + 'typePTS', + 'objectRegistration', + ]), + async ({ + leaseObjectType: leaseObjectTypeId, + leaseObjectCategory, + typePTS, + objectRegistration, + }) => { + if (objectRegistration === 100_000_001 && typePTS === 100_000_001) { + $calculation.element('selectObjectCategoryTax').unblock(); + if (leaseObjectTypeId) { + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + if (leaseObjectCategory && leaseObjectCategory === evo_leasingobject_type?.evo_category) { + $calculation + .element('selectObjectCategoryTax') + .setOptions( + selectObjectCategoryTax.filter((option) => + evo_leasingobject_type?.evo_category_tr?.includes(option.value) + ) + ); + } else { + $calculation.element('selectObjectCategoryTax').resetOptions(); + } + } + } else { + $calculation.element('selectObjectCategoryTax').resetValue().block(); + } + } + ); +} + +export function validation({ store, apolloClient }: ProcessContext) { + const { $calculation } = store; + + reaction( + () => $calculation.$values.getValues(['leaseObjectCategory', 'maxMass']), + ({ leaseObjectCategory, maxMass }) => { + $calculation.element('tbxMaxMass').validate({ + invalid: leaseObjectCategory === 100_000_001 && maxMass > 3500, + message: 'При категории ТС = В Разрешенная макс.масса не может быть больше 3500 кг', + }); + $calculation.element('tbxMaxMass').validate({ + invalid: leaseObjectCategory === 100_000_002 && maxMass <= 3500, + message: 'При категории ТС = С Разрешенная макс.масса не может быть меньше 3500 кг', + }); + } + ); + + { + const validationHelper = new ValidationHelper(); + reaction( + () => + $calculation.$values.getValues([ + 'typePTS', + 'objectRegistration', + 'objectCategoryTax', + 'leaseObjectType', + ]), + async ({ + leaseObjectType: leaseObjectTypeId, + typePTS, + objectRegistration, + objectCategoryTax, + }) => { + if (!leaseObjectTypeId) { + validationHelper.removeErrors(); + + return; + } + + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + + $calculation.element('selectObjectCategoryTax').validate({ + helper: validationHelper, + invalid: + objectRegistration === 100_000_001 && + typePTS === 100_000_001 && + objectCategoryTax === null && + Boolean(evo_leasingobject_type?.evo_category_tr?.length), + message: 'Необходимо из ЭПТС указать Категорию в соответствии с ТР ТС 018/2011', + }); + } + ); + } + + { + const validationHelper = new ValidationHelper(); + reaction( + () => $calculation.$values.getValues(['leaseObjectType', 'insNSIB']), + async ({ insNSIB, leaseObjectType: leaseObjectTypeId }) => { + if (!leaseObjectTypeId) { + validationHelper.removeErrors(); + + return; + } + + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + + $calculation.element('selectInsNSIB').validate({ + helper: validationHelper, + invalid: evo_leasingobject_type?.evo_id === '11' && !insNSIB, + message: 'Страхование НСИБ обязательно для мотоциклистов', + }); + } + ); + } +}