Очередь: столбец «списано с» и ссылка на QuickBooks, ответ на проблему и contract_basis (миграция 077), инструкции и процессы; review-done-action.md
All checks were successful
ci / test (push) Successful in 1m7s
ci / deploy (push) Successful in 3m16s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 17:47:01 +03:00
parent 09f6f81038
commit 1a7515dfbc
9 changed files with 163 additions and 16 deletions

View File

@@ -35,6 +35,8 @@ export function buildConclusion(i: {
ambiguousContractIds?: string[];
duplicateIds: string[];
insuranceValidUntil: string | null;
/** Основание вместо договора: invoice - сам инвойс служит основанием (доп. заказ), проблема «нет контракта» не ставится. */
contractBasis?: string | null;
today: string;
now: Date;
}): Conclusion {
@@ -43,7 +45,7 @@ export function buildConclusion(i: {
const remaining = c ? Math.round((c.total_amount - c.retained_amount - c.paid_amount) * 100) / 100 : null;
const ambiguous = i.ambiguousContractIds ?? [];
if (ambiguous.length > 1) problems.push(`контракт неоднозначен: у вендора на этом проекте контрактов ${ambiguous.length}, выберите нужный (сверка стадии работ тоже вручную)`);
else if (!c) problems.push("нет контракта с этим вендором на этом проекте");
else if (!c && i.contractBasis !== "invoice") problems.push("нет контракта с этим вендором на этом проекте");
const exceeds = remaining !== null && i.amount > remaining;
if (exceeds) problems.push(`сумма инвойса ${i.amount.toFixed(2)} больше остатка по контракту ${remaining!.toFixed(2)}`);
if (i.duplicateIds.length > 0) problems.push(`возможный дубль инвойса (${i.duplicateIds.length} шт.: тот же номер или та же сумма и дата)`);
@@ -113,7 +115,7 @@ export async function runInvoiceCheck(deps: { pool: Pool; now?: () => Date }): P
);
const concl = buildConclusion({
amount: Number(inv.amount), contract, ambiguousContractIds: ambiguousIds, duplicateIds: (dup.rows as { id: string }[]).map((r) => r.id),
insuranceValidUntil: cert.rows[0]?.v ?? null, today, now,
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",