Files
hose-use/src/cli/commands/bill/create.ts
T
gitea ebeec98f6d fix: 整合本地单据校验与离线身份修复
从旧审查分支选择仍未进入主分支的单据修复,保留主分支较新的工作流与插件分发实现。
兼容费用类型包装树,统一创建预演与执行,修正核销净支付,并将真实规格校验接入复制及送审。
注册 whoami 离线参数,补充写入契约和完整入口回归,保留旧分支与工作区。

验证:bun test 876 pass / 0 fail;bun run check、check:version、git diff --check 通过。
2026-10-28 15:00:37 +08:00

67 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createBillDraft, prepareBillDraft } from "../../../domains/bill/create.js";
import { isDryRun } from "../../mutation.js";
import { stringOption } from "../../parser.js";
import { printJson } from "../../printer.js";
import type { CliResult } from "../../types.js";
import type { BillActionContext } from "./context.js";
/**
* `hose-use bill create --template <模板ID> [--title=...] [--amount=0.01] [--reason=...] [--dry-run] --yes`
*
* 纯接口创建草稿:最小表头 + 一条费用明细,创建后不提交。
*/
export async function handleCreate(ctx: BillActionContext): Promise<CliResult> {
const { parsed, runtime, corpId } = ctx;
const templateId = stringOption(parsed.options, ["template", "spec", "specification"]);
if (!templateId) {
throw new Error("请通过 --template 指定单据模板 ID: hose-use bill create --template <ID> --yes");
}
const title = stringOption(parsed.options, ["title"]);
const amount = stringOption(parsed.options, ["amount"]) ?? "0.01";
const reason = stringOption(parsed.options, ["reason"]);
const feeTypeName = stringOption(parsed.options, ["fee-type", "feeType"]);
if (isDryRun(parsed, runtime)) {
const prepared = await prepareBillDraft(await ctx.getClient(), corpId, { templateId, title, amount, reason, feeTypeName });
const preview = { template: templateId, title: prepared.title, amount: prepared.amount, reason: reason ?? "", feeType: prepared.feeType };
if (runtime.jsonMode) {
return { stdout: printJson({ dryRun: true, ...preview }, runtime.outputOptions), stderr: "", exitCode: 0 };
}
return {
stdout:
`====== 创建单据(dry-run,未创建) ======\n` +
` 模板 : ${preview.template}\n` +
` 标题 : ${preview.title}\n` +
` 金额 : ${preview.amount} CNY\n` +
` 费用类型: ${preview.feeType}\n` +
` 事由 : ${preview.reason || "-"}\n` +
`\n提示: 追加 --yes 执行创建(仍为草稿,不会提交)\n`,
stderr: "",
exitCode: 0,
};
}
await ctx.requireWriteConfirmation();
const result = await createBillDraft(await ctx.getClient(), corpId, {
templateId,
title,
amount,
reason,
feeTypeName,
});
if (runtime.jsonMode) {
return { stdout: printJson({ ...result, submitted: false }, runtime.outputOptions), stderr: "", exitCode: 0 };
}
return {
stdout:
`创建成功(草稿,未提交)\n` +
` 单号 : ${result.code}\n` +
` 流程 ID : ${result.flowId}\n` +
` 标题 : ${result.title}\n` +
` 金额 : ${result.amount} CNY(${result.feeType})\n`,
stderr: "",
exitCode: 0,
};
}