process: add 1c request to gibdd

This commit is contained in:
vchikalkin 2023-02-22 15:46:44 +03:00
parent 21b01d9e18
commit 32b706d563
17 changed files with 678 additions and 516 deletions

3
.env
View File

@ -8,4 +8,5 @@ USERS_SUPER=["akalinina","vchikalkin"]
####### URLS ########
URL_GET_USER_DIRECT=
URL_CRM_GRAPHQL_DIRECT=
URL_CORE_FINGAP_DIRECT=
URL_CORE_FINGAP_DIRECT=
URL_1C_TRANSTAX_DIRECT=

View File

@ -365,7 +365,7 @@ const props: Partial<ElementsProps> = {
linkDownloadKp: {
type: 'primary',
text: 'Скачать КП',
icon: DownloadOutlined,
icon: <DownloadOutlined />,
},
tbxMileage: {
min: 0,

View File

@ -7,8 +7,10 @@ import map from '../map';
import type { RenderProps } from './types';
import { Container, Head } from '@/Components/Layout/Element';
import { useStore } from '@/stores/hooks';
import { useIsFetching } from '@tanstack/react-query';
import { observer } from 'mobx-react-lite';
import type { ComponentProps } from 'react';
import { LoadingOutlined } from 'ui/elements/icons';
import Link from 'ui/elements/Link';
import Tooltip from 'ui/elements/Tooltip';
@ -192,14 +194,24 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
valueName,
});
return (
<Tooltip placement="topLeft" title="Без учета налога на роскошь">
<Container>
<Head htmlFor={elementName} title={title} />
<Element {...props} id={elementName} />
</Container>
</Tooltip>
);
function RenderedComponent() {
const isFetching = useIsFetching({ queryKey: ['1c', 'trans-tax'] });
return (
<Tooltip placement="topLeft" title="Без учета налога на роскошь">
<Container>
<Head htmlFor={elementName} title={title} />
<Element
{...props}
id={elementName}
addonBefore={isFetching && <LoadingOutlined spin />}
/>
</Container>
</Tooltip>
);
}
return <RenderedComponent />;
},
},
};

12
apps/web/api/1c/query.ts Normal file
View File

@ -0,0 +1,12 @@
import type { RequestTransTax, ResponseTransTax } from './types';
import getUrls from '@/config/urls';
import type { QueryFunctionContext } from '@tanstack/react-query';
import axios from 'axios';
const { URL_1C_TRANSTAX } = getUrls();
export async function getTransTax(payload: RequestTransTax, { signal }: QueryFunctionContext) {
const { data } = await axios.post<ResponseTransTax>(URL_1C_TRANSTAX, payload, { signal });
return data;
}

11
apps/web/api/1c/types.ts Normal file
View File

@ -0,0 +1,11 @@
export type RequestTransTax = {
OKTMO: string;
calcDate: Date;
carCategory: string;
power: number;
year: number;
};
export type ResponseTransTax = {
error: string;
tax: number;
};

View File

@ -3,6 +3,7 @@ const { z } = require('zod');
const envSchema = z.object({
BASE_PATH: z.string().optional().default(''),
PORT: z.string().optional(),
URL_1C_TRANSTAX_DIRECT: z.string(),
URL_CORE_FINGAP_DIRECT: z.string(),
URL_CRM_GRAPHQL_DIRECT: z.string(),
URL_GET_USER_DIRECT: z.string(),

View File

@ -9,6 +9,7 @@ const publicRuntimeConfigSchema = envSchema.pick({
const serverRuntimeConfigSchema = envSchema.pick({
BASE_PATH: true,
PORT: true,
URL_1C_TRANSTAX_DIRECT: true,
URL_CORE_FINGAP_DIRECT: true,
URL_CRM_GRAPHQL_DIRECT: true,
URL_GET_USER_DIRECT: true,

View File

@ -9,12 +9,18 @@ function getUrls() {
const { BASE_PATH } = publicRuntimeConfigSchema.parse(publicRuntimeConfig);
if (isServer()) {
const { URL_CRM_GRAPHQL_DIRECT, URL_GET_USER_DIRECT, URL_CORE_FINGAP_DIRECT, PORT } =
serverRuntimeConfigSchema.parse(serverRuntimeConfig);
const {
URL_CRM_GRAPHQL_DIRECT,
URL_GET_USER_DIRECT,
URL_CORE_FINGAP_DIRECT,
URL_1C_TRANSTAX_DIRECT,
PORT,
} = serverRuntimeConfigSchema.parse(serverRuntimeConfig);
return {
BASE_PATH,
PORT,
URL_1C_TRANSTAX: URL_1C_TRANSTAX_DIRECT,
URL_CORE_FINGAP: URL_CORE_FINGAP_DIRECT,
URL_CRM_GRAPHQL: URL_CRM_GRAPHQL_DIRECT,
URL_GET_USER: URL_GET_USER_DIRECT,
@ -27,6 +33,7 @@ function getUrls() {
return {
BASE_PATH,
URL_1C_TRANSTAX: withBasePath(urls.URL_1C_TRANSTAX_PROXY),
URL_CORE_FINGAP: withBasePath(urls.URL_CORE_FINGAP_PROXY),
URL_CRM_GRAPHQL: withBasePath(urls.URL_CRM_GRAPHQL_PROXY),
URL_GET_USER: withBasePath(urls.URL_GET_USER_PROXY),

View File

@ -1,4 +1,5 @@
module.exports = {
URL_1C_TRANSTAX_PROXY: '/api/1c/transtax',
URL_CORE_FINGAP_PROXY: '/api/core/fingap',
URL_CRM_GRAPHQL_PROXY: '/api/graphql/crm',
URL_GET_USER_PROXY: '/api/auth/user',

View File

@ -210,6 +210,12 @@ query GetRegions {
}
}
query GetRegion($regionId: Uuid!) {
evo_region(evo_regionid: $regionId) {
evo_oktmo
}
}
query GetGPSBrands {
evo_gps_brands(statecode: 0) {
label: evo_name

File diff suppressed because it is too large Load Diff

View File

@ -245,6 +245,13 @@ export type GetRegionsQueryVariables = Exact<{ [key: string]: never; }>;
export type GetRegionsQuery = { __typename?: 'Query', evo_regions: Array<{ __typename?: 'evo_region', label: string | null, value: string | null } | null> | null };
export type GetRegionQueryVariables = Exact<{
regionId: Scalars['Uuid'];
}>;
export type GetRegionQuery = { __typename?: 'Query', evo_region: { __typename?: 'evo_region', evo_oktmo: string | null } | null };
export type GetGpsBrandsQueryVariables = Exact<{ [key: string]: never; }>;
@ -490,6 +497,7 @@ export const GetSubsidiesDocument = {"kind":"Document","definitions":[{"kind":"O
export const GetSubsidyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSubsidy"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"subsidyId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_subsidy"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_subsidyid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"subsidyId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"accounts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_brands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brandid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_models"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_modelid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_subsidy_summ"}},{"kind":"Field","name":{"kind":"Name","value":"evo_percent_subsidy"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_subsidy_summ"}}]}}]}}]} as unknown as DocumentNode<GetSubsidyQuery, GetSubsidyQueryVariables>;
export const GetImportProgramDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetImportProgram"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"importProgramId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"importProgram"},"name":{"kind":"Name","value":"evo_subsidy"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_subsidyid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"importProgramId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"accounts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_brands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brandid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_models"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_modelid"}}]}}]}}]}}]} as unknown as DocumentNode<GetImportProgramQuery, GetImportProgramQueryVariables>;
export const GetRegionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRegions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_regions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_regionid"}}]}}]}}]} as unknown as DocumentNode<GetRegionsQuery, GetRegionsQueryVariables>;
export const GetRegionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRegion"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"regionId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_region"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_regionid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"regionId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_oktmo"}}]}}]}}]} as unknown as DocumentNode<GetRegionQuery, GetRegionQueryVariables>;
export const GetGpsBrandsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetGPSBrands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_gps_brands"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_gps_brandid"}}]}}]}}]} as unknown as DocumentNode<GetGpsBrandsQuery, GetGpsBrandsQueryVariables>;
export const GetLeaseObjectTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectTypes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_leasingobject_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}}]}}]} as unknown as DocumentNode<GetLeaseObjectTypesQuery, GetLeaseObjectTypesQueryVariables>;
export const GetLeaseObjectTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leasingobject_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type_tax"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category_tr"}}]}}]}}]} as unknown as DocumentNode<GetLeaseObjectTypeQuery, GetLeaseObjectTypeQueryVariables>;

View File

@ -23,7 +23,7 @@ const users = {
},
};
const { URL_GET_USER, URL_CORE_FINGAP, URL_CRM_GRAPHQL } = getUrls();
const { URL_GET_USER, URL_CORE_FINGAP, URL_1C_TRANSTAX } = getUrls();
export const handlers = [
rest.get(URL_GET_USER, (req, res, ctx) => {
@ -37,6 +37,15 @@ export const handlers = [
})
);
}),
rest.post(URL_1C_TRANSTAX, (req, res, ctx) => {
return res(
ctx.json({
error: null,
tax: _.random(100000, 200000),
})
);
}),
// rest.post(URL_CRM_GRAPHQL, (req, res, ctx) => {
// return res(ctx.status(503));
// }),

View File

@ -52,6 +52,10 @@ const nextConfig = {
destination: env.URL_CORE_FINGAP_DIRECT,
source: urls.URL_CORE_FINGAP_PROXY,
},
{
destination: env.URL_1C_TRANSTAX_DIRECT,
source: urls.URL_1C_TRANSTAX_PROXY,
},
...favicons.map((fileName) => buildFaviconRewrite(`/${fileName}`)),
];
},

View File

@ -1,12 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { ProcessContext } from '../types';
import { getTransTax } from '@/api/1c/query';
import { selectObjectCategoryTax } from '@/config/default-options';
import * as CRMTypes from '@/graphql/crm.types';
import ValidationHelper from '@/stores/validation/helper';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { reaction } from 'mobx';
import { makeDisposable } from 'tools';
export function common({ store, apolloClient }: ProcessContext) {
dayjs.extend(utc);
export function common({ store, apolloClient, queryClient }: ProcessContext) {
const { $calculation, $process } = store;
reaction(
@ -65,19 +70,6 @@ export function common({ store, apolloClient }: ProcessContext) {
}
);
reaction(
() => $calculation.$values.getValues(['leasingPeriod', 'vehicleTaxInYear']),
({ leasingPeriod, vehicleTaxInYear }) => {
if (vehicleTaxInYear > 0) {
$calculation
.element('tbxVehicleTaxInLeasingPeriod')
.setValue((vehicleTaxInYear / 12) * leasingPeriod);
} else {
$calculation.element('tbxVehicleTaxInLeasingPeriod').resetValue();
}
}
);
makeDisposable(
() =>
reaction(
@ -115,43 +107,140 @@ export function common({ store, apolloClient }: ProcessContext) {
() => $process.has('LoadKP')
);
makeDisposable(
() =>
reaction(
() =>
$calculation.$values.getValues([
'leaseObjectType',
'leaseObjectCategory',
'typePTS',
'objectRegistration',
]),
async ({
leaseObjectType: leaseObjectTypeId,
leaseObjectCategory,
typePTS,
objectRegistration,
}) => {
if (objectRegistration === 100_000_001 && typePTS === 100_000_001) {
$calculation.element('selectObjectCategoryTax').unblock();
if (leaseObjectTypeId) {
const {
data: { evo_leasingobject_type },
} = await apolloClient.query({
query: CRMTypes.GetLeaseObjectTypeDocument,
variables: { leaseObjectTypeId },
});
if (
leaseObjectCategory &&
leaseObjectCategory === evo_leasingobject_type?.evo_category
) {
$calculation
.element('selectObjectCategoryTax')
.setOptions(
selectObjectCategoryTax.filter((option) =>
evo_leasingobject_type?.evo_category_tr?.includes(option.value)
)
);
} else {
$calculation.element('selectObjectCategoryTax').resetOptions();
}
}
} else {
$calculation.element('selectObjectCategoryTax').resetValue().block();
}
}
),
() => $process.has('LoadKP')
);
reaction(
() => $calculation.$values.getValues(['leasingPeriod', 'vehicleTaxInYear']),
({ leasingPeriod, vehicleTaxInYear }) => {
if (vehicleTaxInYear > 0) {
$calculation
.element('tbxVehicleTaxInLeasingPeriod')
.setValue((vehicleTaxInYear / 12) * leasingPeriod);
} else {
$calculation.element('tbxVehicleTaxInLeasingPeriod').resetValue();
}
}
);
const mapObjectTypeTaxToCategory = {
100_000_000: 'D',
100_000_001: 'B',
100_000_002: 'C',
100_000_003: 'T',
100_000_004: 'A',
};
function getCarCategory(objectTypeTax: number) {
return mapObjectTypeTaxToCategory[objectTypeTax as keyof typeof mapObjectTypeTaxToCategory];
}
reaction(
() =>
$calculation.$values.getValues([
'leaseObjectType',
'leaseObjectCategory',
'typePTS',
'objectRegistration',
'objectTypeTax',
'regionRegistration',
'leaseObjectYear',
'leaseObjectMotorPower',
]),
async ({
leaseObjectType: leaseObjectTypeId,
leaseObjectCategory,
typePTS,
objectRegistration,
objectTypeTax,
regionRegistration,
leaseObjectYear,
leaseObjectMotorPower,
}) => {
if (objectRegistration === 100_000_001 && typePTS === 100_000_001) {
$calculation.element('selectObjectCategoryTax').unblock();
if (leaseObjectTypeId) {
const {
data: { evo_leasingobject_type },
} = await apolloClient.query({
query: CRMTypes.GetLeaseObjectTypeDocument,
variables: { leaseObjectTypeId },
});
if (leaseObjectCategory && leaseObjectCategory === evo_leasingobject_type?.evo_category) {
$calculation
.element('selectObjectCategoryTax')
.setOptions(
selectObjectCategoryTax.filter((option) =>
evo_leasingobject_type?.evo_category_tr?.includes(option.value)
)
);
} else {
$calculation.element('selectObjectCategoryTax').resetOptions();
}
if (
objectRegistration === null ||
objectRegistration !== 100_000_001 ||
objectTypeTax === null ||
regionRegistration === null ||
leaseObjectYear === 0 ||
leaseObjectMotorPower === 0
) {
$calculation.element('tbxVehicleTaxInYear').resetValue();
return;
}
const {
data: { evo_region },
} = await apolloClient.query({
query: CRMTypes.GetRegionDocument,
variables: {
regionId: regionRegistration,
},
});
const OKTMO = evo_region?.evo_oktmo;
const carCategory = getCarCategory(objectTypeTax);
if (OKTMO) {
const currentDate = dayjs().utc(false).toDate();
const { tax, error } = await queryClient.fetchQuery(['1c', 'trans-tax'], (context) =>
getTransTax(
{
OKTMO,
calcDate: currentDate,
carCategory,
power: leaseObjectMotorPower,
year: leaseObjectYear,
},
context
)
);
if (!error && tax) {
$calculation.element('tbxVehicleTaxInYear').setValue(tax);
}
} else {
$calculation.element('selectObjectCategoryTax').resetValue().block();
$calculation.element('tbxVehicleTaxInYear').resetValue();
}
}
);

View File

@ -1,3 +0,0 @@
import DownloadOutlined from '@ant-design/icons/lib/icons/DownloadOutlined';
export default <DownloadOutlined />;

View File

@ -1 +1 @@
export { default as DownloadOutlined } from './DownloadOutlined';
export * from '@ant-design/icons';