From ebd7c2ef3c5eca193eaa72ff565f53a7d27bad50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A7=D0=B8=D0=BA=D0=B0=D0=BB=D0=BA=D0=B8=D0=BD?= Date: Wed, 11 Nov 2020 19:46:37 +0300 Subject: [PATCH] add reactions --- .../CalculationStore/Effects/reaction.ts | 238 +++++++++++++++++- src/core/Data/initialOptions.ts | 2 +- src/core/config/initialValues.ts | 6 + src/core/types/Entities/crmEntities.ts | 2 +- 4 files changed, 245 insertions(+), 3 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 198503a..1cb20a5 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -6,7 +6,6 @@ import { Status } from 'core/types/statuses'; import { ITableCell, TableProps } from 'core/types/Calculation/Store/tables'; import { toJS } from 'mobx'; import { calcPrice, calculatePerc, calculateRub } from './lib/tools'; -import { query } from 'express'; import { gql } from '@apollo/client'; import { currentDate } from 'client/common/constants'; @@ -409,6 +408,9 @@ const reactionEffects: IReactionEffect[] = [ break; } }, + options: { + fireImmediately: true, + }, }), calculationStore => ({ @@ -2832,6 +2834,240 @@ const reactionEffects: IReactionEffect[] = [ fireImmediately: true, }, }), + + calculationStore => ({ + expression: () => { + const { supplier } = calculationStore.values; + return supplier; + }, + effect: supplierId => { + calculationStore.setOptions('selectFinDepartment', []); + calculationStore.setValue('finDepartment', null); + if (supplierId) { + const supplier = calculationStore.options.selectSupplier?.find( + x => x.accountid === supplierId, + ); + if (supplier && supplier.evo_fin_department_accountid) + CalculationService.crmgqlquery({ + query: gql` + query($accountid: Uuid!) { + account(accountid: $accountid) { + accountid + name + } + } + `, + toOptions: ['account'], + variables: { + accountid: supplier.evo_fin_department_accountid, + }, + }).then(({ entities }) => { + if (entities.account && !Array.isArray(entities.account)) { + calculationStore.setOptions('selectFinDepartment', [ + entities.account, + ]); + } + }); + } + }, + }), + calculationStore => ({ + expression: () => { + const { supplier, channel } = calculationStore.values; + return { supplierId: supplier, channelId: channel }; + }, + //TODO: add $ownerid: Uuid + effect: ({ supplierId, channelId }) => { + calculationStore.setOptions('selectAgent', []); + calculationStore.setValue('agent', null); + if (channelId === 100000002) { + CalculationService.crmgqlquery({ + query: gql` + query( + $statecode: Int + $evo_account_type: [Int!] + $evo_legal_form: Int + ) { + account: accounts( + statecode: $statecode + evo_account_type: $evo_account_type + evo_legal_form: $evo_legal_form + ) { + accountid + name + } + } + `, + toOptions: ['account'], + variables: { + statecode: 0, + evo_account_type: [100000005], + evo_legal_form: 100000004, + }, + }).then(({ entities }) => { + if (entities.account && Array.isArray(entities.account)) { + calculationStore.setOptions('selectAgent', entities.account); + } + }); + } else { + if (supplierId) { + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $salonaccountid: Uuid!) { + account: salon_agents( + statecode: $statecode + salonaccountid: $salonaccountid + ) { + accountid + name + } + } + `, + toOptions: ['account'], + variables: { + statecode: 0, + salonaccountid: supplierId, + }, + }).then(({ entities }) => { + if (entities.account && Array.isArray(entities.account)) { + calculationStore.setOptions('selectAgent', entities.account); + } + }); + } + } + }, + }), + //TODO + // calculationStore => ({ + // expression: () => { + // const { product } = calculationStore.values; + // return product; + // }, + // effect: productId => { + // if (productId) { + // const product = calculationStore.options.selectProduct?.find( + // x => x.evo_id === productId, + // ); + // if ( + // product && + // product.evo_leasingobject_types && + // Array.isArray(product.evo_leasingobject_types) + // ) { + // calculationStore.setOptions( + // 'selectLeaseObjectType', + // product.evo_leasingobject_types, + // ); + // } + // } + // }, + // }), + + calculationStore => ({ + expression: () => { + const { GPSBrand } = calculationStore.values; + return GPSBrand; + }, + effect: GPSBrandId => { + calculationStore.setStatus('selectGPSModel', Status.Disabled); + calculationStore.setOptions('selectGPSModel', []); + calculationStore.setValue('GPSModel', null); + + if (GPSBrandId) { + const gpsBrand = calculationStore.options.selectGPSBrand?.find( + x => x.evo_gps_brandid === GPSBrandId, + ); + if (gpsBrand) { + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $evo_gps_brandid: Uuid) { + evo_gps_model: evo_gps_models( + statecode: $statecode + evo_gps_brandid: $evo_gps_brandid + ) { + evo_name + evo_gps_modelid + } + } + `, + variables: { + statecode: 0, + evo_gps_brandid: GPSBrandId, + }, + toOptions: ['evo_gps_model'], + }).then(({ entities }) => { + if ( + entities.evo_gps_model && + Array.isArray(entities.evo_gps_model) && + entities.evo_gps_model.length > 0 + ) { + calculationStore.setStatus('selectGPSModel', Status.Default); + calculationStore.setOptions( + 'selectGPSModel', + entities.evo_gps_model, + ); + calculationStore.setValue('GPSModel', null); + } + }); + } + } + }, + options: { fireImmediately: true }, + }), + + calculationStore => ({ + expression: () => { + const { regionRegistration } = calculationStore.values; + return regionRegistration; + }, + effect: regionRegistrationId => { + calculationStore.setStatus('selectTownRegistration', Status.Disabled); + calculationStore.setOptions('selectTownRegistration', []); + calculationStore.setValue('townRegistration', null); + + if (regionRegistrationId) { + const regionRegistration = calculationStore.options.selectRegionRegistration?.find( + x => x.evo_regionid === regionRegistrationId, + ); + if (regionRegistration) { + CalculationService.crmgqlquery({ + query: gql` + query($statecode: Int, $evo_regionid: Uuid) { + evo_town: evo_towns( + statecode: $statecode + evo_regionid: $evo_regionid + ) { + evo_name + evo_townid + } + } + `, + variables: { + statecode: 0, + evo_regionid: regionRegistrationId, + }, + toOptions: ['evo_town'], + }).then(({ entities }) => { + if ( + entities.evo_town && + Array.isArray(entities.evo_town) && + entities.evo_town.length > 0 + ) { + calculationStore.setStatus( + 'selectTownRegistration', + Status.Default, + ); + calculationStore.setOptions( + 'selectTownRegistration', + entities.evo_town, + ); + calculationStore.setValue('townRegistration', null); + } + }); + } + } + }, + options: { fireImmediately: true }, + }), ]; export default reactionEffects; diff --git a/src/core/Data/initialOptions.ts b/src/core/Data/initialOptions.ts index ffa08ea..4af6d25 100644 --- a/src/core/Data/initialOptions.ts +++ b/src/core/Data/initialOptions.ts @@ -42,7 +42,7 @@ const initialOptions: TEntityQuery[] = [ statecode: 0, evo_legal_form: 100000001, }, - fields: ['accountid', 'name'], + fields: ['accountid', 'name', 'evo_fin_department_accountid'], many: true, toOption: true, }, diff --git a/src/core/config/initialValues.ts b/src/core/config/initialValues.ts index d037a4a..dedbe33 100644 --- a/src/core/config/initialValues.ts +++ b/src/core/config/initialValues.ts @@ -1,6 +1,12 @@ import { TValues, TValue } from 'core/types/Calculation/Store/values'; const initialValues: TValues = { + lead: null, + opportunity: null, + quote: null, + channel: null, + contactClient: null, + account: null, recalcWithRevision: false, contactGender: 100000000, leaseObjectPrice: 1000000, diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 43b5362..4d1a57e 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -79,7 +79,7 @@ export interface IEvoBaseproduct { evo_datefrom?: Date; evo_datefrom_param?: Date; evo_dateto_param?: Date; - evo_leaseobject_types?: IEvoLeasingObjectType[]; + evo_leasingobject_types?: IEvoLeasingObjectType[]; evo_brands?: IEvoBrand[]; }