Compare commits

...

12 Commits

Author SHA1 Message Date
vchikalkin
9454d9e2b2 fix: validation leaseObjectMotorPower evo_id !== '8' 2023-05-25 13:42:12 +03:00
vchikalkin
862e1293d3 elt/policy: change selectedKey reaction message 2023-05-24 10:51:11 +03:00
vchikalkin
d13beca5ed reactions: revert shallow comparer 2023-05-24 10:36:55 +03:00
vchikalkin
be48adbded fix prev commit 2023-05-23 20:56:39 +03:00
vchikalkin
a065e49249 fix: get fresh insurance companies before request 2023-05-23 20:49:42 +03:00
vchikalkin
3e774ab327 fix sync elt lists with insurance table lists 2023-05-22 18:29:08 +03:00
vchikalkin
4b3f62ccbe fix validation 2023-05-22 18:09:31 +03:00
vchikalkin
c24e5885bd reaction: fix reset fields lists 2023-05-22 17:49:57 +03:00
vchikalkin
dd7394f221 fix get fresh elt rows 2023-05-22 17:28:37 +03:00
vchikalkin
3087bc7d34 fix kasko result sum
request: use tbxInsFranchise value
reaction: reset kasko results on change tbxInsFranchise
2023-05-22 17:16:15 +03:00
vchikalkin
9bc1ffd093 Osago: totalFranchise text message 2023-05-22 15:58:55 +03:00
vchikalkin
06f5863e2b load-kp: allow quote?.evo_franchise = 0 2023-05-22 15:52:07 +03:00
7 changed files with 266 additions and 158 deletions

View File

@ -6,28 +6,42 @@ import type { Row, StoreSelector } from './types';
import { getEltKasko } from '@/api/elt/query';
import { STALE_TIME } from '@/constants/request';
import { MAX_FRANCHISE, MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import helper from '@/process/elt/lib/helper';
import { useStore } from '@/stores/hooks';
import { useApolloClient } from '@apollo/client';
import type { QueryFunctionContext } from '@tanstack/react-query';
import { useQueries } from '@tanstack/react-query';
import { observer } from 'mobx-react-lite';
import { Flex } from 'ui/grid';
const storeSelector: StoreSelector = ({ kasko }) => kasko;
export function Kasko() {
export const Kasko = observer(() => {
const store = useStore();
const { $tables, $calculation } = store;
const rows = $tables.elt.kasko.getRows;
const apolloClient = useApolloClient();
const { init } = helper({ apolloClient, store });
const queries = useQueries({
queries: rows.map((row) => {
queries: $tables.elt.kasko.getRows.map((row) => {
const { id, key } = row;
return {
cacheTime: 0,
enabled: false,
initialData: { ...row, error: '', kaskoSum: 0, sum: 0 },
initialData: {
...row,
error: '',
kaskoSum: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
sum: 0,
},
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltKaskoRequest({ apolloClient, store }, row);
const res = await getEltKasko(payload, context);
@ -43,79 +57,90 @@ export function Kasko() {
});
async function handleOnClick() {
const fetchingRows = rows.map((x) => ({ ...x, status: 'fetching', sum: 0 }));
$tables.elt.kasko.setRows(fetchingRows);
const { kasko } = await init();
$tables.elt.kasko.setRows(kasko);
queries.forEach(({ refetch, data }) => {
refetch()
.then((res) => {
if (res.data) {
const {
key,
kaskoSum = 0,
message,
skCalcId,
totalFranchise = 0,
requestId,
} = res.data;
let { error } = res.data;
const kaskoCompanyIds = $tables.insurance
.row('kasko')
.getOptions('insuranceCompany')
.map((x) => x.value);
const values = $calculation.$values.getValues();
if (totalFranchise > MAX_FRANCHISE) {
error ||= `Франшиза по страховке превышает максимально допустимое значение: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_FRANCHISE)}`;
queries
.filter(({ data }) => data?.key && kaskoCompanyIds.includes(data.key))
.forEach(({ refetch, data }) => {
if (data?.key) $tables.elt.kasko.setRow({ key: data?.key, status: 'fetching' });
refetch()
.then((res) => {
if (res.data) {
const {
key,
kaskoSum = 0,
message,
skCalcId,
totalFranchise = 0,
requestId,
paymentPeriods,
} = res.data;
let { error } = res.data;
if (totalFranchise > MAX_FRANCHISE) {
error ||= `Франшиза по страховке превышает максимально допустимое значение: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_FRANCHISE)}`;
}
if (kaskoSum > MAX_INSURANCE) {
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости КАСКО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_INSURANCE)}`;
}
if (kaskoSum < MIN_INSURANCE) {
error ||= `Сумма по страховке не должна быть меньше допустимого значения по стоимости КАСКО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MIN_INSURANCE)}`;
}
$tables.elt.kasko.setRow({
key,
message: error || message,
numCalc: 0,
requestId,
skCalcId,
status: error ? 'error' : null,
sum: values.leasingPeriod <= 16 ? kaskoSum : paymentPeriods.at(0)?.kaskoSum || 0,
totalFranchise,
});
}
if (kaskoSum > MAX_INSURANCE) {
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости КАСКО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_INSURANCE)}`;
}
if (kaskoSum < MIN_INSURANCE) {
error ||= `Сумма по страховке не должна быть меньше допустимого значения по стоимости КАСКО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MIN_INSURANCE)}`;
}
$tables.elt.kasko.setRow({
key,
message: error || message,
numCalc: 0,
requestId,
skCalcId,
status: error ? 'error' : null,
sum: kaskoSum,
totalFranchise,
});
}
})
.catch((error) => {
if (data?.key)
$tables.elt.kasko.setRow({
key: data?.key,
message: error,
numCalc: 0,
requestId: '',
skCalcId: '',
status: 'error',
sum: 0,
totalFranchise: 0,
});
});
});
})
.catch((error) => {
if (data?.key)
$tables.elt.kasko.setRow({
key: data?.key,
message: error,
numCalc: 0,
requestId: '',
skCalcId: '',
status: 'error',
sum: 0,
totalFranchise: 0,
});
});
});
}
function handleOnSelectRow(row: Row) {
@ -153,4 +178,4 @@ export function Kasko() {
/>
</Flex>
);
}
});

View File

@ -6,26 +6,30 @@ import type { Row, StoreSelector } from './types';
import { getEltOsago } from '@/api/elt/query';
import { STALE_TIME } from '@/constants/request';
import { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import helper from '@/process/elt/lib/helper';
import { useStore } from '@/stores/hooks';
import { useApolloClient } from '@apollo/client';
import type { QueryFunctionContext } from '@tanstack/react-query';
import { useQueries } from '@tanstack/react-query';
import { observer } from 'mobx-react-lite';
import { Flex } from 'ui/grid';
const storeSelector: StoreSelector = ({ osago }) => osago;
export function Osago() {
export const Osago = observer(() => {
const store = useStore();
const { $tables } = store;
const rows = $tables.elt.osago.getRows;
const apolloClient = useApolloClient();
const { init } = helper({ apolloClient, store });
const queries = useQueries({
queries: rows.map((row) => {
queries: $tables.elt.osago.getRows.map((row) => {
const { id, key } = row;
return {
cacheTime: 0,
enabled: false,
initialData: { ...row, error: '', premiumSum: 0 },
queryFn: async (context: QueryFunctionContext) => {
@ -43,58 +47,67 @@ export function Osago() {
});
async function handleOnClick() {
const fetchingRows = rows.map((x) => ({ ...x, status: 'fetching', sum: 0 }));
$tables.elt.osago.setRows(fetchingRows);
const { osago } = await init();
$tables.elt.osago.setRows(osago);
queries.forEach(({ refetch, data }) => {
refetch()
.then((res) => {
if (res.data) {
const { key, numCalc, premiumSum = 0, message, skCalcId } = res.data;
let { error } = res.data;
const osagoCompanyIds = $tables.insurance
.row('osago')
.getOptions('insuranceCompany')
.map((x) => x.value);
if (premiumSum > MAX_INSURANCE) {
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости ОСАГО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MAX_INSURANCE)}`;
queries
.filter(({ data }) => data?.key && osagoCompanyIds.includes(data.key))
.forEach(({ refetch, data }) => {
if (data?.key) $tables.elt.osago.setRow({ key: data?.key, status: 'fetching' });
refetch()
.then((res) => {
if (res.data) {
const { key, numCalc, premiumSum = 0, message, skCalcId } = res.data;
let { error } = res.data;
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,
skCalcId,
status: error ? 'error' : null,
sum: premiumSum,
});
}
if (premiumSum < MIN_INSURANCE) {
error ||= `Сумма по страховке не должна быть меньше допустимого значения по стоимости ОСАГО: ${Intl.NumberFormat(
'ru',
{
currency: 'RUB',
style: 'currency',
}
).format(MIN_INSURANCE)}`;
}
$tables.elt.osago.setRow({
key,
message: error || message,
numCalc,
skCalcId,
status: error ? 'error' : null,
sum: premiumSum,
});
}
})
.catch((error) => {
if (data?.key)
$tables.elt.osago.setRow({
key: data?.key,
message: error,
numCalc: 0,
skCalcId: '',
status: 'error',
sum: 0,
});
});
});
})
.catch((error) => {
if (data?.key)
$tables.elt.osago.setRow({
key: data?.key,
message: error,
numCalc: 0,
skCalcId: '',
status: 'error',
sum: 0,
});
});
});
}
function handleOnSelectRow(row: Row) {
@ -118,6 +131,13 @@ export function Osago() {
};
}
if (column.key === 'totalFranchise') {
return {
...column,
render: () => 'Не требуется',
};
}
return column;
});
@ -131,4 +151,4 @@ export function Osago() {
/>
</Flex>
);
}
});

View File

@ -439,7 +439,7 @@ export async function makeEltKaskoRequest(
outsideRoadsSpecified = true;
}
const franchise = row.totalFranchise;
const franchise = $calculation.element('tbxInsFranchise').getValue();
const franchiseSpecified = getSpecified(franchise);
let puuMark = '';

View File

@ -41,7 +41,7 @@ export async function getKPData({
quote?.evo_id_elt_kasko &&
quote?.evo_id_kasko_calc &&
quote?.evo_kasko_price &&
quote?.evo_franchise
quote?.evo_franchise !== null
) {
elt.kasko = {
key: quote?.evo_kasko_accountid,

View File

@ -13,30 +13,83 @@ export default function reactions(context: ProcessContext) {
() => $process.has('ELT') || $process.has('LoadKP'),
() => ({
values: $calculation.$values.getValues([
'leaseObjectType',
// osago
'townRegistration',
'legalClientTown',
'legalClientRegion',
'objectRegistration',
'townRegistration',
// kasko
'legalClientRegion',
'legalClientTown',
'brand',
'model',
'GPSBrand',
'GPSModel',
'leaseObjectYear',
'leaseObjectCategory',
'leaseObjectMotorPower',
'leaseObjectUseFor',
'maxMass',
'countSeats',
'withTrailer',
'lead',
'opportunity',
'leaseObjectUseFor',
'leaseObjectCategory',
'insDecentral',
'leasingWithoutKasko',
'leaseObjectType',
'insAgeDrivers',
'insExpDrivers',
'vin',
'leaseObjectUsed',
'leasingPeriod',
'leaseObjectPrice',
]),
}),
async () => {
const initialValues = await init();
if (initialValues) {
$tables.elt.osago.setRows(initialValues.osago);
}
},
{
delay: 10,
equals: comparer.shallow,
fireImmediately: true,
}
);
disposableReaction(
() => $process.has('ELT') || $process.has('LoadKP'),
() => ({
values: $calculation.$values.getValues([
'legalClientRegion',
'legalClientTown',
'leaseObjectType',
'leaseObjectCategory',
'brand',
'model',
'leaseObjectMotorPower',
'leaseObjectPrice',
'supplierDiscountRub',
'leaseObjectUsed',
'product',
'leaseObjectYear',
'leaseObjectMotorPower',
'engineType',
'leasingPeriod',
'plPriceRub',
'discountRub',
'importProgramSum',
'addEquipmentPrice',
'insFranchise',
'GPSBrand',
'GPSModel',
'insAgeDrivers',
'insExpDrivers',
'insUnlimitDrivers',
'maxMass',
'mileage',
'vin',
'leaseObjectUseFor',
'countSeats',
'lead',
'opportunity',
'withTrailer',
'insDecentral',
'leasingWithoutKasko',
]),
}),
async () => {
@ -44,7 +97,6 @@ export default function reactions(context: ProcessContext) {
if (initialValues) {
$tables.elt.kasko.setRows(initialValues.kasko);
$tables.elt.osago.setRows(initialValues.osago);
}
},
{

View File

@ -88,14 +88,6 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
});
}
if (!leaseObjectMotorPower) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле ' + titles.tbxLeaseObjectMotorPower,
path: ['eltKasko', 'eltOsago'],
});
}
if (!leaseObjectUseFor) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
@ -114,6 +106,14 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
},
});
if (evo_leasingobject_type?.evo_id !== '8' && !leaseObjectMotorPower) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле ' + titles.tbxLeaseObjectMotorPower,
path: ['eltKasko', 'eltOsago'],
});
}
// Проверяем на мотоцикл
if (evo_leasingobject_type?.evo_id && ['11'].includes(evo_leasingobject_type?.evo_id)) {
ctx.addIssue({
@ -124,6 +124,17 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
});
}
if (
evo_leasingobject_type?.evo_id &&
!['1', '2', '3', '6', '7', '9', '10'].includes(evo_leasingobject_type?.evo_id)
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Для выбранной категории ТС расчет в ЭЛТ недоступен',
path: ['eltOsago'],
});
}
if (
evo_leasingobject_type?.evo_id &&
!['1', '2', '3', '6', '7', '8', '9', '10'].includes(evo_leasingobject_type?.evo_id)
@ -131,7 +142,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Для выбранной категории ТС расчет в ЭЛТ недоступен',
path: ['eltKasko', 'eltOsago'],
path: ['eltKasko'],
});
}
}
@ -146,7 +157,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
code: z.ZodIssueCode.custom,
message:
'По данной цели использования возможен только индивидуальный запрос тарифов КАСКО и ОСАГО. Просьба обратиться на адрес strakhovka@evoleasing.ru',
path: ['eltKasko'],
path: ['eltKasko', 'eltOsago'],
});
}
@ -154,7 +165,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не указан Регион по юр.адресу клиента',
path: ['eltKasko'],
path: ['eltKasko', 'eltOsago'],
});
}
@ -182,7 +193,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не указана категория ТС',
path: ['eltKasko'],
path: ['eltKasko', 'eltOsago'],
});
}
}
@ -191,7 +202,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Децентрализованное страхование не может быть расчитано в ЭЛТ',
path: ['eltKasko'],
path: ['eltKasko', 'eltOsago'],
});
}
@ -245,7 +256,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
code: z.ZodIssueCode.custom,
message:
'По данному ОКВЭД Контрагента возможен только индивидуальный запрос тарифов КАСКО/ОСАГО. Просьба обратиться на адрес strakhovka@evoleasing.ru',
path: ['eltKasko'],
path: ['eltKasko', 'eltOsago'],
});
}
}

View File

@ -35,7 +35,7 @@ export default class PolicyStore {
(selectedKey) => {
if (!selectedKey) {
notification.open({
description: 'Расчеты ЭЛТ были сброшены',
description: 'Выбранный расчет ЭЛТ был сброшен',
key: validationConfig.err_key,
message: validationConfig.err_title,
type: 'warning',