contract-billing-demo.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { readSubscriptions } from "./subscription-store";
  2. /** 原型 data.js 的应收期次及对账结果摘录;仅收录合同编号可核对的样例。
  3. * 一条期次 = 一份订阅 × 一个自然月;对账清单按当月分成方展开,各自独立成批。 */
  4. export type BillingStatementRef = { no: string; party: string; status: "已执行" | "待执行" | "执行失败" };
  5. export type ContractBillingPeriod = {
  6. subscriptionId?: string; // 原型期次的订阅关联;旧样例可为空
  7. month: string; // 自然月
  8. subscription: string; // 订阅(该期计费的订阅)
  9. daysText: string; // 在网天数口径(首末月折算 / 尾月对齐在文案中标注)
  10. std: number; // 月结算标准(元/月)
  11. amount: number; // 应收金额(按在网天数折算)
  12. cost: number | null; // 成本快照合计;无随附成本项为 0,未知时为 null
  13. status: "已出账" | "未出账" | "出账异常";
  14. statements: BillingStatementRef[]; // 该期应收进入的对账清单批次
  15. };
  16. function subscriptionLabel(contractNo: string): string {
  17. const sub = readSubscriptions().find((item) => item.contractNumber === contractNo);
  18. if (!sub) return "—";
  19. return sub.changeKind === "首次订阅" ? sub.planName : `${sub.planName} · ${sub.changeKind}`;
  20. }
  21. const stmt = (batch: string, entries: [string, BillingStatementRef["status"]][]): BillingStatementRef[] =>
  22. entries.map(([party, status]) => ({ no: batch, party, status }));
  23. export const contractBillingPeriods: Record<string, ContractBillingPeriod[]> = {
  24. "HT-CL-20260318": [
  25. {
  26. month: "2026-03", subscriptionId: "SUB-2026-002", subscription: subscriptionLabel("HT-CL-20260318"),
  27. daysText: "12 / 31 天(首末月折算)", std: 120, amount: 46.45, cost: 0, status: "已出账",
  28. statements: stmt("ST-202604-SH-01", [["联通", "已执行"], ["邹合", "已执行"], ["华东常规运维", "已执行"], ["沪东施工", "已执行"]]),
  29. },
  30. {
  31. month: "2026-04", subscriptionId: "SUB-2026-002", subscription: subscriptionLabel("HT-CL-20260318"),
  32. daysText: "30 / 30 天", std: 120, amount: 120, cost: 0, status: "已出账",
  33. statements: stmt("ST-202605-SH-01", [["联通", "已执行"], ["邹合", "已执行"], ["华东常规运维", "已执行"], ["沪东施工", "已执行"]]),
  34. },
  35. {
  36. month: "2026-09", subscriptionId: "SUB-2026-002", subscription: subscriptionLabel("HT-CL-20260318"),
  37. daysText: "30 / 30 天", std: 120, amount: 120, cost: 0, status: "已出账",
  38. statements: stmt("ST-202610-SH-01", [["联通", "已执行"], ["邹合", "已执行"], ["华东常规运维", "已执行"], ["沪东施工", "已执行"]]),
  39. },
  40. ],
  41. "HT-WM-20260601": [
  42. {
  43. month: "2026-09", subscriptionId: "SUB-2026-005", subscription: subscriptionLabel("HT-WM-20260601"),
  44. daysText: "30 / 30 天", std: 480, amount: 480, cost: 46, status: "已出账",
  45. statements: stmt("ST-202610-GD-02", [["移动", "已执行"]]),
  46. },
  47. ],
  48. "HT-WM-20260801": [
  49. {
  50. month: "2026-09", subscriptionId: "SUB-2026-006", subscription: subscriptionLabel("HT-WM-20260801"),
  51. daysText: "30 / 30 天", std: 160, amount: 160, cost: 26, status: "已出账",
  52. statements: stmt("ST-202610-GD-02", [["移动", "已执行"]]),
  53. },
  54. ],
  55. "HT-HL-20251001": [
  56. {
  57. month: "2026-09", subscription: subscriptionLabel("HT-HL-20251001"),
  58. daysText: "30 / 30 天", std: 160, amount: 160, cost: 50, status: "已出账",
  59. statements: stmt("ST-202610-SH-02", [["联通", "已执行"]]),
  60. },
  61. ],
  62. };
  63. export function contractBillingSummary(no: string) {
  64. const periods = contractBillingPeriods[no];
  65. if (!periods) return null;
  66. return {
  67. periods,
  68. receivable: periods.reduce((sum, row) => sum + row.amount, 0),
  69. billed: periods.filter((row) => row.status === "已出账").reduce((sum, row) => sum + row.amount, 0),
  70. abnormalCount: periods.filter((row) => row.status === "出账异常").length,
  71. };
  72. }