91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
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');
|
||
}
|
||
}
|
||
);
|
||
}
|