26 lines
1.7 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.

// Правила правки: когда у колонки можно править дату и когда у ячейки доступно подтверждение (P6-6, P6-11).
import type { ColumnOut, IssueOut, ValueOut } from '../../types/api';
import type { StatementDraft } from './statementDraft';
import type { GridRow } from './statementGrid';
/** Записи issues, при которых аналитик правит или подтверждает дату колонки. */
export const COLUMN_DATE_CODES: ReadonlySet<string> = new Set(['COLUMN_WITHOUT_DATE', 'COLUMN_DATE_UNCERTAIN']);
export function columnDateEditable(col: ColumnOut, columnIssues: IssueOut[]): { editable: boolean; canConfirm: boolean } {
const flagged = columnIssues.some((issue) => COLUMN_DATE_CODES.has(issue.code));
const editable = (col.period_kind === 'none' && col.period_date === null) || flagged;
return { editable, canConfirm: editable && col.period_date !== null && flagged };
}
export type CellConfirmState = 'confirm' | 'unconfirm' | 'pending-confirm' | 'pending-unconfirm' | null;
/** Какая кнопка подтверждения нужна ячейке. Нужны оба `id` (у достроенных ядро ответит UNKNOWN_CELL); сумма в черновике подтверждение отменяет. */
export function cellConfirmState(row: GridRow, value: ValueOut | undefined, draft: StatementDraft, key: string): CellConfirmState {
if (!row.lineId || !value || value.id === null) return null;
if (key in draft.amounts) return null;
if (key in draft.confirms) return draft.confirms[key] ? 'pending-confirm' : 'pending-unconfirm';
if (value.needs_review) return 'confirm';
if (value.is_confirmed) return 'unconfirm';
return null;
}