merge branch release/dyn-3905_elt-osago

This commit is contained in:
vchikalkin 2024-04-08 21:09:28 +03:00
parent a0e6c4ff2f
commit bd7cf3284b
11 changed files with 5204 additions and 168 deletions

View File

@ -103,7 +103,7 @@ export const Kasko = observer(() => {
$tables.elt.kasko.setRow({ $tables.elt.kasko.setRow({
key, key,
message: error || message, message: error || message,
numCalc: 0, numCalc: '0',
requestId, requestId,
skCalcId, skCalcId,
status: error ? 'error' : null, status: error ? 'error' : null,

View File

@ -1,7 +1,8 @@
/* eslint-disable no-negated-condition */
/* eslint-disable sonarjs/cognitive-complexity */ /* eslint-disable sonarjs/cognitive-complexity */
import { PolicyTable, ReloadButton, Validation } from './Components'; import { PolicyTable, ReloadButton, Validation } from './Components';
import { columns } from './lib/config'; import { columns } from './lib/config';
import { makeEltOsagoRequest } from './lib/make-request'; import { makeEltOsagoRequest, makeOwnOsagoRequest } from './lib/make-request';
import type { Row, StoreSelector } from './types'; import type { Row, StoreSelector } from './types';
import { getEltOsago } from '@/api/elt/query'; import { getEltOsago } from '@/api/elt/query';
import { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values'; import { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
@ -40,56 +41,83 @@ export const Osago = observer(() => {
.getOptions('insuranceCompany') .getOptions('insuranceCompany')
.map((x) => x.value) .map((x) => x.value)
); );
osagoCompanyIds.forEach((key) => { osagoCompanyIds.forEach((key) => {
const row = $tables.elt.osago.getRow(key); const row = $tables.elt.osago.getRow(key);
if (row) { if (row) {
row.status = 'fetching'; row.status = 'fetching';
$tables.elt.osago.setRow(row); $tables.elt.osago.setRow(row);
makeEltOsagoRequest({ apolloClient, store }, row)
.then((payload) => if (row.metodCalc === 'CRM') {
getEltOsago(payload, { signal: $tables.elt.osago.abortController.signal }) makeOwnOsagoRequest({ apolloClient, store }, row).then((res) => {
) if (!res) {
.then((res) => {
if (res) {
const { numCalc, premiumSum = 0, message, skCalcId } = res;
let { error } = res;
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)}`;
}
$tables.elt.osago.setRow({ $tables.elt.osago.setRow({
key, key,
message: error || message, message:
numCalc, 'Для получения расчета ОСАГО следует использовать калькулятор ЭЛТ или Индивидуальный запрос',
skCalcId, numCalc: undefined,
status: error ? 'error' : null, skCalcId: undefined,
sum: premiumSum, status: 'error',
sum: 0,
totalFranchise: 0,
});
} else {
$tables.elt.osago.setRow({
key,
message: null,
numCalc: res.evo_id || undefined,
status: null,
sum: res.evo_graph_price_withoutnds || undefined,
}); });
} }
})
.catch((error) => {
const _err = error as Error;
$tables.elt.osago.setRow({
...initialData,
key,
message: _err.message || String(error),
status: 'error',
});
}); });
} else {
makeEltOsagoRequest({ apolloClient, store }, row)
.then((payload) =>
getEltOsago(payload, { signal: $tables.elt.osago.abortController.signal })
)
.then((res) => {
if (res) {
const { message, numCalc, premiumSum = 0, skCalcId } = res;
let { error } = res;
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)}`;
}
$tables.elt.osago.setRow({
key,
message: error || message,
numCalc: `${numCalc}`,
skCalcId,
status: error ? 'error' : null,
sum: premiumSum,
});
}
})
.catch((error) => {
const _err = error as Error;
$tables.elt.osago.setRow({
...initialData,
key,
message: _err.message || String(error),
status: 'error',
});
});
}
} }
}); });
}, [$tables.elt.osago, $tables.insurance, apolloClient, init, store]); }, [$tables.elt.osago, $tables.insurance, apolloClient, init, store]);

View File

@ -4,7 +4,56 @@ import type { Row } from '../types';
import type { RequestEltKasko, RequestEltOsago } from '@/api/elt/types'; import type { RequestEltKasko, RequestEltOsago } from '@/api/elt/types';
import * as CRMTypes from '@/graphql/crm.types'; import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types'; import type { ProcessContext } from '@/process/types';
import { getCurrentISODate } from '@/utils/date';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { first, sort } from 'radash';
export async function makeOwnOsagoRequest(
{ store, apolloClient }: Pick<ProcessContext, 'apolloClient' | 'store'>,
row: Row
): Promise<NonNullable<CRMTypes.GetOsagoAddproductTypesQuery['evo_addproduct_types']>[number]> {
const currentDate = getCurrentISODate();
const {
data: { evo_addproduct_types },
} = await apolloClient.query({
query: CRMTypes.GetOsagoAddproductTypesDocument,
variables: { currentDate },
});
if (!evo_addproduct_types) return null;
const { leaseObjectCategory, leaseObjectMotorPower, countSeats, maxMass } =
store.$calculation.$values.getValues([
'leaseObjectCategory',
'leaseObjectMotorPower',
'countSeats',
'maxMass',
]);
const filteredTypes = evo_addproduct_types.filter(
(type) =>
type?.evo_accountid === row.key &&
type.evo_visible_calc &&
type.evo_category === leaseObjectCategory &&
type.evo_min_power !== null &&
type.evo_max_power !== null &&
type.evo_min_power <= leaseObjectMotorPower &&
type.evo_max_power >= leaseObjectMotorPower &&
type.evo_min_seats_count !== null &&
type.evo_max_seats_count !== null &&
type.evo_min_seats_count <= countSeats &&
type.evo_max_seats_count >= countSeats &&
type.evo_min_mass !== null &&
type.evo_max_mass !== null &&
type.evo_min_mass <= maxMass &&
type.evo_max_mass >= maxMass
);
const sortedTypes = sort(filteredTypes, (type) => dayjs(type?.createdon).date());
return first(sortedTypes) || null;
}
const getSpecified = (value: unknown) => value !== null && value !== undefined; const getSpecified = (value: unknown) => value !== null && value !== undefined;

View File

@ -272,8 +272,9 @@ export const RowSchema = z.object({
id: z.string(), id: z.string(),
key: z.string(), key: z.string(),
message: z.string().nullable(), message: z.string().nullable(),
metodCalc: z.union([z.literal('CRM'), z.literal('ELT')]),
name: z.string(), name: z.string(),
numCalc: z.number(), numCalc: z.string(),
requestId: z.string(), requestId: z.string(),
skCalcId: z.string(), skCalcId: z.string(),
status: z.string().nullable(), status: z.string().nullable(),

View File

@ -307,6 +307,7 @@ query GetTarif($tarifId: Uuid!) {
evo_rates { evo_rates {
evo_datefrom evo_datefrom
evo_rateid evo_rateid
evo_type
} }
evo_irr_plan evo_irr_plan
evo_margin_min evo_margin_min
@ -847,6 +848,29 @@ query GetLeasingWithoutKaskoTypes($currentDate: DateTime) {
} }
} }
query GetOsagoAddproductTypes($currentDate: DateTime) {
evo_addproduct_types(
statecode: 0
evo_product_type: 100000008
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
evo_product_type
evo_visible_calc
evo_accountid
createdon
evo_category
evo_min_power
evo_max_power
evo_min_seats_count
evo_max_seats_count
evo_min_mass
evo_max_mass
evo_graph_price_withoutnds
evo_id
}
}
query GetInsuranceCompany($accountId: Uuid!) { query GetInsuranceCompany($accountId: Uuid!) {
account(accountid: $accountId) { account(accountid: $accountId) {
evo_osago_with_kasko evo_osago_with_kasko
@ -865,6 +889,7 @@ query GetInsuranceCompanies {
evo_id_elt_osago evo_id_elt_osago
evo_id_elt evo_id_elt
evo_id_elt_smr evo_id_elt_smr
evo_osago_id
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -105,9 +105,12 @@ export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloCli
variables: { tarifId }, variables: { tarifId },
}); });
const filtered_evo_tarif_evo_rates =
evo_tarif?.evo_rates?.filter((x) => x?.evo_type === 100_000_000) || [];
const evo_tarif_evo_rate = const evo_tarif_evo_rate =
evo_tarif?.evo_rates && evo_tarif?.evo_rates &&
first(sort(evo_tarif?.evo_rates, (x) => dayjs(x?.evo_datefrom).date())); first(sort(filtered_evo_tarif_evo_rates, (x) => dayjs(x?.evo_datefrom).date()));
if (evo_tarif_evo_rate) { if (evo_tarif_evo_rate) {
return { return {

View File

@ -22,7 +22,7 @@ export async function getKPData({ quote }: GetQuoteInputData): Promise<GetQuoteP
if (quote?.evo_osago_accountid && quote?.evo_id_elt_osago && quote?.evo_osago_price) { if (quote?.evo_osago_accountid && quote?.evo_id_elt_osago && quote?.evo_osago_price) {
elt.osago = { elt.osago = {
key: quote?.evo_osago_accountid, key: quote?.evo_osago_accountid,
numCalc: Number.parseInt(quote?.evo_id_elt_osago, 10), numCalc: quote?.evo_id_elt_osago,
sum: quote?.evo_osago_price, sum: quote?.evo_osago_price,
}; };
} }

View File

@ -50,11 +50,16 @@ export default function helper({
name: x?.label, name: x?.label,
})) || []) as Row[], })) || []) as Row[],
osago: (accounts osago: (accounts
?.filter((x) => x?.evo_type_ins_policy?.includes(100_000_001) && x?.evo_id_elt_osago) ?.filter(
(x) =>
x?.evo_type_ins_policy?.includes(100_000_001) &&
(x?.evo_id_elt_osago || x.evo_osago_id)
)
.map((x) => ({ .map((x) => ({
...defaultRow, ...defaultRow,
id: x?.evo_id_elt_osago, id: x?.evo_id_elt_osago || x?.evo_osago_id,
key: x?.value, key: x?.value,
metodCalc: x?.evo_osago_id ? 'CRM' : 'ELT',
name: x?.label, name: x?.label,
})) || []) as Row[], })) || []) as Row[],
}; };

View File

@ -4,8 +4,9 @@ export const defaultRow: ELT.Row = {
id: '', id: '',
key: '', key: '',
message: null, message: null,
metodCalc: 'ELT',
name: '', name: '',
numCalc: 0, numCalc: '0',
requestId: '', requestId: '',
skCalcId: '', skCalcId: '',
status: null, status: null,