add leaseback reactions

This commit is contained in:
Chika 2022-11-02 21:34:25 +03:00
parent 3d93f02a1e
commit e4f00bdb22
4 changed files with 163 additions and 1 deletions

View File

@ -316,6 +316,13 @@ export type GetRewardWithoutOtherAgentQueryVariables = Exact<{
export type GetRewardWithoutOtherAgentQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_agency_agreementidData?: { __typename?: 'evo_agency_agreement', evo_reward_without_other_agent?: boolean | null } | null } | null };
export type GetDealerReturnLeasingQueryVariables = Exact<{
dealerId: Scalars['Uuid'];
}>;
export type GetDealerReturnLeasingQuery = { __typename?: 'Query', dealer?: { __typename?: 'account', evo_return_leasing_dealer?: boolean | null } | null };
export type GetDealerPersonQueryVariables = Exact<{
dealerId: Scalars['Uuid'];
}>;

View File

@ -5,6 +5,7 @@ import * as leadOpportunityReactions from '../../lead-opportunity/reactions';
import paymentsReactions from '../../payments/reactions';
import * as priceReactions from '../../price/reactions';
import * as agentsReactions from '../../supplier-agent/reactions/agents';
import leasebackReactions from '../../supplier-agent/reactions/leaseback';
import * as supplierReactions from '../../supplier-agent/reactions/supplier';
import setInitialValuesReactions from '../set-values/reactions';
@ -18,6 +19,7 @@ export default function injectDefaultReactions(store, apolloClient, queryClient,
agentsReactions.fillReactions(store, apolloClient, queryClient);
agentsReactions.commonReactions(store, apolloClient, queryClient);
agentsReactions.validationReactions(store, apolloClient, queryClient);
leasebackReactions(store, apolloClient, queryClient);
priceReactions.computed(store, apolloClient, queryClient);
fingapReactions.common(store, apolloClient, queryClient);
fingapReactions.validation(store, apolloClient, queryClient);

View File

@ -0,0 +1,90 @@
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
export default function leasebackReactions(store: RootStore, apolloClient: ApolloClient<object>) {
const { $calculation, $tables } = store;
/**
* Дополнить реакцию на изменение поля Салон приобретения selectDealer:
если в поле selectDealer указан account, у которого evo_return_leasing_dealer = true, то
1) поле selectDealerPerson обнулять и закрывать для редактирования,
иначе формировать список связанных значений
2) в таблице страхования в столбце Плательщик
в строках ОСАГО и КАСКО указывать "Лизингополучатель" (100 000 000) и закрывать для редактирования ,
иначе открывать данные поля для редактирования
3) ПЛ БУ cbxLeaseObjectUsed = true
*/
const QUERY_GET_DEALER_RETURN_LEASING = gql`
query GetDealerReturnLeasing($dealerId: Uuid!) {
dealer: account(accountid: $dealerId) {
evo_return_leasing_dealer
}
}
`;
reaction(
() => $calculation.element('selectDealer').getValue(),
async (dealerId) => {
if (!dealerId) return;
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
if (dealer?.evo_return_leasing_dealer === true) {
$tables.insurance.row('kasko').setValue('insured', 100_000_000).block('insured');
$calculation.element('cbxLeaseObjectUsed').setValue(true);
} else {
$tables.insurance.row('kasko').resetStatus('insured');
}
}
);
// объединили реакцию для прицепа и возвратного лизинга
reaction(
() => ({
dealerId: $calculation.element('selectDealer').getValue(),
leaseObjectCategory: $calculation.element('selectLeaseObjectCategory').getValue(),
}),
async ({ dealerId, leaseObjectCategory }) => {
const isTrailer = leaseObjectCategory === 100_000_004;
let returnLeasing = false;
if (dealerId) {
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
returnLeasing = dealer?.evo_return_leasing_dealer === true;
}
if (isTrailer || returnLeasing) {
$tables.insurance.row('osago').setValue('insured', 100_000_000).block('insured');
} else {
$tables.insurance.row('osago').resetStatus('insured');
}
}
);
}

View File

@ -51,6 +51,8 @@ export default class InsuranceTable {
if (rowIndex >= 0) {
this.values[rowIndex] = { ...this.values[rowIndex], ...rowValues };
}
return this;
};
getRowOptions(key: Insurance.Keys) {
@ -67,6 +69,8 @@ export default class InsuranceTable {
setRowStatuses = (key: Insurance.Keys, rowStatuses: Partial<Insurance.RowStatuses>) => {
this.statuses[key] = { ...this.statuses[key], ...rowStatuses };
return this;
};
validate = ({ invalid, message }: ValidationParams) => {
@ -77,10 +81,69 @@ export default class InsuranceTable {
}
};
reset = () => {
resetTable = () => {
this.values = insuranceTableConfig.defaultValues;
this.options = insuranceTableConfig.defaultOptions;
this.statuses = insuranceTableConfig.defaultStatuses;
this.validation.clearErrors();
};
row = <K extends Insurance.Keys>(key: K) => ({
setValue: <V extends Insurance.Values>(valueName: V, value: Insurance.RowValues[V]) => {
const rowIndex = this.values.findIndex((x) => x.key === key);
if (rowIndex >= 0) {
this.values[rowIndex] = { ...this.values[rowIndex], [valueName]: value };
}
return this.row(key);
},
block: (valueName: Insurance.Values) => {
this.statuses[key][valueName] = 'Disabled';
return this.row(key);
},
unblock: (valueName: Insurance.Values) => {
this.statuses[key][valueName] = 'Default';
return this.row(key);
},
setOptions: <V extends Insurance.Values>(valueName: V, options: Insurance.RowOptions[V]) => {
this.options[key][valueName] = options;
return this.row(key);
},
resetValue: (valueName: Insurance.Values) => {
const rowIndex = this.values.findIndex((x) => x.key === key);
if (rowIndex >= 0) {
const defaultValue = insuranceTableConfig.defaultValues[rowIndex][valueName];
this.values[rowIndex] = { ...this.values[rowIndex], [valueName]: defaultValue };
}
return this.row(key);
},
resetStatus: (valueName: Insurance.Values) => {
this.statuses[key][valueName] = insuranceTableConfig.defaultStatuses[key][valueName];
return this.row(key);
},
resetOptions: <V extends Insurance.Values>(valueName: V) => {
this.options[key][valueName] = insuranceTableConfig.defaultOptions[key][valueName];
return this.row(key);
},
reset: (valueName: Insurance.Values) => {
this.row(key).resetValue(valueName).resetStatus(valueName).resetOptions(valueName);
return this.row(key);
},
});
}