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

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

View File

@ -6,6 +6,7 @@ import type { GoodwillRow, GoodwillTableResponse, GoodwillTreeRow } from '../../
import './ConsolidationGoodwillTable.css'; import './ConsolidationGoodwillTable.css';
import { chessTableCellFormatValue } from '../../../utils/chessTableCellFormatValue'; import { chessTableCellFormatValue } from '../../../utils/chessTableCellFormatValue';
import { getGoodwillColumns } from './config'; import { getGoodwillColumns } from './config';
import { sumAmounts } from '../../../utils/money';
const { Text } = Typography; const { Text } = Typography;
@ -128,17 +129,28 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
const scrollY = isFullscreen ? 'calc(100vh - 200px)' : 'auto'; const scrollY = isFullscreen ? 'calc(100vh - 200px)' : 'auto';
const renderSummary = () => { 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 ( return (
<Table.Summary fixed> <Table.Summary fixed>
<Table.Summary.Row className='resRow'> <Table.Summary.Row className='resRow'>
{visibleColumns.map((col, index) => { {visibleColumns.map((col, index) => {
if (index === 0) { if (col.key === 'include_in_kfo') {
return ( 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%' }}> <div style={{ backgroundColor: '#e6f4ea', width: '100%', height: '100%' }}>
<Text strong>Итого по листу</Text> <Text strong>Итого по листу</Text>
</div> </div>
@ -146,8 +158,6 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
); );
} }
if (index < ownershipIndex) return null;
if (col.key === 'ownership_share') { if (col.key === 'ownership_share') {
return ( return (
<Table.Summary.Cell key={col.key} index={index} align='right'> <Table.Summary.Cell key={col.key} index={index} align='right'>
@ -160,7 +170,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
return ( return (
<Table.Summary.Cell key={col.key} index={index} align='right'> <Table.Summary.Cell key={col.key} index={index} align='right'>
<div style={{ backgroundColor: '#e6f4ea' }}> <div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(data.totals.financial_investment_amount, units, decimals)}</Text> <Text strong>{chessTableCellFormatValue(String(totalFinInv), units, decimals)}</Text>
</div> </div>
</Table.Summary.Cell> </Table.Summary.Cell>
); );
@ -170,7 +180,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
return ( return (
<Table.Summary.Cell key={col.key} index={index} align='right'> <Table.Summary.Cell key={col.key} index={index} align='right'>
<div style={{ backgroundColor: '#e6f4ea' }}> <div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(data.totals.participation_amount, units, decimals)}</Text> <Text strong>{chessTableCellFormatValue(String(totalParticipation), units, decimals)}</Text>
</div> </div>
</Table.Summary.Cell> </Table.Summary.Cell>
); );
@ -179,7 +189,9 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
if (col.key === 'charter_capital_amount') { if (col.key === 'charter_capital_amount') {
return ( return (
<Table.Summary.Cell key={col.key} index={index} align='right'> <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> </Table.Summary.Cell>
); );
} }
@ -188,7 +200,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
return ( return (
<Table.Summary.Cell key={col.key} index={index} align='right'> <Table.Summary.Cell key={col.key} index={index} align='right'>
<div style={{ backgroundColor: '#e6f4ea' }}> <div style={{ backgroundColor: '#e6f4ea' }}>
<Text strong>{chessTableCellFormatValue(data.totals.goodwill_amount, units, decimals)}</Text> <Text strong>{chessTableCellFormatValue(String(totalGoodwill), units, decimals)}</Text>
</div> </div>
</Table.Summary.Cell> </Table.Summary.Cell>
); );
@ -221,6 +233,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
size='small' size='small'
bordered bordered
title={() => toolbar} title={() => toolbar}
key={data?.rows?.length}
expandable={{ defaultExpandAllRows: true }} expandable={{ defaultExpandAllRows: true }}
summary={renderSummary} summary={renderSummary}
rowClassName={(record) => (record.isGroupTotal ? 'group-total-row' : '')} 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 val = editedRows[row.key]?.ownership_share ?? row.ownership_share;
const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo; const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo;
if (isEditMode && isChecked) { if (isEditMode && isChecked) {
return ( return (
<Input <Input
type='number' style={{ width: '100%', backgroundColor: 'transparent' }}
min={0} value={val ?? ''}
max={100}
step={1}
style={{ width: '100%' }}
value={val ? Math.floor(Number(val)) : ''}
onChange={(e) => { onChange={(e) => {
const intValue = e.target.value.replace(/\D/g, ''); let inputValue = e.target.value;
onRowEdit(row.key, 'ownership_share', intValue);
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='%' placeholder='%'
/> />
); );
} }
return val ? `${Math.floor(Number(val))}%` : '—'; return val ? `${Number(val)}%` : '—';
}, },
}, },
@ -135,11 +145,7 @@ export const getGoodwillColumns = ({
const isNegative = String(val).trim().startsWith('-'); const isNegative = String(val).trim().startsWith('-');
return ( return <Text style={{ color: isNegative ? '#cf1322' : '#3f8600' }}>{formatted}</Text>;
<Text style={{ color: isNegative ? '#cf1322' : '#3f8600' }}>
{formatted}
</Text>
);
}, },
}, },
{ {