acc_invoices: сервис WebUI и бэкенд платёжного процесса (миграция 082, правила статусов, согласования, ручная отметка оплаты), статусы оплат, предложения к ТЗ
All checks were successful
ci / test (push) Successful in 59s
ci / deploy (push) Successful in 3m14s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 12:44:58 +03:00
parent 37778d8b11
commit 16e9b2c085
31 changed files with 2458 additions and 6 deletions

View File

@@ -74,11 +74,11 @@ export async function runInvoiceCheck(deps: { pool: Pool; now?: () => Date }): P
const now = (deps.now ?? (() => new Date()))();
const today = now.toISOString().slice(0, 10);
const res: InvoiceCheckResult = { checked: 0, withProblems: 0, errors: [] };
const { rows } = await deps.pool.query("select id from acc_invoices where stage = 'checking' and conclusion is null order by created_at");
const { rows } = await deps.pool.query("select id from acc_invoices where stage = 'checking' and conclusion is null and not is_draft and not cancelled order by created_at");
for (const { id } of rows as { id: string }[]) {
try {
const problems = await withTx(deps.pool, async (c) => {
const inv = (await c.query("select * from acc_invoices where id = $1 and stage = 'checking' and conclusion is null for update skip locked", [id])).rows[0];
const inv = (await c.query("select * from acc_invoices where id = $1 and stage = 'checking' and conclusion is null and not is_draft and not cancelled for update skip locked", [id])).rows[0];
if (!inv) return null;
// контракт: указанный в инвойсе, иначе по вендору и проекту (один; если несколько - неоднозначно, не выбираем)
const found = (
@@ -118,8 +118,9 @@ export async function runInvoiceCheck(deps: { pool: Pool; now?: () => Date }): P
insuranceValidUntil: cert.rows[0]?.v ?? null, contractBasis: inv.contract_basis ?? null, today, now,
});
await c.query(
"update acc_invoices set conclusion = $2::jsonb, contract_id = coalesce(contract_id, $3::uuid) where id = $1",
[id, JSON.stringify(concl), contract?.id ?? null],
// llm_result (сервис acc_invoices): «OK» без замечаний, иначе текст проблем
"update acc_invoices set conclusion = $2::jsonb, contract_id = coalesce(contract_id, $3::uuid), llm_result = $4 where id = $1",
[id, JSON.stringify(concl), contract?.id ?? null, concl.problems.length ? concl.problems.join("; ") : "OK"],
);
const highlight = concl.problems.length > 0 ? concl.problems.join("; ") : null;
await c.query(