| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { readSubscriptions } from "./subscription-store";
- /** 原型 data.js 的应收期次及对账结果摘录;仅收录合同编号可核对的样例。
- * 一条期次 = 一份订阅 × 一个自然月;对账清单按当月分成方展开,各自独立成批。 */
- export type BillingStatementRef = { no: string; party: string; status: "已执行" | "待执行" | "执行失败" };
- export type ContractBillingPeriod = {
- subscriptionId?: string; // 原型期次的订阅关联;旧样例可为空
- month: string; // 自然月
- subscription: string; // 订阅(该期计费的订阅)
- daysText: string; // 在网天数口径(首末月折算 / 尾月对齐在文案中标注)
- std: number; // 月结算标准(元/月)
- amount: number; // 应收金额(按在网天数折算)
- cost: number | null; // 成本快照合计;无随附成本项为 0,未知时为 null
- status: "已出账" | "未出账" | "出账异常";
- statements: BillingStatementRef[]; // 该期应收进入的对账清单批次
- };
- function subscriptionLabel(contractNo: string): string {
- const sub = readSubscriptions().find((item) => item.contractNumber === contractNo);
- if (!sub) return "—";
- return sub.changeKind === "首次订阅" ? sub.planName : `${sub.planName} · ${sub.changeKind}`;
- }
- const stmt = (batch: string, entries: [string, BillingStatementRef["status"]][]): BillingStatementRef[] =>
- entries.map(([party, status]) => ({ no: batch, party, status }));
- export const contractBillingPeriods: Record<string, ContractBillingPeriod[]> = {
- "HT-CL-20260318": [
- {
- month: "2026-03", subscriptionId: "SUB-2026-002", subscription: subscriptionLabel("HT-CL-20260318"),
- daysText: "12 / 31 天(首末月折算)", std: 120, amount: 46.45, cost: 0, status: "已出账",
- statements: stmt("ST-202604-SH-01", [["联通", "已执行"], ["邹合", "已执行"], ["华东常规运维", "已执行"], ["沪东施工", "已执行"]]),
- },
- {
- month: "2026-04", subscriptionId: "SUB-2026-002", subscription: subscriptionLabel("HT-CL-20260318"),
- daysText: "30 / 30 天", std: 120, amount: 120, cost: 0, status: "已出账",
- statements: stmt("ST-202605-SH-01", [["联通", "已执行"], ["邹合", "已执行"], ["华东常规运维", "已执行"], ["沪东施工", "已执行"]]),
- },
- {
- month: "2026-09", subscriptionId: "SUB-2026-002", subscription: subscriptionLabel("HT-CL-20260318"),
- daysText: "30 / 30 天", std: 120, amount: 120, cost: 0, status: "已出账",
- statements: stmt("ST-202610-SH-01", [["联通", "已执行"], ["邹合", "已执行"], ["华东常规运维", "已执行"], ["沪东施工", "已执行"]]),
- },
- ],
- "HT-WM-20260601": [
- {
- month: "2026-09", subscriptionId: "SUB-2026-005", subscription: subscriptionLabel("HT-WM-20260601"),
- daysText: "30 / 30 天", std: 480, amount: 480, cost: 46, status: "已出账",
- statements: stmt("ST-202610-GD-02", [["移动", "已执行"]]),
- },
- ],
- "HT-WM-20260801": [
- {
- month: "2026-09", subscriptionId: "SUB-2026-006", subscription: subscriptionLabel("HT-WM-20260801"),
- daysText: "30 / 30 天", std: 160, amount: 160, cost: 26, status: "已出账",
- statements: stmt("ST-202610-GD-02", [["移动", "已执行"]]),
- },
- ],
- "HT-HL-20251001": [
- {
- month: "2026-09", subscription: subscriptionLabel("HT-HL-20251001"),
- daysText: "30 / 30 天", std: 160, amount: 160, cost: 50, status: "已出账",
- statements: stmt("ST-202610-SH-02", [["联通", "已执行"]]),
- },
- ],
- };
- export function contractBillingSummary(no: string) {
- const periods = contractBillingPeriods[no];
- if (!periods) return null;
- return {
- periods,
- receivable: periods.reduce((sum, row) => sum + row.amount, 0),
- billed: periods.filter((row) => row.status === "已出账").reduce((sum, row) => sum + row.amount, 0),
- abnormalCount: periods.filter((row) => row.status === "出账异常").length,
- };
- }
|