исправление багов

This commit is contained in:
Grog 2026-11-05 17:34:59 +03:00
parent 12f7c4824d
commit 446cd583d5
3 changed files with 123 additions and 71 deletions

View File

@ -23,7 +23,7 @@ import { getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
// {
// head_legal_entity: { id: 'head-1', name: 'Агрохолдинг "Просторы" АО' },
// subsidiary_legal_entity: { id: 'sub-1-1', name: 'ООО "Дон Агро"' },
// ownership_share: '100.0000',
// ownership_share: '100',
// financial_investment_amount: '4060.00',
// charter_capital_amount: '371.17',
// additional_capital_amount: '0.00',
@ -37,7 +37,7 @@ import { getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
// {
// head_legal_entity: { id: 'head-1', name: 'Агрохолдинг "Просторы" АО' },
// subsidiary_legal_entity: { id: 'sub-1-2', name: 'АО "Дон Агро"' },
// ownership_share: '75.0000',
// ownership_share: '75',
// financial_investment_amount: '260.01',
// charter_capital_amount: '120.00',
// additional_capital_amount: '0.00',
@ -51,7 +51,7 @@ import { getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
// {
// head_legal_entity: { id: 'head-1', name: 'Агрохолдинг "Просторы" АО' },
// subsidiary_legal_entity: { id: 'sub-1-3', name: 'ООО "Дон Мучнов"' },
// ownership_share: '100.0000',
// ownership_share: '7.12',
// financial_investment_amount: '130.00',
// charter_capital_amount: '0.01',
// additional_capital_amount: '0.00',
@ -65,7 +65,7 @@ import { getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
// {
// head_legal_entity: { id: 'head-1', name: 'Агрохолдинг "Просторы" АО' },
// subsidiary_legal_entity: { id: 'sub-1-4', name: 'ООО "Инвестком"' },
// ownership_share: '100.0000',
// ownership_share: '100',
// financial_investment_amount: '267.00',
// charter_capital_amount: '0.01',
// additional_capital_amount: '0.00',
@ -79,7 +79,7 @@ import { getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
// {
// head_legal_entity: { id: 'head-2', name: 'Инвестком АО' },
// subsidiary_legal_entity: { id: 'sub-2-1', name: 'ООО "Юг-Инвест"' },
// ownership_share: '50.0000',
// ownership_share: '50',
// financial_investment_amount: '8500.00',
// charter_capital_amount: '1000.00',
// additional_capital_amount: '500.00',
@ -130,17 +130,42 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
const next = { ...prev };
children.forEach((child) => {
const childKey = `${headId}-${child.subsidiary_legal_entity.id}`;
next[childKey] = { ...next[childKey], include_in_kfo: value as boolean };
const currentChild = next[childKey] || {};
next[childKey] = {
...currentChild,
include_in_kfo: value as boolean,
...(value
? {
ownership_share: currentChild.ownership_share ?? child.ownership_share,
comment: currentChild.comment ?? child.comment,
}
: {}),
};
});
return next;
});
return;
}
setEditedRows((prev) => ({
...prev,
[rowKey]: { ...prev[rowKey], [field]: value },
}));
setEditedRows((prev) => {
const current = prev[rowKey] || {};
const originalRow = data?.rows.find((r) => `${r.head_legal_entity.id}-${r.subsidiary_legal_entity.id}` === rowKey);
return {
...prev,
[rowKey]: {
...current,
[field]: value,
...(field === 'include_in_kfo' && value && originalRow
? {
ownership_share: current.ownership_share ?? originalRow.ownership_share,
comment: current.comment ?? originalRow.comment,
}
: {}),
},
};
});
},
[data?.rows],
);
@ -174,32 +199,35 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
setGoodwillFilter('allValue');
};
const loadData = useCallback(async (vId: string) => {
setLoading(true);
try {
const res = await fetchGoodwillTable(vId);
setData(res);
const loadData = useCallback(
async (vId: string) => {
setLoading(true);
try {
const res = await fetchGoodwillTable(vId);
setData(res);
const initialEdited: Record<string, Partial<GoodwillRow>> = {};
res.rows.forEach((row) => {
if (row.include_in_kfo) {
const key = `${row.head_legal_entity.id}-${row.subsidiary_legal_entity.id}`;
initialEdited[key] = {
include_in_kfo: true,
ownership_share: row.ownership_share,
comment: row.comment,
};
const initialEdited: Record<string, Partial<GoodwillRow>> = {};
res.rows.forEach((row) => {
if (row.include_in_kfo) {
const key = `${row.head_legal_entity.id}-${row.subsidiary_legal_entity.id}`;
initialEdited[key] = {
include_in_kfo: true,
ownership_share: row.ownership_share,
comment: row.comment,
};
}
});
setEditedRows(initialEdited);
} catch (e) {
if (e instanceof ApiError) {
notification.error({ description: e.message });
}
});
setEditedRows(initialEdited);
} catch (e) {
if (e instanceof ApiError) {
notification.error({ description: e.message });
} finally {
setLoading(false);
}
} finally {
setLoading(false);
}
}, [notification]);
},
[notification],
);
const handleSave = async () => {
if (!version_id || !data) return;
@ -207,9 +235,7 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
try {
const promises = Object.keys(editedRows).map((rowKey) => {
const changes = editedRows[rowKey];
const originalRow = data.rows.find(
(r) => `${r.head_legal_entity.id}-${r.subsidiary_legal_entity.id}` === rowKey
);
const originalRow = data.rows.find((r) => `${r.head_legal_entity.id}-${r.subsidiary_legal_entity.id}` === rowKey);
if (!originalRow) return;
const payload: GoodwillRowPayload = {
@ -218,12 +244,7 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
comment: changes.comment !== undefined ? changes.comment : (originalRow.comment ?? null),
};
return saveGoodwillRow(
version_id,
originalRow.head_legal_entity.id,
originalRow.subsidiary_legal_entity.id,
payload
);
return saveGoodwillRow(version_id, originalRow.head_legal_entity.id, originalRow.subsidiary_legal_entity.id, payload);
});
await Promise.all(promises);
@ -281,7 +302,6 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
}
const hasErrors = Object.values(editedRows).some((elem) => {
if (!elem.include_in_kfo) return false;
const isShareEmpty = !elem.ownership_share || String(elem.ownership_share).trim() === '';
const isCommentEmpty = !elem.comment || String(elem.comment).trim() === '';
@ -290,6 +310,19 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
return !hasErrors;
}, [editedRows, isEditMode]);
useEffect(() => {
const handleFullscreenChange = () => {
if (!document.fullscreenElement) {
setIsGoodwillFullscreen(false);
}
};
document.addEventListener('fullscreenchange', handleFullscreenChange);
return () => {
document.removeEventListener('fullscreenchange', handleFullscreenChange);
};
}, []);
useEffect(() => {
if (version_id) {
loadData(version_id);

View File

@ -6,6 +6,7 @@ import type { GoodwillRow, GoodwillTableResponse, GoodwillTreeRow } from '../../
import './ConsolidationGoodwillTable.css';
import { chessTableCellFormatValue } from '../../../utils/chessTableCellFormatValue';
import { getGoodwillColumns } from './config';
import { sumAmounts } from '../../../utils/money';
const { Text } = Typography;
@ -128,17 +129,28 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
const scrollY = isFullscreen ? 'calc(100vh - 200px)' : 'auto';
const renderSummary = () => {
if (!data?.totals) return null;
if (!data?.rows) return null;
const ownershipIndex = visibleColumns.findIndex((c) => c.key === 'ownership_share');
const totalFinInv = sumAmounts(data.rows.map((c) => c.financial_investment_amount)) ?? '0.00';
const totalParticipation = sumAmounts(data.rows.map((c) => c.participation_amount)) ?? '0.00';
const totalCharter = sumAmounts(data.rows.map((c) => c.charter_capital_amount)) ?? '0.00';
const totalGoodwill = sumAmounts(data.rows.map((c) => c.goodwill_amount)) ?? '0.00';
return (
<Table.Summary fixed>
<Table.Summary.Row className='resRow'>
{visibleColumns.map((col, index) => {
if (index === 0) {
if (col.key === 'include_in_kfo') {
return (
<Table.Summary.Cell key='total-label' index={0} colSpan={ownershipIndex > 0 ? ownershipIndex : 1} align='left'>
<Table.Summary.Cell key={col.key} index={index} align='center'>
<Text strong>—</Text>
</Table.Summary.Cell>
);
}
if (col.key === 'name') {
return (
<Table.Summary.Cell key={col.key} index={index} align='left'>
<div style={{ backgroundColor: '#e6f4ea', width: '100%', height: '100%' }}>
<Text strong>Итого по листу</Text>
</div>
@ -146,8 +158,6 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
);
}
if (index < ownershipIndex) return null;
if (col.key === 'ownership_share') {
return (
<Table.Summary.Cell key={col.key} index={index} align='right'>
@ -160,7 +170,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
return (
<Table.Summary.Cell key={col.key} index={index} align='right'>
<div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(data.totals.financial_investment_amount, units, decimals)}</Text>
<Text strong>{chessTableCellFormatValue(String(totalFinInv), units, decimals)}</Text>
</div>
</Table.Summary.Cell>
);
@ -170,7 +180,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
return (
<Table.Summary.Cell key={col.key} index={index} align='right'>
<div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(data.totals.participation_amount, units, decimals)}</Text>
<Text strong>{chessTableCellFormatValue(String(totalParticipation), units, decimals)}</Text>
</div>
</Table.Summary.Cell>
);
@ -179,7 +189,9 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
if (col.key === 'charter_capital_amount') {
return (
<Table.Summary.Cell key={col.key} index={index} align='right'>
<Text strong>—</Text>
<div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(String(totalCharter), units, decimals)}</Text>
</div>
</Table.Summary.Cell>
);
}
@ -188,7 +200,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
return (
<Table.Summary.Cell key={col.key} index={index} align='right'>
<div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(data.totals.goodwill_amount, units, decimals)}</Text>
<Text strong>{chessTableCellFormatValue(String(totalGoodwill), units, decimals)}</Text>
</div>
</Table.Summary.Cell>
);
@ -221,6 +233,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
size='small'
bordered
title={() => toolbar}
key={data?.rows?.length}
expandable={{ defaultExpandAllRows: true }}
summary={renderSummary}
rowClassName={(record) => (record.isGroupTotal ? 'group-total-row' : '')}

View File

@ -74,26 +74,36 @@ export const getGoodwillColumns = ({
const val = editedRows[row.key]?.ownership_share ?? row.ownership_share;
const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo;
if (isEditMode && isChecked) {
return (
<Input
type='number'
min={0}
max={100}
step={1}
style={{ width: '100%' }}
value={val ? Math.floor(Number(val)) : ''}
style={{ width: '100%', backgroundColor: 'transparent' }}
value={val ?? ''}
onChange={(e) => {
const intValue = e.target.value.replace(/\D/g, '');
onRowEdit(row.key, 'ownership_share', intValue);
let inputValue = e.target.value;
inputValue = inputValue.replace('.', ',');
inputValue = inputValue.replace(/[^\d,]/g, '');
const parts = inputValue.split(',');
if (parts.length > 1 && parts[1].length > 2) {
inputValue = `${parts[0]},${parts[1].slice(0, 2)}`;
}
const numericValue = Number(inputValue.replace(',', '.'));
if (!isNaN(numericValue) && numericValue > 100) {
inputValue = '100';
}
onRowEdit(row.key, 'ownership_share', inputValue);
}}
placeholder='%'
/>
);
}
return val ? `${Math.floor(Number(val))}%` : '—';
return val ? `${Number(val)}%` : '—';
},
},
@ -135,11 +145,7 @@ export const getGoodwillColumns = ({
const isNegative = String(val).trim().startsWith('-');
return (
<Text style={{ color: isNegative ? '#cf1322' : '#3f8600' }}>
{formatted}
</Text>
);
return <Text style={{ color: isNegative ? '#cf1322' : '#3f8600' }}>{formatted}</Text>;
},
},
{