chore: первый коммит — панель акционера под контроль версий

Код сервера и интерфейса, документы проекта, генератор демонстрационных
данных. Не включены: выгрузки samples/ (внутренняя отчётность) и каталог
data/ — демонстрационный набор воспроизводится `npm run seed` побайтно,
а на сервере его место занимают настоящие выгрузки.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-08-05 22:49:57 +10:00
co-authored by Claude Opus 5
commit d3054a4058
57 changed files with 14798 additions and 0 deletions
+175
View File
@@ -0,0 +1,175 @@
import { useCallback, useEffect, useState } from 'react';
import type { Dataset } from './types';
import { TooltipProvider } from './components/Tooltip';
import { People } from './sections/People';
import { Cash } from './sections/Cash';
import { Deposits } from './sections/Deposits';
import { Taxes } from './sections/Taxes';
import { Finance } from './sections/Finance';
import { DataStatus } from './sections/DataStatus';
import { monthLabel } from './lib/format';
import { uniqueSorted } from './lib/aggregate';
const SECTIONS = [
{ id: 'people', label: 'Люди', short: '01' },
{ id: 'cash', label: 'Деньги', short: '02' },
{ id: 'deposits', label: 'Депозиты', short: '03' },
{ id: 'taxes', label: 'Налоги', short: '04' },
{ id: 'finance', label: 'Финрезультат', short: '05' },
{ id: 'data', label: 'Данные', short: '06' },
];
function sectionFromHash(): string {
const hash = window.location.hash.replace('#', '');
return SECTIONS.some((section) => section.id === hash) ? hash : 'people';
}
export default function App() {
const [dataset, setDataset] = useState<Dataset | null>(null);
const [error, setError] = useState<string | null>(null);
const [section, setSection] = useState<string>(sectionFromHash());
const [reloading, setReloading] = useState(false);
const load = useCallback(async () => {
try {
const response = await fetch('/api/data');
if (!response.ok) {
// сервер присылает человеческое объяснение - показываем его, а не код ответа
const reason = await response.json().catch(() => null);
throw new Error(reason?.error ?? 'Панель не отвечает. Попробуйте обновить страницу.');
}
const data = (await response.json()) as Dataset;
setDataset(data);
setError(null);
} catch (reason) {
setError(reason instanceof Error ? reason.message : String(reason));
}
}, []);
useEffect(() => {
load();
}, [load]);
useEffect(() => {
const handler = () => setSection(sectionFromHash());
window.addEventListener('hashchange', handler);
return () => window.removeEventListener('hashchange', handler);
}, []);
const goTo = useCallback((next: string) => {
window.location.hash = next;
setSection(next);
window.scrollTo({ top: 0, behavior: 'smooth' });
}, []);
const reload = useCallback(async () => {
setReloading(true);
try {
await fetch('/api/reload', { method: 'POST' });
await load();
} finally {
setReloading(false);
}
}, [load]);
if (error) {
return (
<div className="app-error">
<h1>Не удалось загрузить данные</h1>
<p>{error}</p>
<button type="button" onClick={load}>Повторить</button>
</div>
);
}
if (!dataset) {
return <div className="app-loading">Загружаем данные...</div>;
}
// период в шапке - последний закрытый месяц: будущие месяцы с одним прогнозом не считаем
const months = uniqueSorted([
...dataset.finance.filter((row) => row.fact !== null).map((row) => row.month),
...dataset.people.map((row) => row.month),
]);
const lastMonth = months[months.length - 1] ?? '';
const missing = dataset.meta.files.filter((file) => !file.exists).length;
// файл пропал или недочитан - панель показывает прежние цифры; человек должен
// видеть это в подвале, а не только на служебном экране «Данные»
const stale = dataset.meta.files.filter((file) => file.stale).length;
const updated = dataset.meta.dataUpdatedAt
? new Date(dataset.meta.dataUpdatedAt).toLocaleString('ru-RU', { dateStyle: 'short', timeStyle: 'short' })
: 'нет данных';
return (
<TooltipProvider>
<div className="app-shell">
<header className="topbar">
<div className="brand">
<span className="brand-mark"><i /><i /><i /></span>
<span>
<b>КОНТУР</b>
<small>Панель акционера</small>
</span>
</div>
<nav>
{SECTIONS.map((item) => (
<button
key={item.id}
type="button"
className={section === item.id ? 'active' : ''}
onClick={() => goTo(item.id)}
>
<i>{item.short}</i>
{item.label}
</button>
))}
</nav>
<div className="top-actions">
<div className="top-meta">
<span>Контур</span>
<b>Весь холдинг</b>
</div>
<div className="top-meta">
<span>Период</span>
<b>{lastMonth ? monthLabel(lastMonth, true) : '-'}</b>
</div>
<button type="button" className="top-refresh" onClick={reload} disabled={reloading}>
{reloading ? 'Обновляем...' : 'Обновить'}
</button>
<span className="top-avatar">АК</span>
</div>
</header>
<main className="content">
{missing === dataset.meta.files.length && !dataset.meta.files.some((file) => file.stale) && (
<div className="setup-banner">
<b>В каталоге данных нет ни одного файла</b>
<p>
Панель читает CSV из каталога <code>{dataset.meta.dataDir}</code>. Задайте другой каталог
переменной окружения <code>DATA_DIR</code> или положите туда выгрузки:
{' '}{dataset.meta.files.map((file) => file.file).join(', ')}.
</p>
</div>
)}
{section === 'people' && <People dataset={dataset} />}
{section === 'cash' && <Cash dataset={dataset} />}
{section === 'deposits' && <Deposits dataset={dataset} />}
{section === 'taxes' && <Taxes dataset={dataset} />}
{section === 'finance' && <Finance dataset={dataset} />}
{section === 'data' && <DataStatus dataset={dataset} onReload={reload} reloading={reloading} />}
</main>
<footer className="app-footer">
<span>Контур - конфиденциально</span>
<span>
Данные обновлены {updated}
{stale > 0 ? ` - часть данных прежняя: файлов недоступно ${stale}` : (missing > 0 ? ` - не найдено файлов: ${missing}` : '')}
</span>
<span>{new Date().toLocaleString('ru-RU', { dateStyle: 'long', timeStyle: 'short' })}</span>
</footer>
</div>
</TooltipProvider>
);
}