arm-web/src/types/api.ts
Andrey Epifancev 5b7b02a3f2 store: консолидация открытой версии и подпись консолидации у файла (#26)
Чистые функции findCurrentConsolidation, isInWork, consolidationLabel и хук
useCurrentConsolidation; FileOut.consolidation_id; тесты vitest.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-10-10 00:52:33 +04:00

284 lines
7.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// DTO API arm-core (/api/v1). Повторяют arm-core/api/src/schemas/; Decimal и даты — строки.
export type Quarter = 'Q1' | 'Q2' | 'Q3' | 'Q4';
export type DocumentType = 'BALANCE' | 'INCOME' | 'OSV' | 'DISCLOSURE' | 'OTHER';
export type DocumentStatus = 'RECOGNIZED' | 'NEEDS_CHECK' | 'CONFIRMED' | 'ERROR';
export type FileStatus = 'UPLOADED' | 'PROCESSING' | 'PROCESSED' | 'ERROR' | 'SUPERSEDED';
export interface Page<T> {
items: T[];
total: number;
limit: number;
offset: number;
}
export interface AcceptedOut {
file_id: string;
job_id: string;
name: string;
}
export interface RejectedOut {
name: string;
code: string;
message: string;
file_id?: string | null;
}
export interface UploadResult {
accepted: AcceptedOut[];
rejected: RejectedOut[];
}
export type RecognitionStatus = string; // pending | processing | done | error | timeout | dlq — только для показа
export interface JobBrief {
id: string;
status: RecognitionStatus;
error_code: string | null;
error_message: string | null;
mapping_error: string | null;
warnings: string[];
mapping_warnings: string[];
finished_at: string | null;
}
export type CheckResult = 'MATCH' | 'MISMATCH' | 'UNKNOWN';
export interface DocumentBrief {
id: string;
document_type: DocumentType;
osv_account_code: string | null;
period_year: number | null;
period_quarter: Quarter | null;
is_cumulative: boolean | null;
status: DocumentStatus;
period_check: CheckResult | null;
counterparty_check: CheckResult | null;
locator: string | null;
comments_count: number;
}
export type FileType = 'XLS' | 'XLSX' | 'XLSB' | 'PDF' | 'PNG' | 'JPG';
export interface FileOut {
id: string;
legal_entity_id: string;
original_name: string | null;
file_type: FileType;
status: FileStatus;
version_no: number;
size_bytes: number | null;
uploaded_at: string | null;
/** консолидация, в контексте которой загружен файл (v5.18); null — без контекста */
consolidation_id: string | null;
job: JobBrief | null;
documents: DocumentBrief[];
}
export interface DocumentOut extends DocumentBrief {
file_id: string;
legal_entity_id: string;
confirmed_by: string | null;
confirmed_at: string | null;
warnings: string[];
}
/** Уровень строки ОСВ (DBML `osv_group_type`). */
export type OsvGroupType = 'ACCOUNT' | 'DEPARTMENT' | 'COUNTERPARTY' | 'CONTRACT' | 'OTHER';
export interface EntryOut {
id: string;
row_number: number | null;
level: number | null;
parent_entry_id: string | null;
row_value: string | null;
group_type: OsvGroupType | null;
group_name: string | null;
account_code: string | null;
counterparty_name: string | null;
counterparty_inn: string | null;
opening_debit: string | null;
opening_credit: string | null;
turnover_debit: string | null;
turnover_credit: string | null;
closing_debit: string | null;
closing_credit: string | null;
}
export interface HeaderFieldOut {
value: string | null;
original_value: string | null;
confidence?: string | null;
verified: boolean | null;
modified: boolean | null;
}
export interface StatementHeaderOut {
inn: HeaderFieldOut;
report_date: HeaderFieldOut;
units: HeaderFieldOut;
organization_name: string | null;
okud: string | null;
okpo: string | null;
okopf: string | null;
okfs: string | null;
address: string | null;
}
export interface ColumnOut {
id: string;
column_index: number;
label: string | null;
period_date: string | null;
is_current: boolean | null;
}
export interface ValueOut {
id: string | null; // null — ячейка достроена сервером, в БД её нет
column_id: string;
column_index: number;
amount: string | null;
string_value: string | null;
confidence: string | null;
is_recognized: boolean | null;
is_modified: boolean;
original_amount: string | null;
}
export interface LineOut {
id: string | null; // null — строка достроена по справочнику редакции
origin: 'source' | 'template';
line_code: string | null;
line_name: string | null;
values: ValueOut[];
}
export interface FailedCheckOut {
column_index: number;
relation: string;
expected: string;
actual: string;
}
export interface ChecksOut {
failed: FailedCheckOut[];
soft_failed: FailedCheckOut[];
cross_form: FailedCheckOut | null;
accepted: { by: string; at: string; comment: string } | null;
}
export interface StatementOut {
document: {
id: string;
document_type: DocumentType;
status: DocumentStatus;
period_year: number | null;
period_quarter: Quarter | null;
reporting_date: string | null;
counterparty_check: CheckResult | null;
locator: string | null;
file_id: string;
};
edition: string | null;
header: StatementHeaderOut;
columns: ColumnOut[];
lines: LineOut[];
checks: ChecksOut;
}
export type CellPatch = ({ line_id: string } | { line_code: string }) & { column_id: string; amount: string | null };
export interface StatementPatch {
header?: { inn?: string; report_date?: string; units?: string };
values?: CellPatch[];
}
export type CounterpartyType = 'GSK' | 'GK' | 'EXTERNAL';
export type MatchKind = 'INN' | 'NAME' | 'ALIAS' | 'MANUAL' | 'PROPAGATED';
export interface ConsolidatedRowOut {
entry_ids: string[];
legal_entity_id: string;
legal_entity_name: string;
legal_entity_inn: string;
account_code: string | null;
account_root: string | null;
period: string;
is_cumulative: boolean;
counterparty_name: string | null;
counterparty_inn: string | null;
counterparty_id: string | null;
counterparty_entity_name: string | null;
/** ИНН сопоставленного ЮЛ справочника; `counterparty_inn` — ИНН из файла (arm-core #74). */
counterparty_entity_inn: string | null;
counterparty_type: CounterpartyType;
match_kind: MatchKind | null;
opening_debit: string | null;
opening_credit: string | null;
turnover_debit: string | null;
turnover_credit: string | null;
closing_debit: string | null;
closing_credit: string | null;
warnings: string[];
}
export interface RefOut {
id: string;
name: string;
}
export type CandidateScope = 'group' | 'all';
/** Кандидат ручного сопоставления (`GET …/counterparty-candidates`). */
export interface CandidateOut {
id: string;
inn: string;
name: string;
company_group: RefOut | null;
gsk: RefOut | null;
gsz: RefOut | null;
counterparty_type: CounterpartyType;
recommended: boolean;
}
export interface MapCounterpartyIn {
legal_entity_id: string;
move_alias?: boolean;
}
/** `row = null` — строка в свод не попадает; `propagated` — число записей osv_entry, а не строк свода. */
export interface MapCounterpartyOut {
row: ConsolidatedRowOut | null;
propagated: number;
alias_created: boolean;
alias_moved_from: string | null;
}
export interface GapOut {
legal_entity_id: string;
legal_entity_name: string;
account_code: string;
missing_quarters: Quarter[];
}
export interface OsvSummaryOut {
rows_total: number;
unmapped_total: number;
auto_matched_total: number;
documents_total: number;
gaps: GapOut[];
}
export interface OsvFilters {
legal_entity_id?: string;
account_root?: string;
counterparty_type?: CounterpartyType;
unmapped?: boolean;
q?: string;
}
export interface ConsolidationCreate {
company_group_id: string;
related_group_id: string;
year: number;
quarter: Quarter;
legal_entity_ids: string[];
}
export interface RelatedGroupOut {
id: string;
code: string;
company_group_id: string;
kind: 'gsk' | 'gsz';
name: string;
created_date: string | null;
members_count: number;
}
export interface RelatedGroupMemberOut {
legal_entity_id: string;
inn: string;
name: string;
valid_from: string;
}
export interface RelatedGroupDetail extends RelatedGroupOut {
members: RelatedGroupMemberOut[];
}
export interface LegalEntityBrief {
id: string;
name: string;
inn: string;
}