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
@@ -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));
|
||||
}
|
||||
Reference in new issue
Block a user