vchikalkin 25ad87b7b2 В момент получения результата расчета из ELT (до вывода результата) по каждой Страховой компании осуществлять:
по КАСКО:

осуществлять проверку если в карточке Страховая компания "Фактическая доля" evo_kasko_fact_part > "Плановой доли" evo_kasko_plan_part, то в полученных результатах от ELT заменить значения:
"requestId": обнулять,
"skCalcId": обнулять
"sum": обнулять
"totalFranchise": обнулять
2024-08-01 13:13:33 +03:00

156 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { ownOsagoRequest } from './request';
import type * as ELT from '@/api/elt/types';
import type { Row } from '@/Components/Calculation/Form/ELT/types';
import { MAX_FRANCHISE, MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import { defaultRow } from '@/stores/tables/elt/default-values';
export function convertEltOsagoResponse(response: ELT.ResponseEltOsago, row: Row): Row {
const { message, numCalc, premiumSum = 0, skCalcId } = response;
let { error } = response;
if (premiumSum > MAX_INSURANCE) {
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости ОСАГО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_INSURANCE)}`;
}
if (premiumSum < MIN_INSURANCE) {
error ||= `Сумма по страховке не должна быть меньше допустимого значения по стоимости ОСАГО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MIN_INSURANCE)}`;
}
return {
...row,
message: error || message,
numCalc: `${numCalc}`,
skCalcId,
status: error ? 'error' : null,
sum: premiumSum,
};
}
type ResponseOwnOsago = Awaited<ReturnType<typeof ownOsagoRequest>>;
export function convertOwnOsagoResult(result: ResponseOwnOsago | undefined, row: Row): Row {
if (!result) {
return {
...row,
message:
'Для получения расчета ОСАГО следует использовать калькулятор ЭЛТ или Индивидуальный запрос',
numCalc: '',
skCalcId: '',
status: 'error',
sum: 0,
totalFranchise: 0,
};
}
if (!result.evo_id) {
return {
...row,
message: 'Сервер не вернул идентификатор страховки evo_id',
numCalc: '',
skCalcId: '',
status: 'error',
sum: result.evo_graph_price_withoutnds || 0,
};
}
return {
...row,
message: null,
numCalc: result.evo_id,
status: null,
sum: result.evo_graph_price_withoutnds || 0,
};
}
type ConvertEltKaskoResponseInput = {
context: Pick<ProcessContext, 'apolloClient' | 'store'>;
response: ELT.ResponseEltKasko;
row: Row;
};
export async function convertEltKaskoResponse(input: ConvertEltKaskoResponseInput): Promise<Row> {
const { context, response, row } = input;
const { apolloClient, store } = context;
const { kaskoSum = 0, message, paymentPeriods } = response;
let { requestId, skCalcId, totalFranchise = 0, error } = response;
const { $calculation } = store;
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
let sum = leasingPeriod <= 16 ? kaskoSum : paymentPeriods?.[0]?.kaskoSum || 0;
if (totalFranchise > MAX_FRANCHISE) {
error ||= `Франшиза по страховке превышает максимально допустимое значение: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_FRANCHISE)}`;
}
if (sum > MAX_INSURANCE) {
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости КАСКО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_INSURANCE)}`;
}
if (sum < MIN_INSURANCE) {
error ||= `Сумма по страховке не должна быть меньше допустимого значения по стоимости КАСКО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MIN_INSURANCE)}`;
}
const {
data: { account: insuranceCompany },
} = await apolloClient.query({
query: CRMTypes.GetInsuranceCompanyDocument,
variables: { accountId: row.key },
});
if (
insuranceCompany?.evo_kasko_fact_part !== null &&
insuranceCompany?.evo_kasko_plan_part !== undefined &&
insuranceCompany?.evo_kasko_plan_part !== null &&
insuranceCompany?.evo_kasko_plan_part !== undefined &&
insuranceCompany?.evo_kasko_fact_part > insuranceCompany?.evo_kasko_plan_part
) {
requestId = defaultRow.requestId;
skCalcId = defaultRow.skCalcId;
sum = defaultRow.sum;
totalFranchise = defaultRow.totalFranchise;
error = 'Расчет возможен только через отдел страхования ЛК';
}
return {
...row,
message: error || message,
numCalc: '0',
requestId,
skCalcId,
status: error ? 'error' : null,
sum,
totalFranchise,
};
}