AURORA-1671: исправления по функционалу ГК и ЮЛ #179

Merged
aep merged 4 commits from fix/legalEntities into main 2026-10-26 23:17:18 +03:00
18 changed files with 87 additions and 91 deletions
Showing only changes of commit 633c4d3fed - Show all commits

View File

@ -0,0 +1,6 @@
.custom-select-selection-item .ant-select-selection-item {
background-color: #ecfdf3 !important;
color: #1f5f35 !important;
box-shadow: inset 0 0 0 1px #2ea64b38 !important;
border-radius: 999px !important;
}

View File

@ -7,7 +7,6 @@ import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
import { createCompanyGroup, fetchRelatedGroups } from '../services/api/directories/company_groups';
import { createRelatedGroup } from '../services/api/directories/related-groups';
import { getCatalogueJurThunk } from '../store/slices/catalogueJurSlice/thunks';
import { setActiveCompanyGroup } from '../store/slices/companyGroupsSlice/companyGroupsSlice';
import { getCompanyGroupsThunk } from '../store/slices/companyGroupsSlice/thunks';
import { useAppDispatch, useAppSelector } from '../store/store';
import type { RelatedGroupOut } from '../types/api';
@ -37,29 +36,20 @@ export function CatalogueGroup() {
const [activeTab, setActiveTab] = useState<CatalogueGroupTabKey>('legal_entities');
const [gskData, setGskData] = useState<RelatedGroupOut[]>([]);
const [gszData, setGszData] = useState<RelatedGroupOut[]>([]);
const activeCompanyGroup = useAppSelector((state) => state.company_groups.activeCompanyGroup);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
const relatedGroupFilter = useAppSelector((state) => state.catalogue_jur.relatedGroupFilter);
const rawRows = useAppSelector((state) => state.company_groups.raw_rows);
async function createJurHandler(values: CatalogueJurFormProps) {
try {
await createCatalogueJur(values);
dispatch(getCompanyGroupsThunk());
dispatch(
getCatalogueJurThunk({
closed: isGettingArchive,
outside_group: false,
company_group_id: activeCompanyGroup?.id,
}),
);
setKindForm(null);
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
}
await createCatalogueJur(values);
dispatch(getCompanyGroupsThunk());
dispatch(
getCatalogueJurThunk({
closed: isGettingArchive,
outside_group: false,
company_group_id: activeCompanyGroup?.id,
}),
);
setKindForm(null);
}
async function createRelatedGroupHandler(values: RelatedGroupFormType) {
if (values.company_group_id) {
@ -123,12 +113,6 @@ export function CatalogueGroup() {
setActiveTab('legal_entities');
}, [relatedGroupFilter]);
useEffect(() => {
if (!activeCompanyGroup && rawRows?.length) {
dispatch(setActiveCompanyGroup(rawRows?.[0]));
}
}, [rawRows, activeCompanyGroup]);
return (
<div
style={{
@ -203,9 +187,7 @@ export function CatalogueGroup() {
onCancel={() => {
setKindForm(null);
}}
onOk={async (values) => {
await createJurHandler(values);
}}
onOk={createJurHandler}
/>
)}
{(kindForm === 'gsk' || kindForm === 'gsz') && (

View File

@ -7,10 +7,9 @@ import type {
MoveCatalogueJurProps,
WithdrawCatalogueJurProps,
} from '../../../types/catalogueJur/catalogueJur';
import { LE_PAGE } from './company_groups';
export async function fetchCatalogueJur(params: GetCatalogueJurPropsI) {
const res = await api.get<Page<ICatalogueJur>>('/directories/legal-entities', { limit: LE_PAGE, offset: 0, ...params });
const res = await api.get<Page<ICatalogueJur>>('/directories/legal-entities', { limit: 200, offset: 0, ...params });
return res;
}

View File

@ -2,6 +2,7 @@ import { type PayloadAction, createSlice } from '@reduxjs/toolkit';
import type { RelatedGroupOut } from '../../../types/api';
import { getCatalogueJurThunk } from './thunks';
import type { CatalogueJurSliceType } from './types';
import { ICompanyGroup } from '../../../types/companyGroups/companyGroups';
const initialState: CatalogueJurSliceType = {
raw_rows: [],
@ -10,6 +11,7 @@ const initialState: CatalogueJurSliceType = {
error: null,
isGettingArchive: false,
relatedGroupFilter: null,
activeCompanyGroup: null,
};
const catalogueJurSlice = createSlice({
@ -22,6 +24,10 @@ const catalogueJurSlice = createSlice({
setRelatedGroupFilter(state, action: PayloadAction<RelatedGroupOut | null>) {
state.relatedGroupFilter = action.payload;
},
setActiveCompanyGroup(state, action: PayloadAction<ICompanyGroup | null>) {
state.activeCompanyGroup = action.payload;
state.relatedGroupFilter = null
},
},
extraReducers: (builder) => {
builder
@ -40,5 +46,6 @@ const catalogueJurSlice = createSlice({
});
},
});
export const { setIsGettingArchive, setRelatedGroupFilter } = catalogueJurSlice.actions;
export const { setIsGettingArchive, setRelatedGroupFilter, setActiveCompanyGroup } = catalogueJurSlice.actions;
export default catalogueJurSlice.reducer;

View File

@ -1,5 +1,6 @@
import type { RelatedGroupOut } from '../../../types/api';
import type { ICatalogueJur } from '../../../types/catalogueJur/catalogueJur';
import { ICompanyGroup } from '../../../types/companyGroups/companyGroups';
export interface CatalogueJurSliceType {
total_groups: number;
@ -8,6 +9,7 @@ export interface CatalogueJurSliceType {
error: string | null;
isGettingArchive: boolean;
relatedGroupFilter?: RelatedGroupOut | null;
activeCompanyGroup?: ICompanyGroup | null;
}
export interface GetCatalogueJurPropsI {

View File

@ -1,5 +1,4 @@
import { type PayloadAction, createSlice } from '@reduxjs/toolkit';
import type { ICompanyGroup } from '../../../types/companyGroups/companyGroups';
import { createSlice } from '@reduxjs/toolkit';
import { getCompanyGroupsThunk } from './thunks';
import type { CompanyGroupSliceType } from './types';
@ -8,17 +7,12 @@ const initialState: CompanyGroupSliceType = {
total_groups: 0,
loading: false,
error: null,
activeCompanyGroup: null,
};
const comGroupsSlice = createSlice({
name: 'company_groups',
initialState,
reducers: {
setActiveCompanyGroup(state, action: PayloadAction<ICompanyGroup | null>) {
state.activeCompanyGroup = action.payload;
},
},
reducers: {},
extraReducers: (builder) => {
builder
.addCase(getCompanyGroupsThunk.pending, (state) => {
@ -27,10 +21,6 @@ const comGroupsSlice = createSlice({
})
.addCase(getCompanyGroupsThunk.fulfilled, (state, action) => {
state.raw_rows = action.payload;
if (state.activeCompanyGroup?.id) {
const newActiveCompanyGroup = action.payload.find((elem) => elem.id === state.activeCompanyGroup?.id);
state.activeCompanyGroup = newActiveCompanyGroup;
}
state.total_groups = action.payload.length;
state.loading = false;
})
@ -40,5 +30,4 @@ const comGroupsSlice = createSlice({
});
},
});
export const { setActiveCompanyGroup } = comGroupsSlice.actions;
export default comGroupsSlice.reducer;

View File

@ -5,5 +5,4 @@ export interface CompanyGroupSliceType {
raw_rows: ICompanyGroup[];
loading: boolean;
error: string | null;
activeCompanyGroup?: ICompanyGroup | null;
}

View File

@ -375,6 +375,7 @@ export interface ConsolidationCreate {
export interface RelatedGroupOut {
id: string;
code: string;
crm_id:string,
company_group_id: string;
kind: 'gsk' | 'gsz';
name: string;

View File

@ -12,7 +12,7 @@ interface CataloguGroupTabsI {
export type CatalogueGroupTabKey = 'legal_entities' | 'gsk' | 'gsz';
export const CataloguGroupTabs = ({ activeTab, setActiveTab, gskData, gszData }: CataloguGroupTabsI) => {
const activeCompanyGroup = useAppSelector((state) => state.company_groups.activeCompanyGroup);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
return (
<Tabs

View File

@ -5,7 +5,7 @@ import { useAppSelector } from '../../store/store';
import { pluralRu } from '../../utils/labels';
export const CompanyGroupHeader = () => {
const activeCompanyGroup = useAppSelector((state) => state.company_groups.activeCompanyGroup);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
const count = activeCompanyGroup?.legal_entities_count ?? 0;
const organizationWord = pluralRu(count, ['организация', 'организации', 'организаций']);

View File

@ -27,12 +27,11 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
const [loadingOfficesOptions, setLoadingOfficesOptions] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
const [officesOptions, setOfficesOptions] = useState<{ value: string; label: string }[]>([]);
const companyGrops = useAppSelector((state) => state.company_groups.raw_rows);
const companyGropsLoading = useAppSelector((state) => state.company_groups.loading);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
const type = Form.useWatch('entity_type', form);
const companyGroupId = Form.useWatch('company_group_id', form);
async function getInitialData() {
if (jurId) {
@ -51,6 +50,7 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
gsk_id: data.memberships?.find((elem) => elem.kind === 'gsk')?.related_group_id,
gsz_id: data.memberships?.find((elem) => elem.kind === 'gsz')?.related_group_id,
});
getRelatedGroupsHandler(data.company_group_id as string);
} catch (e) {
if (e instanceof ApiError) {
notification.error({ description: e.message });
@ -58,6 +58,11 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
} finally {
setInitialDataLoading(false);
}
} else {
form.setFieldsValue({
company_group_id: activeCompanyGroup?.id ?? undefined,
});
getRelatedGroupsHandler(activeCompanyGroup?.id ?? '');
}
}
@ -76,12 +81,12 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
}
}
async function getRelatedGroupsHandler() {
if (!companyGroupId) return;
async function getRelatedGroupsHandler(companyId: string) {
if (!companyId) return;
setLoadingRelatedGroupsOptions(true);
try {
const res = await fetchRelatedGroups(companyGroupId);
const res = await fetchRelatedGroups(companyId);
const gsks = res.filter((elem) => elem.kind === 'gsk');
const gszs = res.filter((elem) => elem.kind === 'gsz');
setGskData(gsks);
@ -101,18 +106,25 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
const values = await form.validateFields();
await onOk({
...values,
kpp: type === 'ИП' ? null : values.kpp?.toString(),
kpp: type === 'ИП' ? null : (values.kpp?.toString() ?? null),
inn: jurId ? undefined : values?.inn?.toString(),
company_group_id: jurId ? undefined : values.company_group_id,
gsz_id: values.gsz_id ? values?.gsz_id : null,
gsk_id: values.gsk_id ? values?.gsk_id : null,
regional_office_id: values.regional_office_id ? values?.regional_office_id : null,
crm_id: values.crm_id ?? null,
});
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
if (e.code === 'INN_EXISTS') {
form.setFields([
{
name: 'inn',
errors: [e.message],
},
]);
}
notification.error({ description: e.message });
}
} finally {
setConfirmLoading(false);
@ -128,21 +140,13 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
return companyGrops?.map((company) => company && { value: company.id, label: company.name });
}, [companyGrops]);
useEffect(() => {
getInitialData();
}, [jurId, open]);
useEffect(() => {
getOfficesOptionsHandler();
}, []);
useEffect(() => {
form.setFieldsValue({
gsk_id: undefined,
gsz_id: undefined,
});
getRelatedGroupsHandler();
}, [companyGroupId]);
getInitialData();
}, [jurId, open]);
return (
<Modal
@ -213,6 +217,7 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
label='Альтернативные наименования'
extra='Введите синоним и нажмите Enter. Можно добавить несколько значений.'>
<Select
className='custom-select-selection-item'
mode='tags'
style={{ width: '100%' }}
placeholder='Добавить синоним'
@ -246,6 +251,13 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
showSearch
optionFilterProp='label'
notFoundContent={companyGropsLoading ? 'Загрузка' : 'Нет вариантов'}
onChange={(value) => {
form.setFieldsValue({
gsk_id: undefined,
gsz_id: undefined,
});
getRelatedGroupsHandler(value);
}}
/>
</Form.Item>
</Col>

View File

@ -45,7 +45,7 @@ export function CatalogueJurTable({ outside_group, tabsComponent }: CatalogueJur
const rawRows = useAppSelector((state) => state.catalogue_jur.raw_rows);
const loading = useAppSelector((state) => state.catalogue_jur.loading);
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
const activeCompanyGroup = useAppSelector((state) => state.company_groups.activeCompanyGroup);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
const relatedGroupFilter = useAppSelector((state) => state.catalogue_jur.relatedGroupFilter);
const [moveCatalogueFormOpen, setMoveCatalogueFormOpen] = useState(false);
@ -136,10 +136,8 @@ export function CatalogueJurTable({ outside_group, tabsComponent }: CatalogueJur
}
useEffect(() => {
if (activeCompanyGroup?.id) {
getCatalogueJur();
}
}, [isGettingArchive, activeCompanyGroup]);
}, [isGettingArchive, activeCompanyGroup, outside_group]);
const extraColumns: ColumnsType<ICatalogueJur> = useMemo(
() => [

View File

@ -19,7 +19,7 @@ export const CompanyGroupForm: React.FC<Props> = ({ open, onCancel, onOk }) => {
const { me } = useMe();
const notification = useNotificationApi();
const activeCompanyGroup = useAppSelector((state) => state.company_groups.activeCompanyGroup);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
const [officesOptions, setOfficesOptions] = useState<{ value: string; label: string }[]>([]);
const [loadingOptions, setLoadingOptions] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
@ -86,7 +86,7 @@ export const CompanyGroupForm: React.FC<Props> = ({ open, onCancel, onOk }) => {
<Row gutter={16}>
<Col span={12}>
<Form.Item name='crm_id' label='ID ГК в CRM'>
<Input placeholder='Генерируется автоматически' />
<Input />
</Form.Item>
</Col>
<Col span={12}>

View File

@ -2,9 +2,9 @@ import { FolderOpenOutlined, SearchOutlined } from '@ant-design/icons';
import { Empty, Input, List, Spin, Tag, Typography } from 'antd';
import { useEffect, useMemo, useState } from 'react';
import { useVirtualList } from '../../hooks/useVirtualList';
import { setActiveCompanyGroup } from '../../store/slices/companyGroupsSlice/companyGroupsSlice';
import { getCompanyGroupsThunk } from '../../store/slices/companyGroupsSlice/thunks';
import { useAppDispatch, useAppSelector } from '../../store/store';
import { setActiveCompanyGroup } from '../../store/slices/catalogueJurSlice/catalogueJurSlice';
const { Text } = Typography;
@ -13,7 +13,7 @@ export const CompanyGroupsList = () => {
const rawRows = useAppSelector((state) => state.company_groups.raw_rows);
const loading = useAppSelector((state) => state.company_groups.loading);
const activeCompanyGroup = useAppSelector((state) => state.company_groups.activeCompanyGroup);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
const [query, setQuery] = useState('');

View File

@ -1,7 +0,0 @@
/* Теги выбранных значений в селектах фильтра шахматки */
.custom-select-selection-item .ant-select-selection-item {
background-color: #ecfdf3 !important;
color: #1f5f35 !important;
box-shadow: inset 0 0 0 1px #2ea64b38 !important;
border-radius: 999px !important;
}

View File

@ -6,7 +6,6 @@ import { type OptionType, TreeFilterDropdown } from '../../components/TreeFilter
import type { Account, MatrixCompany, Quarter } from '../../types/api';
import { quarterShortLabel } from '../../utils/labels';
import { useNotificationApi } from '../../utils/useNotification';
import './ConsolidationChessTableFilter.css';
interface ConsolidationChessTableFilterI {
companies: string[];
@ -16,7 +15,6 @@ interface ConsolidationChessTableFilterI {
credit: string[];
onCreditChange: (val: string[]) => void;
allCompanies: MatrixCompany[];
/** Год и квартал версии — только для показа: версия задаётся адресом. */
year?: number;
quarter?: Quarter;
}

View File

@ -26,9 +26,15 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
const [confirmLoading, setConfirmLoading] = useState(false);
const companyGrops = useAppSelector((state) => state.company_groups.raw_rows);
const companyGropsLoading = useAppSelector((state) => state.company_groups.loading);
const activeCompanyGroup = useAppSelector((state) => state.catalogue_jur.activeCompanyGroup);
async function getInitialData() {
if (!relatedGroupId) return;
if (!relatedGroupId) {
form.setFieldsValue({
company_group_id: activeCompanyGroup?.id ?? undefined,
});
return;
}
setInitialDataLoading(true);
try {
const data = await fetchRelatedGroup(relatedGroupId);
@ -36,7 +42,7 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
form.setFieldsValue({
crm_id: data?.crm_id,
name: data?.name,
created_date: data?.created_date ?? dayjs().format('YYYY-MM-DD'),
created_date: data?.created_date ?? (relatedGroupId ? null : dayjs().format('YYYY-MM-DD')),
company_group_id: data?.company_group_id,
});
} catch (e) {
@ -53,7 +59,7 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
try {
const { created_date, name, crm_id, company_group_id } = await form.validateFields();
await onOk({
created_date: created_date ?? dayjs().format('YYYY-MM-DD'),
created_date: created_date ?? (relatedGroupId ? null : dayjs().format('YYYY-MM-DD') ),
name,
crm_id,
company_group_id: relatedGroupId ? undefined : company_group_id,
@ -96,7 +102,7 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
confirmLoading={confirmLoading}>
<Form form={form} layout='vertical'>
<FormItem name='crm_id' label='ID в CRM'>
<Input placeholder='Генерируется автоматически' />
<Input />
</FormItem>
<FormItem name='name' label='Наименование' rules={[{ required: true, message: 'Укажите наименование' }]}>
<Input />

View File

@ -6,13 +6,17 @@ import { store } from '../../store/store';
import type { RelatedGroupOut } from '../../types/api';
export const relateGroupConfig: TableConfig<RelatedGroupOut> = {
rowKey: 'id',
searchableKeys: ['code', 'name', 'members_count', 'created_date'],
searchableKeys: ['code', 'crm_id', 'name', 'members_count', 'created_date'],
columns: [
{
key: 'code',
title: 'ID',
features: { search: true, multiselect: true },
},
{
key: 'crm_id',
title: 'CRM ID',
},
{
key: 'name',
title: 'Наименование',
@ -35,7 +39,7 @@ export const relateGroupConfig: TableConfig<RelatedGroupOut> = {
key: 'created_date',
title: 'Дата создания',
render: (val) => {
return new Date(val as string).toLocaleDateString('ru-RU');
return val ? new Date(val as string).toLocaleDateString('ru-RU') : '—';
},
},
],