merge branch release/dyn-3905_elt-osago
This commit is contained in:
parent
a0e6c4ff2f
commit
bd7cf3284b
@ -103,7 +103,7 @@ export const Kasko = observer(() => {
|
||||
$tables.elt.kasko.setRow({
|
||||
key,
|
||||
message: error || message,
|
||||
numCalc: 0,
|
||||
numCalc: '0',
|
||||
requestId,
|
||||
skCalcId,
|
||||
status: error ? 'error' : null,
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
/* eslint-disable no-negated-condition */
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
import { PolicyTable, ReloadButton, Validation } from './Components';
|
||||
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 { getEltOsago } from '@/api/elt/query';
|
||||
import { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
|
||||
@ -40,56 +41,83 @@ export const Osago = observer(() => {
|
||||
.getOptions('insuranceCompany')
|
||||
.map((x) => x.value)
|
||||
);
|
||||
|
||||
osagoCompanyIds.forEach((key) => {
|
||||
const row = $tables.elt.osago.getRow(key);
|
||||
if (row) {
|
||||
row.status = 'fetching';
|
||||
$tables.elt.osago.setRow(row);
|
||||
makeEltOsagoRequest({ apolloClient, store }, row)
|
||||
.then((payload) =>
|
||||
getEltOsago(payload, { signal: $tables.elt.osago.abortController.signal })
|
||||
)
|
||||
.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)}`;
|
||||
}
|
||||
|
||||
if (row.metodCalc === 'CRM') {
|
||||
makeOwnOsagoRequest({ apolloClient, store }, row).then((res) => {
|
||||
if (!res) {
|
||||
$tables.elt.osago.setRow({
|
||||
key,
|
||||
message: error || message,
|
||||
numCalc,
|
||||
skCalcId,
|
||||
status: error ? 'error' : null,
|
||||
sum: premiumSum,
|
||||
message:
|
||||
'Для получения расчета ОСАГО следует использовать калькулятор ЭЛТ или Индивидуальный запрос',
|
||||
numCalc: undefined,
|
||||
skCalcId: undefined,
|
||||
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]);
|
||||
|
||||
@ -4,7 +4,56 @@ import type { Row } from '../types';
|
||||
import type { RequestEltKasko, RequestEltOsago } from '@/api/elt/types';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import { getCurrentISODate } from '@/utils/date';
|
||||
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;
|
||||
|
||||
|
||||
@ -272,8 +272,9 @@ export const RowSchema = z.object({
|
||||
id: z.string(),
|
||||
key: z.string(),
|
||||
message: z.string().nullable(),
|
||||
metodCalc: z.union([z.literal('CRM'), z.literal('ELT')]),
|
||||
name: z.string(),
|
||||
numCalc: z.number(),
|
||||
numCalc: z.string(),
|
||||
requestId: z.string(),
|
||||
skCalcId: z.string(),
|
||||
status: z.string().nullable(),
|
||||
|
||||
@ -307,6 +307,7 @@ query GetTarif($tarifId: Uuid!) {
|
||||
evo_rates {
|
||||
evo_datefrom
|
||||
evo_rateid
|
||||
evo_type
|
||||
}
|
||||
evo_irr_plan
|
||||
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!) {
|
||||
account(accountid: $accountId) {
|
||||
evo_osago_with_kasko
|
||||
@ -865,6 +889,7 @@ query GetInsuranceCompanies {
|
||||
evo_id_elt_osago
|
||||
evo_id_elt
|
||||
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
@ -105,9 +105,12 @@ export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloCli
|
||||
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 =
|
||||
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) {
|
||||
return {
|
||||
|
||||
@ -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) {
|
||||
elt.osago = {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
@ -50,11 +50,16 @@ export default function helper({
|
||||
name: x?.label,
|
||||
})) || []) as Row[],
|
||||
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) => ({
|
||||
...defaultRow,
|
||||
id: x?.evo_id_elt_osago,
|
||||
id: x?.evo_id_elt_osago || x?.evo_osago_id,
|
||||
key: x?.value,
|
||||
metodCalc: x?.evo_osago_id ? 'CRM' : 'ELT',
|
||||
name: x?.label,
|
||||
})) || []) as Row[],
|
||||
};
|
||||
|
||||
@ -4,8 +4,9 @@ export const defaultRow: ELT.Row = {
|
||||
id: '',
|
||||
key: '',
|
||||
message: null,
|
||||
metodCalc: 'ELT',
|
||||
name: '',
|
||||
numCalc: 0,
|
||||
numCalc: '0',
|
||||
requestId: '',
|
||||
skCalcId: '',
|
||||
status: null,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user