- 新增 `src/domains/bill/form-helpers.ts`:统一单据类型路由(`resolveBillFormType`:模板类型 > 流程类型 > 字段特征)、东八区日期区间解析、历史流转字段剥离、以及 `dataLinkEdits` 强制重置 `dataLinkId: null` - 更新 `draft-validation.ts`:按类型路由明细校验(非报销单允许无 `details`)、跳过 `hide`/`hidden` 必填字段、强制拦截缺失 `dataLinkId` 键的行程条目(`DATALINK_ID_KEY_MISSING`)与非法 `feeDatePeriod` - 更新 `copy.ts` 与 `cli/commands/bill/copy.ts`:支持申请单复制(不注入 `expenseMoney`/`payMoney`,自动升级最新启用模板版本并重置行程 `dataLinkId: null`),新增 `--reason`/`--description`、`--amount`、`--start-date`、`--end-date` - 新增 `bill edit`(别名 `update`)草稿编辑命令与 `editBillDraft` / `updateBillFlow`,支持修改 `draft` 草稿的标题、事由、申请金额与差旅起止日期(同步联动行程日期) - 更新 `submit.ts`:正确传递 `requisition` 等 `formType`,放行 `ebot`、自动跳过节点(`skippedType`)及条件/延迟计算节点(`conditionalType` / `laterCalcReason`) - 补齐域层与 CLI 单元测试并同步更新 `README.bill.md` 与 `skills/hose-use/references/bill.md`
121 lines
4.4 KiB
TypeScript
121 lines
4.4 KiB
TypeScript
import { editBillDraft, prepareBillEdit } from "../../../domains/bill/write.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";
|
||
|
||
function formatPeriodCst(period: { start?: number; end?: number } | undefined): string {
|
||
if (!period?.start || !period?.end) return "-";
|
||
const fmt = (ms: number) =>
|
||
new Date(ms).toLocaleDateString("sv-SE", { timeZone: "Asia/Shanghai" });
|
||
return `${fmt(period.start)} ~ ${fmt(period.end)}`;
|
||
}
|
||
|
||
/**
|
||
* `hose-use bill edit <单号|ID> [--title=...] [--reason=...] [--description=...] [--amount=...] [--start-date=YYYY-MM-DD] [--end-date=YYYY-MM-DD] [--dry-run] --yes`
|
||
*
|
||
* 仅允许编辑 `draft` 状态草稿(`freeflow.edit`)。
|
||
*/
|
||
export async function handleEdit(ctx: BillActionContext): Promise<CliResult> {
|
||
const { parsed, runtime, corpId } = ctx;
|
||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||
if (!target) {
|
||
throw new Error(
|
||
"请提供要编辑的草稿单号或 ID: hose-use bill edit <单号|ID> [--title=...] [--reason=...] [--amount=...] [--start-date=YYYY-MM-DD --end-date=YYYY-MM-DD] --yes"
|
||
);
|
||
}
|
||
|
||
const title = stringOption(parsed.options, ["title"]);
|
||
const reason = stringOption(parsed.options, ["reason", "description"]);
|
||
const amount = stringOption(parsed.options, ["amount"]);
|
||
const startDate = stringOption(parsed.options, ["start-date", "startDate"]);
|
||
const endDate = stringOption(parsed.options, ["end-date", "endDate"]);
|
||
const editOptions = { title, reason, amount, startDate, endDate };
|
||
|
||
const client = await ctx.getClient();
|
||
|
||
if (isDryRun(parsed, runtime)) {
|
||
const prepared = await prepareBillEdit(client, corpId, target, editOptions);
|
||
if (runtime.jsonMode) {
|
||
return {
|
||
stdout: printJson(
|
||
{
|
||
dryRun: true,
|
||
code: prepared.code,
|
||
flowId: prepared.flowId,
|
||
formType: prepared.formType,
|
||
beforeTitle: prepared.beforeTitle,
|
||
afterTitle: prepared.afterTitle,
|
||
beforeDescription: prepared.beforeDescription,
|
||
afterDescription: prepared.afterDescription,
|
||
amount: prepared.amount,
|
||
tripCount: prepared.tripCount,
|
||
...(prepared.feeDatePeriod ? { feeDatePeriod: prepared.feeDatePeriod } : {}),
|
||
},
|
||
runtime.outputOptions
|
||
),
|
||
stderr: "",
|
||
exitCode: 0,
|
||
};
|
||
}
|
||
|
||
const lines = [
|
||
`====== 编辑草稿(dry-run,未保存) ======`,
|
||
` 单号 : ${prepared.code}(${prepared.flowId})`,
|
||
` 类型 : ${prepared.formType}`,
|
||
` 标题 : ${prepared.beforeTitle === prepared.afterTitle ? prepared.afterTitle : `${prepared.beforeTitle} -> ${prepared.afterTitle}`}`,
|
||
` 事由 : ${prepared.beforeDescription === prepared.afterDescription ? (prepared.afterDescription || "-") : `${prepared.beforeDescription || "(空)"} -> ${prepared.afterDescription || "(空)"}`}`,
|
||
` 金额 : ${prepared.amount} CNY`,
|
||
];
|
||
if (prepared.feeDatePeriod) {
|
||
lines.push(` 日期 : ${formatPeriodCst(prepared.feeDatePeriod)}`);
|
||
}
|
||
if (prepared.tripCount > 0) {
|
||
lines.push(` 行程 : ${prepared.tripCount} 条`);
|
||
}
|
||
lines.push("", "提示: 确认无误后追加 --yes 保存草稿(不会提交)", "");
|
||
|
||
return {
|
||
stdout: lines.join("\n"),
|
||
stderr: "",
|
||
exitCode: 0,
|
||
};
|
||
}
|
||
|
||
await ctx.requireWriteConfirmation();
|
||
const result = await editBillDraft(client, corpId, target, editOptions);
|
||
|
||
if (runtime.jsonMode) {
|
||
return {
|
||
stdout: printJson(
|
||
{
|
||
updated: true,
|
||
code: result.code,
|
||
flowId: result.flowId,
|
||
title: result.title,
|
||
description: result.description,
|
||
formType: result.formType,
|
||
amount: result.amount,
|
||
tripCount: result.tripCount,
|
||
},
|
||
runtime.outputOptions
|
||
),
|
||
stderr: "",
|
||
exitCode: 0,
|
||
};
|
||
}
|
||
|
||
return {
|
||
stdout:
|
||
`草稿保存成功(未提交)\n` +
|
||
` 单号 : ${result.code}\n` +
|
||
` 单据 ID : ${result.flowId}\n` +
|
||
` 标题 : ${result.title}\n` +
|
||
` 事由 : ${result.description || "-"}\n` +
|
||
` 金额 : ${result.amount} CNY${result.tripCount > 0 ? `(行程 ${result.tripCount} 条)` : ""}\n`,
|
||
stderr: "",
|
||
exitCode: 0,
|
||
};
|
||
}
|