old_invoices: таблица (миграция 079), разбор Excel Анастасии и загрузка; архив инвойсов вне рабочего реестра

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 23:23:47 +03:00
parent 31e69589d8
commit dd60da4091
4 changed files with 207 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
-- Архив инвойсов из Excel Анастасии («Payments_Constr List», Drive id 1gPOutfuVrdEJK3j1YoaOd3e_7gHBv4GM): только история, в рабочий реестр acc_invoices не входит.
-- Загрузка повторяемая (уникальность: файл + лист + строка), скрипт packages/accounting_automation/scripts/old-invoices-load.mjs.
create table if not exists old_invoices (
id bigserial primary key,
source_file_id text not null,
source_sheet text not null, -- KH Open Invoices / GK Open Invoices / KH BUILD (три реестра = три компании/периода)
source_row int not null,
invoice_date date,
pay_method_raw text, -- как в Excel: portal, ACH, zelle, BofA transfer, QB link ...
pay_method text, -- нормализованный: ach, zelle, wire, bill_pay, bank_transfer, portal_link, qb_link, check, card, cash, paypal, other
project_text text, -- адрес как в Excel (в acc_invoices - project_customer_id)
project_customer_id text, -- заполняется сопоставлением с QuickBooks, если адрес совпал однозначно
invoice_number_raw text, -- номер вместе с мусором: «Inv 9846», «INVOICE # 5013», «Contract», «DrReq 4»
purpose text,
vendor_name text,
vendor_qbo_id text, -- заполняется сопоставлением с qbo_vendor по имени
amount numeric(14,2) not null, -- сумма платежа по строке (частичные оплаты - отдельными строками)
paid_raw text, -- столбец «дата оплаты / статус» как в Excel
paid_on date,
paid_status text, -- paid / approved / not_approved / waiting / other / unknown
note text, -- последний столбец: «total $…», ссылки, комментарии
contract_total numeric(14,2), -- «total $X» из примечания: полная сумма договора/инвойса, если платёж частичный
drive_file_id text, -- если в примечании была ссылка на Drive
section text,
raw jsonb not null, -- все ячейки строки по буквам столбцов
loaded_at timestamptz not null default now(),
unique (source_file_id, source_sheet, source_row)
);
create index if not exists old_invoices_vendor_idx on old_invoices (vendor_qbo_id, amount);
create index if not exists old_invoices_date_idx on old_invoices (invoice_date);
alter table old_invoices enable row level security;