Add normalized invoice fields, first-class invoices CLI, and CLI-attributed conflict diagnosis
This commit is contained in:
1 parent
b17f7ad722
commit
d40ab9648d
10 files changed
+605
-9
No files matched your search
@@ -3,7 +3,9 @@ export const AREA_ALIASES: Readonly<Record<string, string>> = {
|
||||
corp: "corps",
|
||||
webhooks: "webhook",
|
||||
preferences: "preference",
|
||||
server: "mcp"
|
||||
server: "mcp",
|
||||
invoice: "invoices",
|
||||
expense: "expenses"
|
||||
}
|
||||
|
||||
export const UPDATE_ALIASES = new Set([
|
||||
|
||||
@@ -26,7 +26,10 @@ export async function handleDataCommand(
|
||||
}
|
||||
|
||||
if (action === "invoices" || action === "invoice") {
|
||||
await runCapability("sealInvoicesList", client, corp, params, outputOptions(args.options));
|
||||
const subAction = args.command[2];
|
||||
const maybeTarget = args.command[3];
|
||||
const { handleInvoicesCommand } = await import("./invoices.js");
|
||||
await handleInvoicesCommand(subAction, maybeTarget, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import type { createSealClient } from "../../core/http/factory.js";
|
||||
import { traceInvoice } from "../../domains/seal/approval-runs/invoices.js";
|
||||
import { runCapability } from "../helpers.js";
|
||||
import { booleanOption, numberOption, stringOption } from "../parser.js";
|
||||
import { outputOptions, printJson } from "../printer.js";
|
||||
import type { ParsedArgs } from "../types.js";
|
||||
|
||||
export async function handleInvoicesCommand(
|
||||
action: string | undefined,
|
||||
maybeTarget: string | undefined,
|
||||
client: Awaited<ReturnType<typeof createSealClient>>,
|
||||
corp: CorpConfig,
|
||||
args: ParsedArgs
|
||||
) {
|
||||
// Check if subcommand is "trace" or a positional invoice number
|
||||
const isTrace = action === "trace";
|
||||
const invoiceNumberToTrace = isTrace
|
||||
? (maybeTarget ?? stringOption(args.options.number) ?? stringOption(args.options.invoice))
|
||||
: (action && /^\d{10,25}$/.test(action) ? action : undefined);
|
||||
|
||||
if (invoiceNumberToTrace) {
|
||||
const report = await traceInvoice(client, invoiceNumberToTrace, corp.id);
|
||||
if (!report) {
|
||||
printJson(
|
||||
{
|
||||
found: false,
|
||||
invoiceNumber: invoiceNumberToTrace,
|
||||
message: `未在进项发票库中找到发票号码为 ${invoiceNumberToTrace} 的记录。`
|
||||
},
|
||||
outputOptions(args.options)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (report.conflictStatus === "MULTIPLE_DOCUMENTS_ATTACHED") {
|
||||
console.error(
|
||||
`\n💡 [CLI 辅助溯源指引](注:此指引由 seal-use CLI 基于进项发票库关联数据自动提炼,非后端大模型生成):\n` +
|
||||
`• 发票 ${report.invoice.invoiceNumber}(${report.invoice.sellerName},¥${report.invoice.totalAmount})在 ${report.associatedDocuments.length} 笔单据中均有挂载记录:\n` +
|
||||
report.associatedDocuments.map((d) => ` - 单号: ${d.sourceDocumentSN}(已占 ¥${d.usedAmount ?? 0})👉 诊断命令: ${d.nextDiagnose}`).join("\n") +
|
||||
`\n`
|
||||
);
|
||||
}
|
||||
|
||||
printJson(report, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, default to list / search
|
||||
const searchQuery =
|
||||
stringOption(args.options.search) ??
|
||||
stringOption(args.options.query) ??
|
||||
(action && action !== "list" ? action : undefined);
|
||||
|
||||
const params = {
|
||||
offset: numberOption(args.options.offset),
|
||||
limit: numberOption(args.options.limit),
|
||||
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]),
|
||||
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]),
|
||||
search: searchQuery,
|
||||
full: booleanOption(args.options.full) === true
|
||||
};
|
||||
|
||||
await runCapability("sealInvoicesList", client, corp, params, outputOptions(args.options));
|
||||
}
|
||||
+39
-3
@@ -1169,13 +1169,49 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
commands: [
|
||||
{
|
||||
name: "expenses",
|
||||
summary: "Search raw expense items",
|
||||
summary: "Search raw expense items (also available as 'seal-use expenses')",
|
||||
usage: ["seal-use data expenses [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--corp <corpId>]"]
|
||||
},
|
||||
{
|
||||
name: "invoices",
|
||||
summary: "Search raw invoice records",
|
||||
usage: ["seal-use data invoices [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--corp <corpId>]"]
|
||||
summary: "Search raw invoice records (also available as 'seal-use invoices')",
|
||||
usage: ["seal-use data invoices [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--full] [--corp <corpId>]"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
area: "invoices",
|
||||
title: "进项发票查询与溯源",
|
||||
description: "查看已审批单据中出现的进项发票,支持单据关联穿透、跨单据重复占用排查与扁平化业务视图。",
|
||||
commands: [
|
||||
{
|
||||
name: "list",
|
||||
summary: "分页查询进项发票(默认输出扁平化业务字段,对齐控制台表格)",
|
||||
usage: [
|
||||
"seal-use invoices [list] [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--full] [--corp <corpId>]"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "trace",
|
||||
summary: "穿透溯源指定发票,排查在哪些报销单据中被使用及是否存在跨单重复占用",
|
||||
usage: [
|
||||
"seal-use invoices trace <invoiceNumber> [--corp <corpId>]",
|
||||
"seal-use invoices <invoiceNumber> [--corp <corpId>]"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
area: "expenses",
|
||||
title: "费用明细查询",
|
||||
description: "查询历史费用明细记录。",
|
||||
commands: [
|
||||
{
|
||||
name: "list",
|
||||
summary: "分页查询费用明细",
|
||||
usage: [
|
||||
"seal-use expenses [list] [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--corp <corpId>]"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -65,6 +65,8 @@ const CLIENT_COMMANDS: Record<string, ClientCommand> = {
|
||||
"users": async (args, corp, client) => (await import("./commands/users.js")).handleUsersCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"contacts": async (args, corp, client) => (await import("./commands/contacts.js")).handleContactsCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"data": async (args, corp, client) => (await import("./commands/data.js")).handleDataCommand(args.command[1], client, corp, args),
|
||||
"invoices": async (args, corp, client) => (await import("./commands/invoices.js")).handleInvoicesCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"expenses": async (args, corp, client) => (await import("./commands/data.js")).handleDataCommand("expenses", client, corp, args),
|
||||
"llm": async (args, corp, client) => (await import("./commands/llm.js")).handleLlmCommand(args.command[1], client, corp, args),
|
||||
"permissions": async (args, corp, client) => (await import("./commands/permissions.js")).handlePermissionsCommand(args.command[1], client, corp, args),
|
||||
"billing": async (args, corp, client) => (await import("./commands/billing.js")).handleBillingCommand(args.command[1], client, corp, args),
|
||||
|
||||
Reference in new issue
Block a user