Инвойсы на Drive: раскладка как в «07. Invoices» (Инвойсы / способ оплаты / Месяц ГГГГ / «$сумма Вендор.pdf»), перенос оплаченных; drive_folder
Some checks failed
ci / test (push) Failing after 59s
ci / deploy (push) Has been skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 23:27:04 +03:00
parent dd60da4091
commit db333d6750
7 changed files with 122 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import type { Logger, Pool } from "khb_common";
import type { ClaudeRunner } from "./claude-runner.js";
import { UNTRUSTED_DOC_ARGS } from "./claude-runner.js";
import type { DriveStore } from "./drive.js";
import { invoiceFileName, invoiceFolderPath } from "./invoice-filing.js";
import { ingestCertificate } from "./certificates-ingest.js";
import { normalizeVendorName } from "./vendor-name.js";
import type { MailAttachment, MailMessage, MailSource } from "./gmail.js";
@@ -348,8 +349,10 @@ async function processAttachment(deps: InvoiceIngestDeps, msg: MailMessage, att:
if (tbd.length) problems.unshift(`tbd: ${tbd.join(", ")}`);
const refDate = rec.invoice_date ? new Date(`${rec.invoice_date}T00:00:00Z`) : msg.receivedAt;
const folder = await deps.drive.ensureFolder(["Инвойсы", safeName(rec.vendor_name ?? "Без вендора"), ym(refDate)]);
const file = await deps.drive.upload(att.filename, att.mime || "application/octet-stream", bytes, folder);
// раскладка как в папке «07. Invoices» Анастасии: способ оплаты / месяц / «$сумма Вендор.pdf»; способ оплаты неизвестен до оплаты - «Без оплаты»,
// после оплаты файл переносится в папку счёта оплаты (invoice-filing.ts)
const folder = await deps.drive.ensureFolder(invoiceFolderPath(null, refDate));
const file = await deps.drive.upload(invoiceFileName(rec.amount, rec.vendor_name, att.filename), att.mime || "application/octet-stream", bytes, folder);
await pool.query(
`insert into acc_invoices_review (id, source_message_id, drive_file_id, vendor_name, vendor_qbo_id, invoice_number, invoice_date, amount, lines,