acc_invoices: сервис WebUI и бэкенд платёжного процесса (миграция 082, правила статусов, согласования, ручная отметка оплаты), статусы оплат, предложения к ТЗ
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user