diff --git a/packages/acc_invoices/src/repo.ts b/packages/acc_invoices/src/repo.ts index 83c34d6..98cfea2 100644 --- a/packages/acc_invoices/src/repo.ts +++ b/packages/acc_invoices/src/repo.ts @@ -8,7 +8,7 @@ const LIST_SQL = ` select i.id, i.invoice_number, i.vendor_name, i.vendor_qbo_id, i.invoice_date::text as invoice_date, i.amount::float8 as amount, i.project_customer_id, i.jt_job_id, i.contract_id, i.pay_method, i.is_draft, i.cancelled, i.is_approved, i.llm_result, i.manual_result, i.invoice_url, i.payment_url, - i.sent_to_bank, i.paid_on::text as paid_on, i.is_paid_manual, i.paid_manual_at, i.review_date::text as review_date, + i.sent_to_bank, i.qbo_txn_id, i.paid_on::text as paid_on, i.is_paid_manual, i.paid_manual_at, i.review_date::text as review_date, i.need_employee_refund, i.is_employee_refunded, i.author, i.target_employee, i.created_at, i.updated_at, (select display_name from person where id = i.author) as author_name, (select display_name from person where id = i.target_employee) as target_name, diff --git a/packages/acc_invoices/src/rules.ts b/packages/acc_invoices/src/rules.ts index 33e95e5..5aae079 100644 --- a/packages/acc_invoices/src/rules.ts +++ b/packages/acc_invoices/src/rules.ts @@ -17,6 +17,7 @@ export interface InvoiceRow { is_paid_manual: boolean; /** когда сотрудник поставил отметку «оплачен» */ paid_manual_at: Date | string | null; + qbo_txn_id?: string | null; review_date: string | null; amount: number; author: string | null; diff --git a/packages/acc_invoices/web/src/App.tsx b/packages/acc_invoices/web/src/App.tsx index ca309e3..5758b18 100644 --- a/packages/acc_invoices/web/src/App.tsx +++ b/packages/acc_invoices/web/src/App.tsx @@ -8,6 +8,10 @@ import { day, money, shortDate } from "./format.js"; interface ListResp { items: Row[]; counts: Record } +const qbUrl = (txn: string): string => txn.startsWith("bill:") ? `https://app.qbo.intuit.com/app/bill?txnId=${txn.slice(5)}` : `https://app.qbo.intuit.com/app/expense?txnId=${txn}`; +const QB_ICON = ( + +); const hashFilter = (): string => new URLSearchParams(location.hash.slice(1)).get("f") ?? "to_pay"; export function App() { @@ -49,6 +53,8 @@ function Main({ me, onLogout }: { me: Me; onLogout: () => void }) { const [reason, setReason] = useState(""); const [pendingAction, setPendingAction] = useState<"manual" | "reject" | null>(null); const seq = useRef(0); + const [loading, setLoading] = useState(true); + const [checked, setChecked] = useState>(new Set()); const flash = (text: string, bad = false) => { setToast({ text, bad }); setTimeout(() => setToast(null), bad ? 8000 : 3000); }; const run = async (p: Promise, ok?: string) => { @@ -60,10 +66,12 @@ function Main({ me, onLogout }: { me: Me; onLogout: () => void }) { const loadList = useCallback(async () => { const n = ++seq.current; + setLoading(true); try { const r = await api(`invoices?filter=${filter}${q.trim() ? `&q=${encodeURIComponent(q.trim())}` : ""}`); if (n === seq.current) setList(r); } catch (e) { flash(String(e instanceof ApiError ? e.message : e), true); } + finally { if (n === seq.current) setLoading(false); } }, [filter, q]); const loadDetail = useCallback(async (id: string | null) => { if (!id) { setDetail(null); return; } @@ -87,7 +95,21 @@ function Main({ me, onLogout }: { me: Me; onLogout: () => void }) { if (n) setSelected(n.id); }; - const tabs = Ariakit.useTabStore({ selectedId: filter, setSelectedId: (id) => id && setFilter(id) }); + const tabs = Ariakit.useTabStore({ selectedId: filter, setSelectedId: (id) => { if (id && id !== filter) { setList((l) => ({ ...l, items: [] })); setLoading(true); setFilter(id); } } }); + const showQb = me.is_staff; + const chosen = list.items.filter((r) => checked.has(r.id)); + const allChecked = list.items.length > 0 && list.items.every((r) => checked.has(r.id)); + const toggle = (id: string) => setChecked((s) => { const n = new Set(s); if (n.has(id)) n.delete(id); else n.add(id); return n; }); + const toggleAll = () => setChecked((s) => { const n = new Set(s); if (allChecked) list.items.forEach((r) => n.delete(r.id)); else list.items.forEach((r) => n.add(r.id)); return n; }); + const idsText = () => chosen.map((r) => r.id).join("\n"); + const copyIds = async () => { try { await navigator.clipboard.writeText(idsText()); flash(`Скопировано id: ${chosen.length}`); } catch { flash("Не удалось скопировать в буфер", true); } }; + const askClaude = async () => { + const lines = chosen.map((r) => `- acc_invoices id ${r.id}: ${r.vendor_name}, инвойс ${r.invoice_number ?? "без номера"}, ${r.invoice_date}, ${money(r.amount)}${r.qbo_txn_id ? `, QuickBooks txn ${r.qbo_txn_id}` : ""}`).join("\n"); + const prompt = `Подключись к MCP нашей бухгалтерской автоматизации KH Build (accounting) и к MCP QuickBooks. Получи информацию по этим операциям (инвойсы/платежи из acc_invoices и их проводки в QuickBooks):\n${lines}\n\nКогда получишь данные, ответь только: «ОК, какой у Вас вопрос?». Затем я задам вопрос по этим операциям.`; + const url = `https://claude.ai/new?q=${encodeURIComponent(prompt)}`; + if (url.length > 7000) { try { await navigator.clipboard.writeText(prompt); } catch { /* ignore */ } flash("Выбрано много операций: промпт скопирован, вставьте его в новый чат Claude", true); window.open("https://claude.ai/new", "_blank", "noopener"); return; } + window.open(url, "_blank", "noopener"); + }; const contractTab = Ariakit.useTabStore({ defaultSelectedId: "inv" }); const lineTotal = useMemo(() => (detail?.details ?? []).reduce((s, l) => s + l.amount, 0), [detail]); const myPending = detail?.approves.some((a) => a.approver_person_id === me.person_id && a.decision === "pending"); @@ -105,6 +127,14 @@ function Main({ me, onLogout }: { me: Me; onLogout: () => void }) { setQ(e.target.value)} aria-label="Поиск" /> + {chosen.length > 0 && ( + + выбрано {chosen.length}: {chosen.slice(0, 3).map((r) => r.id.slice(0, 8)).join(", ")}{chosen.length > 3 ? "…" : ""} + + + + + )} {me.name} {me.can_switch && ( + СтатусДатаВендорИнвойсПроектСумма + Проверки +
+
A проверка агента (автоматическая): зелёный - OK, красный - найдена проблема, серый - ещё не проверялось
+
С проверка сотрудником (бухгалтерия): зелёный - OK, красный - проблема, серый - не проверено
+
✓ согласования: зелёный - согласовано или не требуется, серый - ждёт решения, красный - отклонено
+
+ + ОплатаКто ждёт{showQb && QB} {list.items.map((r) => ( setSelected(r.id)} aria-selected={r.id === selected}> + e.stopPropagation()}> toggle(r.id)} /> {r.status === "on_payment" ? `На оплате ${day(r.sent_to_bank)}` : r.status === "postponed" ? `Отложен до ${day(r.review_date)}` : r.status_label}{r.errors.length > 0 && !} {shortDate(r.invoice_date)} {r.vendor_name} @@ -139,9 +181,10 @@ function Main({ me, onLogout }: { me: Me; onLogout: () => void }) { {r.paid_on ? `${shortDate(r.paid_on)} QB` : r.is_paid_manual ? "отмечен, ждём QB" : ""} {r.target_name} + {showQb && e.stopPropagation()}>{r.qbo_txn_id && {QB_ICON}}} ))} - {!list.items.length && Нет инвойсов в этом фильтре} + {!list.items.length && Нет инвойсов в этом фильтре} diff --git a/packages/acc_invoices/web/src/api.ts b/packages/acc_invoices/web/src/api.ts index 327e90f..6d10732 100644 --- a/packages/acc_invoices/web/src/api.ts +++ b/packages/acc_invoices/web/src/api.ts @@ -3,7 +3,7 @@ export interface Row { id: string; invoice_number: string | null; vendor_name: string; vendor_qbo_id: string | null; invoice_date: string | null; amount: number; project_customer_id: string | null; project_name: string | null; contract_id: string | null; pay_method: string | null; is_draft: boolean; cancelled: boolean; is_approved: boolean; llm_result: string | null; manual_result: string | null; - invoice_url: string | null; payment_url: string | null; sent_to_bank: string | null; paid_on: string | null; is_paid_manual: boolean; + invoice_url: string | null; payment_url: string | null; qbo_txn_id: string | null; sent_to_bank: string | null; paid_on: string | null; is_paid_manual: boolean; review_date: string | null; need_employee_refund: boolean; is_employee_refunded: boolean; author: string | null; target_employee: string | null; author_name: string | null; target_name: string | null; approves_pending: number; approves_rejected: number; status: string; status_label: string; errors: string[]; editable: string[]; } diff --git a/packages/acc_invoices/web/src/styles.css b/packages/acc_invoices/web/src/styles.css index 74f14b0..3778b50 100644 --- a/packages/acc_invoices/web/src/styles.css +++ b/packages/acc_invoices/web/src/styles.css @@ -23,6 +23,20 @@ body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 syst .search { min-width: 240px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); } .spacer { flex: 1; } .who { color: var(--muted); } +.chosen { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-2); } +.chosen-ids { color: var(--accent); font-size: 13px; font-variant-numeric: tabular-nums; } +.master { position: relative; } +.master.loading .grid-table { opacity: .35; transition: opacity .15s; } +.loader { position: absolute; inset: 0; z-index: 3; display: flex; align-items: flex-start; justify-content: center; padding-top: 70px; gap: 10px; color: var(--accent); font-weight: 600; pointer-events: none; } +.spinner { width: 20px; height: 20px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; } +@keyframes spin { to { transform: rotate(360deg); } } +.grid-table th.cb, .grid-table td.cb { width: 28px; padding: 5px 6px 5px 10px; } +.grid-table th.qb, .grid-table td.qb { width: 34px; text-align: center; padding: 5px 4px; } +.grid-table td.qb a { display: inline-flex; } +.hint-th { position: sticky; cursor: help; } +.hint-pop { display: none; position: absolute; top: 100%; left: 0; z-index: 5; width: 380px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); white-space: normal; font-weight: 400; color: var(--text); line-height: 1.5; } +.hint-pop div { margin-bottom: 6px; } +.hint-th:hover .hint-pop, .hint-th:focus .hint-pop { display: block; } .role-switch { padding: 5px 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; } .btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 6px 14px; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; display: inline-block; }