Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20d967a4a4 | ||
|
|
31fdc2e456 | ||
|
|
1d07812fa8 | ||
|
|
2fe06b74ae | ||
|
|
307f9ba76f | ||
|
|
020b556801 | ||
|
|
7938a274f2 | ||
|
|
dc0fb76f8f | ||
|
|
5a6a629597 | ||
|
|
5f215271af | ||
|
|
3b10a58d93 | ||
|
|
6d23711e6c | ||
|
|
f99917321b | ||
|
|
df517d4a68 | ||
|
|
a621ebc323 |
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。当前代码状态请看 `README.md`、`项目需求.md`、`最新进度.md` 和 `任务清单.md`。
|
||||||
|
|
||||||
# 项目交接说明
|
# 项目交接说明
|
||||||
|
|
||||||
更新时间:2026-08-06
|
更新时间:2026-08-06
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# 总账项目手册
|
||||||
|
|
||||||
|
最后核对:2026-08-23。核对依据是当前 `main` 最新代码(`5f21527`)、数据库迁移、接口、测试和近期提交记录。
|
||||||
|
|
||||||
|
这是接手本项目的第一站。阅读顺序如下:
|
||||||
|
|
||||||
|
1. [项目需求](项目需求.md):先知道系统要解决什么问题,以及哪些规则绝不能碰。
|
||||||
|
2. [最新进度](最新进度.md):再确认哪些能力已经真实完成,哪些仍未完成。
|
||||||
|
3. [任务清单](任务清单.md):最后挑选下一项工作,避免重复做已经完成的事。
|
||||||
|
4. 需要技术细节时,再查看 `decisions/` 中的技术决定和 `issues/` 中保留的历史任务规格。
|
||||||
|
|
||||||
|
## 维护规矩
|
||||||
|
|
||||||
|
- 每新增、开始、完成、取消一项任务,负责的智能体都要在同一次提交里更新 `最新进度.md` 和 `任务清单.md`。
|
||||||
|
- 新功能改变产品规则时,同时更新 `项目需求.md`;技术方案有变化时,补充 `decisions/` 的决定记录。
|
||||||
|
- 写进手册的“已完成”必须能在代码、测试或已合并提交中找到依据;只有计划、页面演示或口头讨论的内容,一律写为“未完成”。
|
||||||
|
- 不删除历史文档。旧内容与当前代码不一致时,在旧文件开头加“已过时,仅留档备查”提示,并在本目录写新版说明。
|
||||||
|
|
||||||
|
## 旧交接说明
|
||||||
|
|
||||||
|
`HANDOFF.md` 是 2026-08-06 的历史交接稿,已经不反映当前实现,保留仅作对照。当前事实以本手册三份正文为准。
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# 005 规范转账事件与双边归并技术决策
|
||||||
|
|
||||||
|
对应 Issue:B-43/B-83/B-114(`docs/issues/006-p1-canonical-transfer-matching.md`)。
|
||||||
|
|
||||||
|
## 分层模型
|
||||||
|
|
||||||
|
- 银行源行是不可变观察;匹配层从不修改 `source_rows`。
|
||||||
|
- 新增“不可变决定日志 + 可重建当前投影”的规范事件层:
|
||||||
|
- `transfer_match_decisions` 等证据表只增不改(UPDATE/DELETE 被触发器拒绝)。
|
||||||
|
- `current_transfer_decisions` 与 `transfer_observation_claims` 是可更新、可重建的
|
||||||
|
当前投影,`source_row_id` 主键保证一条观察不可能同时属于两个当前事件。
|
||||||
|
- B-44 余额计算只读 `eligible_intercompany_events` 视图,只含
|
||||||
|
`active + current + classification='intercompany'`,且单边事件必须
|
||||||
|
`locked = 1`(管理员按证据确认)才可计算;paired 事件不受锁定状态限制;
|
||||||
|
单边内部、待审、同公司调拨、外部事件全部排除。
|
||||||
|
|
||||||
|
## 已确认业务口径(B-114)
|
||||||
|
|
||||||
|
1. 单边流水即使双方公司都能由批准账号唯一确认,也先进入未决金额,不进入 B-44
|
||||||
|
已确认往来余额;只有完成双边归并(`intercompany` + `paired`)或管理员按证据确认
|
||||||
|
(`intercompany` + locked 单边)后才可计算。
|
||||||
|
2. 跨日事件经济日期取付款方 outgoing 银行入账时间,与导入顺序无关。
|
||||||
|
3. 自动窗口 v1:非空参考号相同且账号镜像 <= 3 自然日(M1);无参考号精确账号镜像
|
||||||
|
<= 1 自然日(M2);别名/个人映射镜像 <= 1 自然日且参考号或摘要相等(M3)。
|
||||||
|
超窗或同层多候选全部进入人工审核,禁止按行号、导入顺序或名字破平局。
|
||||||
|
4. 个人过账映射绑定具体账号、生效区间、允许方向和代表公司,必须管理员批准;
|
||||||
|
姓名只作辅助证据,不能单独定案。
|
||||||
|
|
||||||
|
## 参与方解析
|
||||||
|
|
||||||
|
- 本方:源行 `own_account` 精确命中生效期内已批准账户(`own_exact`);缺失时才用
|
||||||
|
上传时持久化的批准上传账户(`upload_account`),且必须与批次公司一致。冲突进入
|
||||||
|
审核,不以 `company_id` 或户名反推。
|
||||||
|
- 对方:严格按账号层解析——精确账号 -> 已审核账号别名 -> 已批准且在窗口内、方向
|
||||||
|
允许的个人过账映射;每层唯一最佳结果才继续。户名/户名别名只用于一致性/冲突证据,
|
||||||
|
冲突降级到审核。
|
||||||
|
- 方向:`expense > 0 且 income = 0` 为 outgoing;`income > 0 且 expense = 0` 为
|
||||||
|
incoming;双正/双零/负数/缺币种进入 `unresolved`。金额用 `Decimal` 精确相等,
|
||||||
|
不设手续费容差。
|
||||||
|
|
||||||
|
## 匹配与状态机
|
||||||
|
|
||||||
|
- 候选硬门槛:双方工作表 confirmed、方向相反、金额与币种相等、公司端点互为反向。
|
||||||
|
- M1/M2/M3 唯一候选自动 paired;R1(端点可确认但镜像/参考号证据不足)与 R2(同层
|
||||||
|
多候选)进入 `needs_review`;待审行不能被其他自动匹配抢占。
|
||||||
|
- 状态:`unresolved -> internal_single -> matched`、`needs_review -> matched |
|
||||||
|
same_company_transfer | external`;单边确认两端同公司立即为同公司调拨。
|
||||||
|
- 幂等:rule_version + 当前观察集合 + 证据未变时零写入;locked 人工决定自动重跑
|
||||||
|
跳过;纠错只能通过 `reverse`(`mode='reversal'` 新记录)+ 原因,之后允许重跑。
|
||||||
|
|
||||||
|
## 事务、并发与回滚
|
||||||
|
|
||||||
|
- “确认工作表 + 为新增确认行建立/更新事件 + audit”在同一个服务事务,任一失败整体
|
||||||
|
回滚,不存在 confirmed 但未匹配的半成品。
|
||||||
|
- 独立重跑使用 `BEGIN IMMEDIATE`,按 `source_row_id` 升序写,SQLite 30 秒 busy
|
||||||
|
timeout 保留;投影可从只增日志重建(`rebuild_current_projection`)。
|
||||||
|
- migration down 只用于测试/上线前回退;生产产生决定后默认保留 migration 5 与审计
|
||||||
|
数据,不执行破坏性 down。
|
||||||
|
|
||||||
|
## Decimal
|
||||||
|
|
||||||
|
金额全程以规范十进制字符串存储和比较,任何路径都不转 `float`;`100.0` 与 `100.00`
|
||||||
|
视为相等,`100.00` 与 `100.01` 不匹配。
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。该历史任务已落地;当前状态见 `../任务清单.md`。
|
||||||
|
|
||||||
# [P0] 仓库银行样本数据分级与脱敏治理
|
# [P0] 仓库银行样本数据分级与脱敏治理
|
||||||
|
|
||||||
## 背景
|
## 背景
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。该历史任务已落地;当前状态见 `../任务清单.md`。
|
||||||
|
|
||||||
# [P0] 持久化层与不可变银行导入基础
|
# [P0] 持久化层与不可变银行导入基础
|
||||||
|
|
||||||
## 背景
|
## 背景
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。该历史任务已落地;当前状态见 `../任务清单.md`。
|
||||||
|
|
||||||
# [P0] 正式认证、RBAC 与公司级数据隔离
|
# [P0] 正式认证、RBAC 与公司级数据隔离
|
||||||
|
|
||||||
## 背景
|
## 背景
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。该历史任务已落地;当前状态见 `../任务清单.md`。
|
||||||
|
|
||||||
# [P1] 动态公司、用户、账户和别名主数据
|
# [P1] 动态公司、用户、账户和别名主数据
|
||||||
|
|
||||||
## 背景
|
## 背景
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。该历史任务已落地;当前状态见 `../任务清单.md`。
|
||||||
|
|
||||||
# [P1] 银行导入 API 加固与回归测试
|
# [P1] 银行导入 API 加固与回归测试
|
||||||
|
|
||||||
## 背景
|
## 背景
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
⚠️ 本文档已过时,仅留档备查,请勿删除。该历史任务已落地;当前状态见 `../任务清单.md`。
|
||||||
|
|
||||||
# [P1] 规范转账事件、双边匹配与调拨排除
|
# [P1] 规范转账事件、双边匹配与调拨排除
|
||||||
|
|
||||||
## 背景
|
## 背景
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# 任务清单
|
||||||
|
|
||||||
|
最后核对:2026-08-23。状态以当前代码和已合并提交为准。
|
||||||
|
|
||||||
|
## 正在做
|
||||||
|
|
||||||
|
- 当前没有已确认正在进行的业务功能开发。下一项工作开始前,先在此处写明负责人、范围和验收标准。
|
||||||
|
|
||||||
|
## 已做完
|
||||||
|
|
||||||
|
- 六类银行流水模板识别与解析。
|
||||||
|
- 数据库迁移、不可变原始证据、导入批次和重复导入处理。
|
||||||
|
- 管理员/公司用户登录、密码策略、会话、限流、服务端公司隔离和审计。
|
||||||
|
- 动态公司、用户、银行账户、别名与账户审核流程。
|
||||||
|
- 导入接口加固、逐工作表确认、失败诊断和导出。
|
||||||
|
- 规范转账事件、双边匹配、同公司调拨排除与个人过账映射。
|
||||||
|
- 登录页视觉融合改版。
|
||||||
|
|
||||||
|
## 还没安排
|
||||||
|
|
||||||
|
- 公司间余额和四类往来科目的正式计算,已批准手工记录入账,以及从余额逐层查回原始流水。
|
||||||
|
- 起算日、期初余额、流水覆盖断档检测和无业务校准。
|
||||||
|
- 月结、重开、调整/冲销审批与审计报告。
|
||||||
|
- 服务端流水查询、筛选、分页和可追溯导出。
|
||||||
|
- 站内提醒与状态流转;外部通知只预留扩展位置,不默认启用。
|
||||||
|
- 前端全面接入真实接口,移除模拟金额、静态业务记录和 `localStorage` 业务状态。
|
||||||
|
- 测试环境之外的运行保障,包括 HTTPS、备份、监控和正式部署方案。
|
||||||
|
|
||||||
|
每完成或新增一项任务,必须在同一次提交里把它从本清单的相应栏目移走或补上,并同步更新 `最新进度.md`。
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# 最新进度
|
||||||
|
|
||||||
|
最后核对:2026-08-23。以下“已完成”均以当前代码、数据库迁移、接口和自动化测试为依据,不把页面演示当作真实功能。
|
||||||
|
|
||||||
|
## 已经真实完成
|
||||||
|
|
||||||
|
- 支持中信、农行、工行、建行、河南农商行、郑州银行六类样本的 `.xls` / `.xlsx` 流水解析;能识别变动的表头位置和列顺序,并校验余额连续性。
|
||||||
|
- 已有 SQLite 数据库和 5 次版本迁移。原始文件按内容哈希保存,导入批次、工作表、源行和异常都有记录;原始文件、工作表和源行被数据库规则保护,不能直接改或删。
|
||||||
|
- 已实现管理员与公司用户登录、首次改密、会话失效、登录失败限流、服务端权限隔离和审计记录。
|
||||||
|
- 已实现公司、用户、银行账户、别名等主数据管理;公司提交的银行账户需管理员审核后才能参与上传和识别。
|
||||||
|
- 已实现导入、逐工作表确认或忽略、失败诊断、重复上传处理和 CSV 导出;未确认的工作表不进入后续处理。
|
||||||
|
- 已实现规范转账事件和双边流水匹配。匹配决定保留历史,无法自动判断的记录进入人工审核;同公司调拨、外部流水和未锁定的单边记录不进入已确认的公司间往来。
|
||||||
|
- 已有登录页、总账端和公司端页面,最近一次合并完成了登录页视觉改版。
|
||||||
|
|
||||||
|
## 仍未完成或不能当成已完成
|
||||||
|
|
||||||
|
- 公司间余额与会计科目的正式计算、已批准手工记录入账和逐层余额追溯尚未完成。
|
||||||
|
- 全局起算日、期初余额、流水覆盖断档、无业务校准、月结、重开和调整审批尚未完成。
|
||||||
|
- 提醒、完整的服务端查询导出,以及前端彻底移除演示数据和浏览器本地业务状态尚未完成。
|
||||||
|
- 生产部署所需的 HTTPS、反向代理、备份、监控和正式运行保障尚未完成;本项目当前只允许测试环境部署。
|
||||||
|
|
||||||
|
## 最近验证
|
||||||
|
|
||||||
|
2026-08-23 已运行完整 Python 自动化测试:解析、持久化、认证与权限、导入接口、主数据和双边匹配相关测试均通过。后续修改功能时,必须再次运行完整测试并在本文件记录结果。
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# 项目需求
|
||||||
|
|
||||||
|
## 这个系统做什么
|
||||||
|
|
||||||
|
这是河南金牛实业集团有限公司内部各公司之间的资金往来管理系统。它把各公司的银行流水集中起来,识别同一笔公司间转账的两边记录,形成可以一路查回原始银行流水的往来结果。
|
||||||
|
|
||||||
|
系统有两个独立入口:
|
||||||
|
|
||||||
|
- 总账管理端:管理公司、公司账号、银行账户、导入记录、异常和公司间转账匹配。
|
||||||
|
- 公司出纳端:只处理本公司的账户登记、流水上传、工作表确认和本公司相关异常。
|
||||||
|
|
||||||
|
## 必须做到的业务规则
|
||||||
|
|
||||||
|
- 银行原始文件和原始流水是证据,导入后不能直接修改或删除;修正必须通过可追溯的审核决定、冲销或调整完成。
|
||||||
|
- 一笔公司间转账的收、付两边只能算作一个经济事件,不能因为有两条银行流水就重复计算。
|
||||||
|
- 同一家公司不同银行账户之间调拨,不计入公司间往来。
|
||||||
|
- 账号、金额、方向、日期和余额等可核对信息优先于户名;信息不完整或有歧义时进入异常审核,不能猜。
|
||||||
|
- 已确认金额和待确认金额必须分开;所有余额都要说明统计截止日期和未决金额。
|
||||||
|
- 公司用户只能查看、上传和导出本公司的数据。这个限制由服务端执行,页面上“看不见”不等于有权限限制。
|
||||||
|
- 起算日前的流水必须保留,但不参与期内计算;期初余额、流水覆盖断档、无业务校准、月结和调整都要留痕。
|
||||||
|
|
||||||
|
## 当前技术边界
|
||||||
|
|
||||||
|
项目使用 Python 标准库服务、SQLite 数据库和浏览器页面。银行模板支持 `.xls` 与 `.xlsx`,按表头识别而非依赖固定行列。金额使用精确十进制,真实运行数据放在 `data/`,不进入代码仓库。
|
||||||
|
|
||||||
|
系统目前仍是测试环境项目,不能当作已完成生产部署:正式上线前仍需补齐核算、期初与断档、月结、备份、监控和 HTTPS 等能力。
|
||||||
@@ -10,7 +10,7 @@ from http.cookies import SimpleCookie
|
|||||||
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
||||||
from urllib.parse import parse_qs, urlparse
|
from urllib.parse import parse_qs, urlparse
|
||||||
|
|
||||||
from bank_importer import auth, importing, master_data, multipart
|
from bank_importer import auth, importing, master_data, matching, multipart, personal_transit
|
||||||
from bank_importer.db import connect, migrate, utc_now
|
from bank_importer.db import connect, migrate, utc_now
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +77,29 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
if path == "/api/admin/audit-log":
|
if path == "/api/admin/audit-log":
|
||||||
self._handle_admin_audit_log(query)
|
self._handle_admin_audit_log(query)
|
||||||
return
|
return
|
||||||
|
if path == "/api/admin/transfer-events":
|
||||||
|
self._handle_admin_transfer_events(query)
|
||||||
|
return
|
||||||
|
if path == "/api/admin/match-exceptions":
|
||||||
|
self._handle_admin_match_exceptions(query)
|
||||||
|
return
|
||||||
|
if path == "/api/admin/personal-transit-mappings":
|
||||||
|
self._handle_admin_personal_mappings(query)
|
||||||
|
return
|
||||||
|
event_match = re.fullmatch(r"/api/admin/transfer-events/(\d+)", path)
|
||||||
|
if event_match:
|
||||||
|
self._handle_admin_transfer_event_detail(int(event_match.group(1)))
|
||||||
|
return
|
||||||
|
if path == "/api/company/transfer-events":
|
||||||
|
self._handle_company_transfer_events(query)
|
||||||
|
return
|
||||||
|
if path == "/api/company/match-exceptions":
|
||||||
|
self._handle_company_match_exceptions(query)
|
||||||
|
return
|
||||||
|
company_event_match = re.fullmatch(r"/api/company/transfer-events/(\d+)", path)
|
||||||
|
if company_event_match:
|
||||||
|
self._handle_company_transfer_event_detail(int(company_event_match.group(1)))
|
||||||
|
return
|
||||||
|
|
||||||
if path == "/admin.html" and not self._guard_page("admin"):
|
if path == "/admin.html" and not self._guard_page("admin"):
|
||||||
return
|
return
|
||||||
@@ -130,6 +153,20 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
if ignore_match:
|
if ignore_match:
|
||||||
self._handle_batch_review(int(ignore_match.group(1)), "ignore")
|
self._handle_batch_review(int(ignore_match.group(1)), "ignore")
|
||||||
return
|
return
|
||||||
|
if path == "/api/admin/transfer-events/reconcile":
|
||||||
|
self._handle_admin_reconcile()
|
||||||
|
return
|
||||||
|
if path == "/api/admin/personal-transit-mappings":
|
||||||
|
self._handle_admin_create_personal_mapping()
|
||||||
|
return
|
||||||
|
decision_match = re.fullmatch(r"/api/admin/transfer-events/(\d+)/decisions", path)
|
||||||
|
if decision_match:
|
||||||
|
self._handle_admin_transfer_decision(int(decision_match.group(1)))
|
||||||
|
return
|
||||||
|
mapping_review = re.fullmatch(r"/api/admin/personal-transit-mappings/(\d+)/review", path)
|
||||||
|
if mapping_review:
|
||||||
|
self._handle_admin_review_personal_mapping(int(mapping_review.group(1)))
|
||||||
|
return
|
||||||
self._send_json(404, {"status": "error", "message": "接口不存在。"})
|
self._send_json(404, {"status": "error", "message": "接口不存在。"})
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@@ -339,7 +376,10 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
# Tenant binding comes from the session only; any
|
# Tenant binding comes from the session only; any
|
||||||
# company_id in the multipart body is ignored.
|
# company_id in the multipart body is ignored.
|
||||||
company_id = user["company_id"]
|
company_id = user["company_id"]
|
||||||
if not self._validate_upload_account(connection, user, fields):
|
upload_account_id, invalid = self._resolve_upload_account(
|
||||||
|
connection, user, fields, company_id
|
||||||
|
)
|
||||||
|
if invalid:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
company_id = self._parse_company_field(
|
company_id = self._parse_company_field(
|
||||||
@@ -347,10 +387,16 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
)
|
)
|
||||||
if company_id is None:
|
if company_id is None:
|
||||||
return
|
return
|
||||||
|
upload_account_id, invalid = self._resolve_upload_account(
|
||||||
|
connection, user, fields, company_id
|
||||||
|
)
|
||||||
|
if invalid:
|
||||||
|
return
|
||||||
|
|
||||||
result = importing.import_statement_path(
|
result = importing.import_statement_path(
|
||||||
connection, STORAGE_DIR, filename, upload.path,
|
connection, STORAGE_DIR, filename, upload.path,
|
||||||
company_id=company_id,
|
company_id=company_id,
|
||||||
|
upload_bank_account_id=upload_account_id,
|
||||||
)
|
)
|
||||||
auth.audit(
|
auth.audit(
|
||||||
connection,
|
connection,
|
||||||
@@ -410,32 +456,33 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
raise ValueError(str(exc)) from exc
|
raise ValueError(str(exc)) from exc
|
||||||
return fields, upload
|
return fields, upload
|
||||||
|
|
||||||
def _validate_upload_account(self, connection, user, fields) -> bool:
|
def _resolve_upload_account(self, connection, user, fields, company_id) -> tuple[int | None, bool]:
|
||||||
"""Validate the optional bank_account_id on a company upload.
|
"""Validate and return the approved upload account for a batch.
|
||||||
|
|
||||||
When supplied, the account must belong to the session company and be
|
Returns ``(account_id, False)`` when the account is accepted or when
|
||||||
enabled inside its effective interval — pending, returned or disabled
|
none was supplied, and ``(None, True)`` after sending the rejection.
|
||||||
accounts never accept uploads.
|
The approved account is persisted on the batch so ownership can be
|
||||||
|
resolved later even when source rows lack an own account.
|
||||||
"""
|
"""
|
||||||
raw = fields.get("bank_account_id")
|
raw = fields.get("bank_account_id")
|
||||||
if not raw:
|
if not raw:
|
||||||
return True
|
return None, False
|
||||||
try:
|
try:
|
||||||
account_id = int(raw)
|
account_id = int(raw)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._send_json(400, {"status": "error", "message": "bank_account_id 参数无效。"})
|
self._send_json(400, {"status": "error", "message": "bank_account_id 参数无效。"})
|
||||||
return False
|
return None, True
|
||||||
account = master_data.get_account(connection, account_id)
|
account = master_data.get_account(connection, account_id)
|
||||||
if account is None or account["company_id"] != user["company_id"]:
|
if account is None or account["company_id"] != company_id:
|
||||||
self._send_json(404, {"status": "error", "message": "账户不存在。"})
|
self._send_json(404, {"status": "error", "message": "账户不存在。"})
|
||||||
return False
|
return None, True
|
||||||
if not master_data.is_usable(account, master_data.utc_today()):
|
if not master_data.is_usable(account, master_data.utc_today()):
|
||||||
self._send_json(
|
self._send_json(
|
||||||
409,
|
409,
|
||||||
{"status": "error", "message": "该账户未启用或已超出有效期,不能上传流水。"},
|
{"status": "error", "message": "该账户未启用或已超出有效期,不能上传流水。"},
|
||||||
)
|
)
|
||||||
return False
|
return None, True
|
||||||
return True
|
return account_id, False
|
||||||
|
|
||||||
def _parse_company_field(self, connection, raw) -> int | None:
|
def _parse_company_field(self, connection, raw) -> int | None:
|
||||||
try:
|
try:
|
||||||
@@ -600,16 +647,24 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
self._send_json(400, {"status": "error", "message": str(exc)})
|
self._send_json(400, {"status": "error", "message": str(exc)})
|
||||||
return
|
return
|
||||||
|
except Exception:
|
||||||
|
# Confirmation and matching share one transaction; any failure
|
||||||
|
# rolls both back (the sheet stays pending).
|
||||||
|
self._send_json(
|
||||||
|
500,
|
||||||
|
{"status": "error", "message": "确认失败,本次确认与匹配已整体回滚。"},
|
||||||
|
)
|
||||||
|
return
|
||||||
rows = importing.sheet_review_rows(connection, batch_id)
|
rows = importing.sheet_review_rows(connection, batch_id)
|
||||||
self._send_json(
|
payload: dict[str, object] = {
|
||||||
200,
|
"status": "ok",
|
||||||
{
|
"updated": outcome["updated"],
|
||||||
"status": "ok",
|
"already": outcome["already"],
|
||||||
"updated": outcome["updated"],
|
"sheets": [self._sheet_payload(row) for row in rows],
|
||||||
"already": outcome["already"],
|
}
|
||||||
"sheets": [self._sheet_payload(row) for row in rows],
|
if outcome.get("matching") is not None:
|
||||||
},
|
payload["matching"] = outcome["matching"]
|
||||||
)
|
self._send_json(200, payload)
|
||||||
finally:
|
finally:
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
@@ -1261,6 +1316,664 @@ class AppHandler(SimpleHTTPRequestHandler):
|
|||||||
finally:
|
finally:
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Canonical transfer events (admin)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _event_base_sql(company_scope: bool) -> str:
|
||||||
|
"""Shared list SELECT; ``company_scope`` filters to one company."""
|
||||||
|
where = (
|
||||||
|
"WHERE payer.company_id = ? OR payee.company_id = ?"
|
||||||
|
if company_scope
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
return f"""
|
||||||
|
SELECT c.event_id, d.id AS decision_id, d.revision, d.classification,
|
||||||
|
d.pairing, d.amount, d.currency, d.effective_at, d.mode,
|
||||||
|
d.locked, d.rule_version, d.created_at,
|
||||||
|
payer.company_id AS payer_company_id,
|
||||||
|
payee.company_id AS payee_company_id,
|
||||||
|
payer.bank_account_id AS payer_account_id,
|
||||||
|
payee.bank_account_id AS payee_account_id,
|
||||||
|
cpayer.name AS payer_company_name,
|
||||||
|
cpayee.name AS payee_company_name,
|
||||||
|
(SELECT COUNT(*) FROM transfer_decision_observations o
|
||||||
|
WHERE o.decision_id = d.id) AS evidence_count
|
||||||
|
FROM current_transfer_decisions c
|
||||||
|
JOIN transfer_match_decisions d ON d.id = c.decision_id
|
||||||
|
LEFT JOIN transfer_decision_participants payer
|
||||||
|
ON payer.decision_id = d.id AND payer.role = 'payer'
|
||||||
|
LEFT JOIN transfer_decision_participants payee
|
||||||
|
ON payee.decision_id = d.id AND payee.role = 'payee'
|
||||||
|
LEFT JOIN companies cpayer ON cpayer.id = payer.company_id
|
||||||
|
LEFT JOIN companies cpayee ON cpayee.id = payee.company_id
|
||||||
|
{where}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _handle_admin_transfer_events(self, query: dict[str, list[str]]) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
conditions: list[str] = []
|
||||||
|
params: list[object] = []
|
||||||
|
raw_company = (query.get("company_id") or [None])[0]
|
||||||
|
if raw_company:
|
||||||
|
try:
|
||||||
|
params.append(int(raw_company))
|
||||||
|
params.append(int(raw_company))
|
||||||
|
except ValueError:
|
||||||
|
self._send_json(400, {"status": "error", "message": "company_id 参数无效。"})
|
||||||
|
return
|
||||||
|
conditions.append("(payer.company_id = ? OR payee.company_id = ?)")
|
||||||
|
raw_from = (query.get("from") or [None])[0]
|
||||||
|
if raw_from:
|
||||||
|
conditions.append("d.effective_at >= ?")
|
||||||
|
params.append(raw_from)
|
||||||
|
raw_to = (query.get("to") or [None])[0]
|
||||||
|
if raw_to:
|
||||||
|
conditions.append("d.effective_at <= ?")
|
||||||
|
params.append(raw_to)
|
||||||
|
raw_limit = (query.get("limit") or ["200"])[0]
|
||||||
|
try:
|
||||||
|
limit = max(1, min(int(raw_limit), 500))
|
||||||
|
except ValueError:
|
||||||
|
limit = 200
|
||||||
|
where = f"WHERE {' AND '.join(conditions)}" if conditions else ""
|
||||||
|
rows = connection.execute(
|
||||||
|
self._event_base_sql(False) + where + " ORDER BY d.id DESC LIMIT ?",
|
||||||
|
(*params, limit),
|
||||||
|
).fetchall()
|
||||||
|
items = [self._admin_event_list_item(row) for row in rows]
|
||||||
|
status = (query.get("status") or [None])[0]
|
||||||
|
if status:
|
||||||
|
items = [item for item in items if item["status"] == status]
|
||||||
|
self._send_json(200, {"status": "ok", "events": items})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _admin_event_list_item(row) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"event_id": row["event_id"],
|
||||||
|
"decision_id": row["decision_id"],
|
||||||
|
"revision": row["revision"],
|
||||||
|
"classification": row["classification"],
|
||||||
|
"pairing": row["pairing"],
|
||||||
|
"status": matching.exposed_status(row),
|
||||||
|
"amount": row["amount"],
|
||||||
|
"currency": row["currency"],
|
||||||
|
"effective_at": row["effective_at"],
|
||||||
|
"mode": row["mode"],
|
||||||
|
"locked": bool(row["locked"]),
|
||||||
|
"rule_version": row["rule_version"],
|
||||||
|
"payer_company_id": row["payer_company_id"],
|
||||||
|
"payer_company_name": row["payer_company_name"],
|
||||||
|
"payee_company_id": row["payee_company_id"],
|
||||||
|
"payee_company_name": row["payee_company_name"],
|
||||||
|
"evidence_count": row["evidence_count"],
|
||||||
|
"created_at": row["created_at"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def _handle_admin_transfer_event_detail(self, event_id: int) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
payload = self._admin_event_detail(connection, event_id)
|
||||||
|
if payload is None:
|
||||||
|
self._send_json(404, {"status": "error", "message": "事件不存在。"})
|
||||||
|
return
|
||||||
|
self._send_json(200, {"status": "ok", "event": payload})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _admin_event_detail(self, connection, event_id: int) -> dict[str, object] | None:
|
||||||
|
current = matching._current_decision_for_event(connection, event_id)
|
||||||
|
if current is None:
|
||||||
|
return None
|
||||||
|
decisions = connection.execute(
|
||||||
|
"SELECT * FROM transfer_match_decisions WHERE event_id = ? ORDER BY revision",
|
||||||
|
(event_id,),
|
||||||
|
).fetchall()
|
||||||
|
participants = matching._decision_participants(connection, current["id"])
|
||||||
|
observations = matching._decision_observations(connection, current["id"])
|
||||||
|
candidates = connection.execute(
|
||||||
|
"SELECT * FROM transfer_match_candidates WHERE decision_id = ? ORDER BY id",
|
||||||
|
(current["id"],),
|
||||||
|
).fetchall()
|
||||||
|
observation_rows = []
|
||||||
|
for observation in observations:
|
||||||
|
row = connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT r.id, r.source_row, r.transaction_at, r.income, r.expense,
|
||||||
|
r.own_account, r.own_name, r.counterparty_account,
|
||||||
|
r.counterparty_name, r.summary, r.reference, r.currency,
|
||||||
|
s.sheet_name, f.original_filename,
|
||||||
|
b.company_id AS batch_company_id
|
||||||
|
FROM source_rows r
|
||||||
|
JOIN sheet_batches s ON s.id = r.sheet_batch_id
|
||||||
|
JOIN import_batches b ON b.id = s.import_batch_id
|
||||||
|
JOIN source_files f ON f.id = b.source_file_id
|
||||||
|
WHERE r.id = ?
|
||||||
|
""",
|
||||||
|
(observation["source_row_id"],),
|
||||||
|
).fetchone()
|
||||||
|
observation_rows.append(
|
||||||
|
{
|
||||||
|
"source_row_id": observation["source_row_id"],
|
||||||
|
"role": observation["role"],
|
||||||
|
"source_row": row["source_row"] if row else None,
|
||||||
|
"sheet_name": row["sheet_name"] if row else None,
|
||||||
|
"original_filename": row["original_filename"] if row else None,
|
||||||
|
"company_id": row["batch_company_id"] if row else None,
|
||||||
|
"transaction_at": row["transaction_at"] if row else None,
|
||||||
|
"income": row["income"] if row else None,
|
||||||
|
"expense": row["expense"] if row else None,
|
||||||
|
"counterparty_name": row["counterparty_name"] if row else None,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
history = [
|
||||||
|
{
|
||||||
|
"decision_id": decision["id"],
|
||||||
|
"revision": decision["revision"],
|
||||||
|
"classification": decision["classification"],
|
||||||
|
"pairing": decision["pairing"],
|
||||||
|
"status": matching.exposed_status(decision),
|
||||||
|
"amount": decision["amount"],
|
||||||
|
"currency": decision["currency"],
|
||||||
|
"effective_at": decision["effective_at"],
|
||||||
|
"mode": decision["mode"],
|
||||||
|
"locked": bool(decision["locked"]),
|
||||||
|
"rule_version": decision["rule_version"],
|
||||||
|
"reason": decision["reason"],
|
||||||
|
"actor_username": decision["actor_username"],
|
||||||
|
"supersedes_decision_id": decision["supersedes_decision_id"],
|
||||||
|
"created_at": decision["created_at"],
|
||||||
|
}
|
||||||
|
for decision in decisions
|
||||||
|
]
|
||||||
|
return {
|
||||||
|
"event_id": event_id,
|
||||||
|
"decision_id": current["id"],
|
||||||
|
"revision": current["revision"],
|
||||||
|
"classification": current["classification"],
|
||||||
|
"pairing": current["pairing"],
|
||||||
|
"status": matching.exposed_status(current),
|
||||||
|
"amount": current["amount"],
|
||||||
|
"currency": current["currency"],
|
||||||
|
"effective_at": current["effective_at"],
|
||||||
|
"mode": current["mode"],
|
||||||
|
"locked": bool(current["locked"]),
|
||||||
|
"rule_version": current["rule_version"],
|
||||||
|
"participants": [
|
||||||
|
{
|
||||||
|
"role": participant["role"],
|
||||||
|
"company_id": participant["company_id"],
|
||||||
|
"bank_account_id": participant["bank_account_id"],
|
||||||
|
"resolve_method": participant["resolve_method"],
|
||||||
|
"evidence": json.loads(participant["evidence"])
|
||||||
|
if participant["evidence"]
|
||||||
|
else None,
|
||||||
|
}
|
||||||
|
for participant in participants
|
||||||
|
],
|
||||||
|
"observations": observation_rows,
|
||||||
|
"candidates": [
|
||||||
|
{
|
||||||
|
"source_row_id": candidate["source_row_id"],
|
||||||
|
"rule_tier": candidate["rule_tier"],
|
||||||
|
"date_diff_days": candidate["date_diff_days"],
|
||||||
|
"account_mirror": bool(candidate["account_mirror"]),
|
||||||
|
"reference_match": candidate["reference_match"],
|
||||||
|
"summary_match": bool(candidate["summary_match"]),
|
||||||
|
"accepted": candidate["accepted"],
|
||||||
|
"reason": candidate["reason"],
|
||||||
|
}
|
||||||
|
for candidate in candidates
|
||||||
|
],
|
||||||
|
"history": history,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _handle_admin_match_exceptions(self, query: dict[str, list[str]]) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
conditions = ["d.classification IN ('unresolved', 'needs_review')"]
|
||||||
|
params: list[object] = []
|
||||||
|
raw_company = (query.get("company_id") or [None])[0]
|
||||||
|
if raw_company:
|
||||||
|
try:
|
||||||
|
company_id = int(raw_company)
|
||||||
|
except ValueError:
|
||||||
|
self._send_json(400, {"status": "error", "message": "company_id 参数无效。"})
|
||||||
|
return
|
||||||
|
conditions.append("(payer.company_id = ? OR payee.company_id = ?)")
|
||||||
|
params.extend([company_id, company_id])
|
||||||
|
rows = connection.execute(
|
||||||
|
self._event_base_sql(False)
|
||||||
|
+ f"WHERE {' AND '.join(conditions)} ORDER BY d.id DESC LIMIT 500",
|
||||||
|
params,
|
||||||
|
).fetchall()
|
||||||
|
items = [self._admin_event_list_item(row) for row in rows]
|
||||||
|
self._send_json(200, {"status": "ok", "exceptions": items})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _handle_admin_reconcile(self) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
data = self._read_json_body()
|
||||||
|
if data is None:
|
||||||
|
return
|
||||||
|
raw_rows = data.get("source_row_ids")
|
||||||
|
row_ids: list[int] = []
|
||||||
|
if raw_rows is not None:
|
||||||
|
if not isinstance(raw_rows, list):
|
||||||
|
self._send_json(400, {"status": "error", "message": "source_row_ids 必须是数组。"})
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
row_ids = [int(item) for item in raw_rows]
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._send_json(400, {"status": "error", "message": "source_row_ids 必须是整数数组。"})
|
||||||
|
return
|
||||||
|
raw_batch = data.get("batch_id")
|
||||||
|
if raw_batch is not None and not row_ids:
|
||||||
|
try:
|
||||||
|
batch_id = int(raw_batch)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._send_json(400, {"status": "error", "message": "batch_id 参数无效。"})
|
||||||
|
return
|
||||||
|
rows = connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT r.id FROM source_rows r
|
||||||
|
JOIN sheet_batches s ON s.id = r.sheet_batch_id
|
||||||
|
JOIN sheet_reviews rv ON rv.sheet_batch_id = s.id
|
||||||
|
WHERE s.import_batch_id = ? AND rv.review_status = 'confirmed'
|
||||||
|
ORDER BY r.id
|
||||||
|
""",
|
||||||
|
(batch_id,),
|
||||||
|
).fetchall()
|
||||||
|
row_ids = [item["id"] for item in rows]
|
||||||
|
if not row_ids:
|
||||||
|
self._send_json(400, {"status": "error", "message": "必须指定 source_row_ids 或 batch_id。"})
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
result = matching.reconcile_rows(connection, row_ids, actor=user)
|
||||||
|
except Exception as exc:
|
||||||
|
self._send_json(500, {"status": "error", "message": f"重跑匹配失败:{exc}"})
|
||||||
|
return
|
||||||
|
auth.audit(
|
||||||
|
connection, "transfer_reconcile", actor=user,
|
||||||
|
target=f"rows:{len(row_ids)}",
|
||||||
|
detail=f"created:{result['created_events']};updated:{result['updated_events']}",
|
||||||
|
ip=self._client_ip,
|
||||||
|
)
|
||||||
|
self._send_json(200, {"status": "ok", "matching": result})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _handle_admin_transfer_decision(self, event_id: int) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
data = self._read_json_body()
|
||||||
|
if data is None:
|
||||||
|
return
|
||||||
|
action = str(data.get("action") or "")
|
||||||
|
try:
|
||||||
|
expected_revision = (
|
||||||
|
int(data["expected_revision"])
|
||||||
|
if data.get("expected_revision") is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._send_json(400, {"status": "error", "message": "expected_revision 参数无效。"})
|
||||||
|
return
|
||||||
|
source_row_ids = data.get("source_row_ids")
|
||||||
|
if source_row_ids is not None and not isinstance(source_row_ids, list):
|
||||||
|
self._send_json(400, {"status": "error", "message": "source_row_ids 必须是数组。"})
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
payload = matching.apply_manual_decision(
|
||||||
|
connection,
|
||||||
|
event_id,
|
||||||
|
action,
|
||||||
|
reason=str(data.get("reason") or ""),
|
||||||
|
expected_revision=expected_revision,
|
||||||
|
request_key=str(data.get("request_key") or "") or None,
|
||||||
|
actor=user,
|
||||||
|
source_row_ids=[int(item) for item in source_row_ids]
|
||||||
|
if source_row_ids
|
||||||
|
else None,
|
||||||
|
participant=data.get("participant"),
|
||||||
|
)
|
||||||
|
except matching.MatchConflictError as exc:
|
||||||
|
self._send_json(409, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
except matching.MatchInputError as exc:
|
||||||
|
self._send_json(400, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
self._send_json(200, {"status": "ok", "decision": payload})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Personal transit mappings (admin)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _handle_admin_personal_mappings(self, query: dict[str, list[str]]) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
raw_company = (query.get("company_id") or [None])[0]
|
||||||
|
raw_status = (query.get("status") or [None])[0]
|
||||||
|
try:
|
||||||
|
company_id = int(raw_company) if raw_company else None
|
||||||
|
except ValueError:
|
||||||
|
self._send_json(400, {"status": "error", "message": "company_id 参数无效。"})
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
rows = personal_transit.list_mappings(
|
||||||
|
connection, company_id=company_id, status=raw_status or None
|
||||||
|
)
|
||||||
|
except ValueError as exc:
|
||||||
|
self._send_json(400, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
self._send_json(
|
||||||
|
200,
|
||||||
|
{"status": "ok",
|
||||||
|
"mappings": [personal_transit.mapping_payload(row, full=True) for row in rows]},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _handle_admin_create_personal_mapping(self) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
data = self._read_json_body()
|
||||||
|
if data is None:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
company_id = int(str(data.get("represented_company_id")))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._send_json(400, {"status": "error", "message": "represented_company_id 参数无效。"})
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
mapping = personal_transit.submit_mapping(
|
||||||
|
connection,
|
||||||
|
account_number=data.get("account_number"),
|
||||||
|
account_name=data.get("account_name"),
|
||||||
|
represented_company_id=company_id,
|
||||||
|
allowed_direction=str(data.get("allowed_direction") or ""),
|
||||||
|
effective_from=data.get("effective_from"),
|
||||||
|
actor=user,
|
||||||
|
)
|
||||||
|
except personal_transit.ConflictError as exc:
|
||||||
|
self._send_json(409, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
except ValueError as exc:
|
||||||
|
self._send_json(400, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
auth.audit(
|
||||||
|
connection, "personal_transit_submit", actor=user,
|
||||||
|
target=f"personal_transit:{mapping['id']}",
|
||||||
|
detail=f"company:{company_id}",
|
||||||
|
ip=self._client_ip,
|
||||||
|
)
|
||||||
|
self._send_json(
|
||||||
|
200,
|
||||||
|
{"status": "ok",
|
||||||
|
"mapping": personal_transit.mapping_payload(mapping, full=True)},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _handle_admin_review_personal_mapping(self, mapping_id: int) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_admin(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
data = self._read_json_body()
|
||||||
|
if data is None:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
mapping = personal_transit.review_mapping(
|
||||||
|
connection,
|
||||||
|
mapping_id,
|
||||||
|
str(data.get("decision") or ""),
|
||||||
|
str(data.get("reason") or ""),
|
||||||
|
user,
|
||||||
|
effective_from=data.get("effective_from"),
|
||||||
|
effective_to=data.get("effective_to"),
|
||||||
|
)
|
||||||
|
except LookupError as exc:
|
||||||
|
self._send_json(404, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
except personal_transit.ConflictError as exc:
|
||||||
|
self._send_json(409, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
except ValueError as exc:
|
||||||
|
self._send_json(400, {"status": "error", "message": str(exc)})
|
||||||
|
return
|
||||||
|
auth.audit(
|
||||||
|
connection, "personal_transit_review", actor=user,
|
||||||
|
target=f"personal_transit:{mapping_id}",
|
||||||
|
detail=str(data.get("decision")),
|
||||||
|
ip=self._client_ip,
|
||||||
|
)
|
||||||
|
self._send_json(
|
||||||
|
200,
|
||||||
|
{"status": "ok",
|
||||||
|
"mapping": personal_transit.mapping_payload(mapping, full=True)},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Canonical transfer events (company, own-company scope only)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _handle_company_transfer_events(self, query: dict[str, list[str]]) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_user(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
if user["role"] != "company":
|
||||||
|
self._send_json(403, {"status": "error", "message": "该操作仅限公司用户。"})
|
||||||
|
return
|
||||||
|
conditions = []
|
||||||
|
params: list[object] = [user["company_id"], user["company_id"]]
|
||||||
|
status = (query.get("status") or [None])[0]
|
||||||
|
raw_limit = (query.get("limit") or ["200"])[0]
|
||||||
|
try:
|
||||||
|
limit = max(1, min(int(raw_limit), 500))
|
||||||
|
except ValueError:
|
||||||
|
limit = 200
|
||||||
|
rows = connection.execute(
|
||||||
|
self._event_base_sql(True) + " ORDER BY d.id DESC LIMIT ?",
|
||||||
|
(*params, limit),
|
||||||
|
).fetchall()
|
||||||
|
items = [
|
||||||
|
self._company_event_list_item(row, user["company_id"]) for row in rows
|
||||||
|
]
|
||||||
|
if status:
|
||||||
|
items = [item for item in items if item["status"] == status]
|
||||||
|
self._send_json(200, {"status": "ok", "events": items})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _company_event_list_item(row, own_company_id: int) -> dict[str, object]:
|
||||||
|
counterparty_company_id = (
|
||||||
|
row["payee_company_id"]
|
||||||
|
if row["payer_company_id"] == own_company_id
|
||||||
|
else row["payer_company_id"]
|
||||||
|
)
|
||||||
|
counterparty_company_name = (
|
||||||
|
row["payee_company_name"]
|
||||||
|
if row["payer_company_id"] == own_company_id
|
||||||
|
else row["payer_company_name"]
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"event_id": row["event_id"],
|
||||||
|
"classification": row["classification"],
|
||||||
|
"pairing": row["pairing"],
|
||||||
|
"status": matching.exposed_status(row),
|
||||||
|
"amount": row["amount"],
|
||||||
|
"currency": row["currency"],
|
||||||
|
"effective_at": row["effective_at"],
|
||||||
|
"mode": row["mode"],
|
||||||
|
"rule_version": row["rule_version"],
|
||||||
|
"own_company_id": own_company_id,
|
||||||
|
"counterparty_company_id": counterparty_company_id,
|
||||||
|
"counterparty_company_name": counterparty_company_name,
|
||||||
|
"evidence_count": row["evidence_count"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def _handle_company_match_exceptions(self, query: dict[str, list[str]]) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_user(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
if user["role"] != "company":
|
||||||
|
self._send_json(403, {"status": "error", "message": "该操作仅限公司用户。"})
|
||||||
|
return
|
||||||
|
params: list[object] = [user["company_id"], user["company_id"]]
|
||||||
|
rows = connection.execute(
|
||||||
|
self._event_base_sql(True)
|
||||||
|
+ "AND d.classification IN ('unresolved', 'needs_review') "
|
||||||
|
"ORDER BY d.id DESC LIMIT 500",
|
||||||
|
params,
|
||||||
|
).fetchall()
|
||||||
|
items = [
|
||||||
|
self._company_event_list_item(row, user["company_id"]) for row in rows
|
||||||
|
]
|
||||||
|
self._send_json(200, {"status": "ok", "exceptions": items})
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _handle_company_transfer_event_detail(self, event_id: int) -> None:
|
||||||
|
connection = connect(DB_PATH)
|
||||||
|
try:
|
||||||
|
user = self._require_user(connection)
|
||||||
|
if user is None:
|
||||||
|
return
|
||||||
|
if user["role"] != "company":
|
||||||
|
self._send_json(403, {"status": "error", "message": "该操作仅限公司用户。"})
|
||||||
|
return
|
||||||
|
current = matching._current_decision_for_event(connection, event_id)
|
||||||
|
if current is None:
|
||||||
|
self._send_json(404, {"status": "error", "message": "事件不存在。"})
|
||||||
|
return
|
||||||
|
participants = matching._decision_participants(connection, current["id"])
|
||||||
|
participant_company_ids = {p["company_id"] for p in participants}
|
||||||
|
if user["company_id"] not in participant_company_ids:
|
||||||
|
self._send_json(404, {"status": "error", "message": "事件不存在。"})
|
||||||
|
return
|
||||||
|
observations = matching._decision_observations(connection, current["id"])
|
||||||
|
own_rows = self._company_observation_rows(connection, observations, user["company_id"])
|
||||||
|
other_side = next(
|
||||||
|
(
|
||||||
|
p for p in participants
|
||||||
|
if p["company_id"] != user["company_id"]
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
counterparty = None
|
||||||
|
if other_side is not None:
|
||||||
|
company = connection.execute(
|
||||||
|
"SELECT name FROM companies WHERE id = ?", (other_side["company_id"],)
|
||||||
|
).fetchone()
|
||||||
|
counterparty = {
|
||||||
|
"company_id": other_side["company_id"],
|
||||||
|
"company_name": company["name"] if company else None,
|
||||||
|
}
|
||||||
|
if other_side["bank_account_id"] is not None:
|
||||||
|
account = master_data.get_account(connection, other_side["bank_account_id"])
|
||||||
|
if account is not None:
|
||||||
|
counterparty["account_number_masked"] = master_data.mask_account_number(
|
||||||
|
account["account_number"]
|
||||||
|
)
|
||||||
|
self._send_json(
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"event": {
|
||||||
|
"event_id": event_id,
|
||||||
|
"classification": current["classification"],
|
||||||
|
"pairing": current["pairing"],
|
||||||
|
"status": matching.exposed_status(current),
|
||||||
|
"amount": current["amount"],
|
||||||
|
"currency": current["currency"],
|
||||||
|
"effective_at": current["effective_at"],
|
||||||
|
"mode": current["mode"],
|
||||||
|
"reason": current["reason"],
|
||||||
|
"counterparty": counterparty,
|
||||||
|
"observations": own_rows,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def _company_observation_rows(self, connection, observations, own_company_id: int) -> list[dict]:
|
||||||
|
rows = []
|
||||||
|
for observation in observations:
|
||||||
|
row = connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT r.id, r.source_row, r.transaction_at, r.income, r.expense,
|
||||||
|
r.own_account, r.own_name, r.counterparty_account,
|
||||||
|
r.counterparty_name, r.summary, r.reference,
|
||||||
|
s.sheet_name, b.company_id AS batch_company_id
|
||||||
|
FROM source_rows r
|
||||||
|
JOIN sheet_batches s ON s.id = r.sheet_batch_id
|
||||||
|
JOIN import_batches b ON b.id = s.import_batch_id
|
||||||
|
WHERE r.id = ?
|
||||||
|
""",
|
||||||
|
(observation["source_row_id"],),
|
||||||
|
).fetchone()
|
||||||
|
if row is None or row["batch_company_id"] != own_company_id:
|
||||||
|
continue
|
||||||
|
rows.append(
|
||||||
|
{
|
||||||
|
"source_row_id": row["id"],
|
||||||
|
"role": observation["role"],
|
||||||
|
"source_row": row["source_row"],
|
||||||
|
"sheet_name": row["sheet_name"],
|
||||||
|
"transaction_at": row["transaction_at"],
|
||||||
|
"income": row["income"],
|
||||||
|
"expense": row["expense"],
|
||||||
|
"batch_company_id": row["batch_company_id"],
|
||||||
|
"own_account_masked": master_data.mask_account_number(row["own_account"])
|
||||||
|
if row["own_account"]
|
||||||
|
else None,
|
||||||
|
"counterparty_name": row["counterparty_name"],
|
||||||
|
"summary": row["summary"],
|
||||||
|
"reference": row["reference"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Request/response plumbing
|
# Request/response plumbing
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -354,6 +354,221 @@ MIGRATIONS: tuple[Migration, ...] = (
|
|||||||
DROP TABLE IF EXISTS sheet_reviews;
|
DROP TABLE IF EXISTS sheet_reviews;
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
|
Migration(
|
||||||
|
version=5,
|
||||||
|
name="0005_canonical_transfer_matching",
|
||||||
|
# Canonical transfer event layer (B-43). Immutable source rows stay
|
||||||
|
# untouched; every matching decision, its participant/observation
|
||||||
|
# bindings and its candidate evidence are append-only history, and the
|
||||||
|
# current decision + row claims are a rebuildable projection that the
|
||||||
|
# B-44 balance layer reads through the eligible view.
|
||||||
|
up="""
|
||||||
|
ALTER TABLE import_batches ADD COLUMN upload_bank_account_id INTEGER REFERENCES bank_accounts (id);
|
||||||
|
|
||||||
|
CREATE TABLE master_data_changes_new (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
entity_type TEXT NOT NULL
|
||||||
|
CHECK (entity_type IN ('company', 'user', 'bank_account', 'account_alias', 'personal_transit_mapping')),
|
||||||
|
entity_id INTEGER NOT NULL,
|
||||||
|
action TEXT NOT NULL,
|
||||||
|
before_json TEXT,
|
||||||
|
after_json TEXT,
|
||||||
|
reason TEXT,
|
||||||
|
actor_user_id INTEGER REFERENCES users (id),
|
||||||
|
actor_username TEXT,
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
INSERT INTO master_data_changes_new SELECT * FROM master_data_changes;
|
||||||
|
DROP TABLE master_data_changes;
|
||||||
|
ALTER TABLE master_data_changes_new RENAME TO master_data_changes;
|
||||||
|
|
||||||
|
CREATE TABLE personal_transit_mappings (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
account_number TEXT NOT NULL UNIQUE,
|
||||||
|
account_name TEXT,
|
||||||
|
represented_company_id INTEGER NOT NULL REFERENCES companies (id),
|
||||||
|
allowed_direction TEXT NOT NULL
|
||||||
|
CHECK (allowed_direction IN ('outgoing', 'incoming', 'both')),
|
||||||
|
status TEXT NOT NULL DEFAULT 'pending'
|
||||||
|
CHECK (status IN ('pending', 'active', 'returned', 'disabled')),
|
||||||
|
effective_from TEXT,
|
||||||
|
effective_to TEXT,
|
||||||
|
submitted_by INTEGER REFERENCES users (id),
|
||||||
|
reviewed_by INTEGER REFERENCES users (id),
|
||||||
|
reviewed_at TEXT,
|
||||||
|
review_reason TEXT,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE canonical_transfer_events (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
lifecycle TEXT NOT NULL DEFAULT 'active'
|
||||||
|
CHECK (lifecycle IN ('active', 'superseded')),
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE transfer_match_decisions (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
event_id INTEGER NOT NULL REFERENCES canonical_transfer_events (id),
|
||||||
|
revision INTEGER NOT NULL,
|
||||||
|
classification TEXT NOT NULL CHECK (classification IN (
|
||||||
|
'unresolved', 'needs_review', 'internal_single',
|
||||||
|
'intercompany', 'same_company', 'external'
|
||||||
|
)),
|
||||||
|
pairing TEXT NOT NULL
|
||||||
|
CHECK (pairing IN ('single', 'paired', 'not_applicable')),
|
||||||
|
amount TEXT,
|
||||||
|
currency TEXT,
|
||||||
|
effective_at TEXT,
|
||||||
|
mode TEXT NOT NULL CHECK (mode IN ('auto', 'manual', 'reversal')),
|
||||||
|
rule_version TEXT,
|
||||||
|
locked INTEGER NOT NULL DEFAULT 0 CHECK (locked IN (0, 1)),
|
||||||
|
reason TEXT,
|
||||||
|
idempotency_key TEXT,
|
||||||
|
actor_user_id INTEGER REFERENCES users (id),
|
||||||
|
actor_username TEXT,
|
||||||
|
supersedes_decision_id INTEGER REFERENCES transfer_match_decisions (id),
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE (event_id, revision)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE transfer_decision_observations (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
decision_id INTEGER NOT NULL REFERENCES transfer_match_decisions (id),
|
||||||
|
source_row_id INTEGER NOT NULL REFERENCES source_rows (id),
|
||||||
|
role TEXT NOT NULL CHECK (role IN ('outgoing', 'incoming')),
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE (decision_id, source_row_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE transfer_decision_participants (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
decision_id INTEGER NOT NULL REFERENCES transfer_match_decisions (id),
|
||||||
|
role TEXT NOT NULL CHECK (role IN ('payer', 'payee')),
|
||||||
|
company_id INTEGER REFERENCES companies (id),
|
||||||
|
bank_account_id INTEGER REFERENCES bank_accounts (id),
|
||||||
|
resolve_method TEXT NOT NULL CHECK (resolve_method IN (
|
||||||
|
'own_exact', 'upload_account', 'counterparty_exact',
|
||||||
|
'account_alias', 'personal_mapping', 'manual'
|
||||||
|
)),
|
||||||
|
alias_id INTEGER REFERENCES account_aliases (id),
|
||||||
|
mapping_id INTEGER REFERENCES personal_transit_mappings (id),
|
||||||
|
evidence TEXT,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE (decision_id, role)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE transfer_match_candidates (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
decision_id INTEGER NOT NULL REFERENCES transfer_match_decisions (id),
|
||||||
|
source_row_id INTEGER NOT NULL REFERENCES source_rows (id),
|
||||||
|
rule_tier TEXT NOT NULL,
|
||||||
|
date_diff_days INTEGER,
|
||||||
|
account_mirror INTEGER NOT NULL DEFAULT 0,
|
||||||
|
reference_match TEXT,
|
||||||
|
summary_match INTEGER NOT NULL DEFAULT 0,
|
||||||
|
accepted INTEGER,
|
||||||
|
reason TEXT,
|
||||||
|
rule_version TEXT,
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE current_transfer_decisions (
|
||||||
|
event_id INTEGER PRIMARY KEY REFERENCES canonical_transfer_events (id),
|
||||||
|
decision_id INTEGER NOT NULL UNIQUE REFERENCES transfer_match_decisions (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE transfer_observation_claims (
|
||||||
|
source_row_id INTEGER PRIMARY KEY REFERENCES source_rows (id),
|
||||||
|
event_id INTEGER NOT NULL REFERENCES canonical_transfer_events (id),
|
||||||
|
decision_id INTEGER NOT NULL REFERENCES transfer_match_decisions (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_obs_decision ON transfer_decision_observations (decision_id);
|
||||||
|
CREATE INDEX idx_participants_decision ON transfer_decision_participants (decision_id);
|
||||||
|
CREATE INDEX idx_candidates_decision ON transfer_match_candidates (decision_id);
|
||||||
|
CREATE INDEX idx_claims_event ON transfer_observation_claims (event_id);
|
||||||
|
|
||||||
|
CREATE VIEW eligible_intercompany_events AS
|
||||||
|
SELECT e.id AS event_id, d.id AS decision_id, d.revision AS revision,
|
||||||
|
d.effective_at AS effective_at, d.amount AS amount, d.currency AS currency,
|
||||||
|
payer.company_id AS payer_company_id,
|
||||||
|
payer.bank_account_id AS payer_account_id,
|
||||||
|
payee.company_id AS payee_company_id,
|
||||||
|
payee.bank_account_id AS payee_account_id,
|
||||||
|
d.pairing AS pairing, d.rule_version AS rule_version,
|
||||||
|
(SELECT COUNT(*) FROM transfer_decision_observations o
|
||||||
|
WHERE o.decision_id = d.id) AS evidence_count
|
||||||
|
FROM current_transfer_decisions c
|
||||||
|
JOIN canonical_transfer_events e ON e.id = c.event_id
|
||||||
|
JOIN transfer_match_decisions d ON d.id = c.decision_id
|
||||||
|
JOIN transfer_decision_participants payer
|
||||||
|
ON payer.decision_id = d.id AND payer.role = 'payer'
|
||||||
|
JOIN transfer_decision_participants payee
|
||||||
|
ON payee.decision_id = d.id AND payee.role = 'payee'
|
||||||
|
WHERE e.lifecycle = 'active' AND d.classification = 'intercompany'
|
||||||
|
AND (d.pairing = 'paired' OR d.locked = 1);
|
||||||
|
|
||||||
|
CREATE TRIGGER canonical_transfer_events_no_delete BEFORE DELETE ON canonical_transfer_events
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'canonical_transfer_events rows are immutable'); END;
|
||||||
|
CREATE TRIGGER canonical_transfer_events_no_update BEFORE UPDATE ON canonical_transfer_events
|
||||||
|
BEGIN
|
||||||
|
SELECT RAISE (ABORT, 'canonical_transfer_events only allow lifecycle changes')
|
||||||
|
WHERE OLD.lifecycle = NEW.lifecycle
|
||||||
|
OR OLD.id IS NOT NEW.id
|
||||||
|
OR OLD.created_at IS NOT NEW.created_at;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CREATE TRIGGER transfer_match_decisions_no_update BEFORE UPDATE ON transfer_match_decisions
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_match_decisions rows are immutable'); END;
|
||||||
|
CREATE TRIGGER transfer_match_decisions_no_delete BEFORE DELETE ON transfer_match_decisions
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_match_decisions rows are immutable'); END;
|
||||||
|
|
||||||
|
CREATE TRIGGER transfer_decision_observations_no_update BEFORE UPDATE ON transfer_decision_observations
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_decision_observations rows are immutable'); END;
|
||||||
|
CREATE TRIGGER transfer_decision_observations_no_delete BEFORE DELETE ON transfer_decision_observations
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_decision_observations rows are immutable'); END;
|
||||||
|
|
||||||
|
CREATE TRIGGER transfer_decision_participants_no_update BEFORE UPDATE ON transfer_decision_participants
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_decision_participants rows are immutable'); END;
|
||||||
|
CREATE TRIGGER transfer_decision_participants_no_delete BEFORE DELETE ON transfer_decision_participants
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_decision_participants rows are immutable'); END;
|
||||||
|
|
||||||
|
CREATE TRIGGER transfer_match_candidates_no_update BEFORE UPDATE ON transfer_match_candidates
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_match_candidates rows are immutable'); END;
|
||||||
|
CREATE TRIGGER transfer_match_candidates_no_delete BEFORE DELETE ON transfer_match_candidates
|
||||||
|
BEGIN SELECT RAISE (ABORT, 'transfer_match_candidates rows are immutable'); END;
|
||||||
|
""",
|
||||||
|
down="""
|
||||||
|
DROP VIEW IF EXISTS eligible_intercompany_events;
|
||||||
|
DROP TABLE IF EXISTS transfer_observation_claims;
|
||||||
|
DROP TABLE IF EXISTS current_transfer_decisions;
|
||||||
|
DROP TABLE IF EXISTS transfer_match_candidates;
|
||||||
|
DROP TABLE IF EXISTS transfer_decision_participants;
|
||||||
|
DROP TABLE IF EXISTS transfer_decision_observations;
|
||||||
|
DROP TABLE IF EXISTS transfer_match_decisions;
|
||||||
|
DROP TABLE IF EXISTS canonical_transfer_events;
|
||||||
|
DROP TABLE IF EXISTS personal_transit_mappings;
|
||||||
|
CREATE TABLE master_data_changes_new (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
entity_type TEXT NOT NULL
|
||||||
|
CHECK (entity_type IN ('company', 'user', 'bank_account', 'account_alias')),
|
||||||
|
entity_id INTEGER NOT NULL,
|
||||||
|
action TEXT NOT NULL,
|
||||||
|
before_json TEXT,
|
||||||
|
after_json TEXT,
|
||||||
|
reason TEXT,
|
||||||
|
actor_user_id INTEGER REFERENCES users (id),
|
||||||
|
actor_username TEXT,
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
INSERT INTO master_data_changes_new SELECT * FROM master_data_changes;
|
||||||
|
DROP TABLE master_data_changes;
|
||||||
|
ALTER TABLE master_data_changes_new RENAME TO master_data_changes;
|
||||||
|
ALTER TABLE import_batches DROP COLUMN upload_bank_account_id;
|
||||||
|
""",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ import os
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from . import auth
|
from . import auth
|
||||||
|
from . import matching
|
||||||
from .db import utc_now
|
from .db import utc_now
|
||||||
from .models import SheetResult, StatementBatch
|
from .models import SheetResult, StatementBatch
|
||||||
from .parser import StatementParseError, analyze_workbook
|
from .parser import StatementParseError, analyze_workbook
|
||||||
@@ -52,6 +54,7 @@ def import_statement(
|
|||||||
original_filename: str,
|
original_filename: str,
|
||||||
content: bytes,
|
content: bytes,
|
||||||
company_id: int | None = None,
|
company_id: int | None = None,
|
||||||
|
upload_bank_account_id: int | None = None,
|
||||||
) -> ImportResult:
|
) -> ImportResult:
|
||||||
sha256 = hashlib.sha256(content).hexdigest()
|
sha256 = hashlib.sha256(content).hexdigest()
|
||||||
existing_file = connection.execute(
|
existing_file = connection.execute(
|
||||||
@@ -64,7 +67,8 @@ def import_statement(
|
|||||||
stored_path = _store_immutable(Path(storage_dir), original_filename, content, sha256)
|
stored_path = _store_immutable(Path(storage_dir), original_filename, content, sha256)
|
||||||
try:
|
try:
|
||||||
source_file_id, batch_id = _create_batch_records(
|
source_file_id, batch_id = _create_batch_records(
|
||||||
connection, sha256, original_filename, len(content), stored_path, company_id
|
connection, sha256, original_filename, len(content), stored_path,
|
||||||
|
company_id, upload_bank_account_id,
|
||||||
)
|
)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
# Lost a concurrent-insert race on the sha256 UNIQUE constraint: the
|
# Lost a concurrent-insert race on the sha256 UNIQUE constraint: the
|
||||||
@@ -87,13 +91,16 @@ def import_statement_path(
|
|||||||
original_filename: str,
|
original_filename: str,
|
||||||
upload_path: str | Path,
|
upload_path: str | Path,
|
||||||
company_id: int | None = None,
|
company_id: int | None = None,
|
||||||
|
upload_bank_account_id: int | None = None,
|
||||||
) -> ImportResult:
|
) -> ImportResult:
|
||||||
"""Import from an already-downloaded upload file (streaming-friendly).
|
"""Import from an already-downloaded upload file (streaming-friendly).
|
||||||
|
|
||||||
``upload_path`` names the temp file the multipart handler streamed to
|
``upload_path`` names the temp file the multipart handler streamed to
|
||||||
disk; it is hashed incrementally and either discarded (duplicate) or
|
disk; it is hashed incrementally and either discarded (duplicate) or
|
||||||
published into the content-addressed store. The upload file itself is
|
published into the content-addressed store. The upload file itself is
|
||||||
never modified.
|
never modified. The approved ``upload_bank_account_id`` used at upload time
|
||||||
|
is persisted on the batch so ownership can be resolved later even when the
|
||||||
|
source rows carry no own account.
|
||||||
"""
|
"""
|
||||||
source = Path(upload_path)
|
source = Path(upload_path)
|
||||||
sha256 = _file_sha256(source)
|
sha256 = _file_sha256(source)
|
||||||
@@ -109,7 +116,8 @@ def import_statement_path(
|
|||||||
size = stored_path.stat().st_size
|
size = stored_path.stat().st_size
|
||||||
try:
|
try:
|
||||||
source_file_id, batch_id = _create_batch_records(
|
source_file_id, batch_id = _create_batch_records(
|
||||||
connection, sha256, original_filename, size, stored_path, company_id
|
connection, sha256, original_filename, size, stored_path,
|
||||||
|
company_id, upload_bank_account_id,
|
||||||
)
|
)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
# Lost a concurrent-insert race on the sha256 UNIQUE constraint: the
|
# Lost a concurrent-insert race on the sha256 UNIQUE constraint: the
|
||||||
@@ -133,6 +141,7 @@ def _create_batch_records(
|
|||||||
size_bytes: int,
|
size_bytes: int,
|
||||||
stored_path: Path,
|
stored_path: Path,
|
||||||
company_id: int | None,
|
company_id: int | None,
|
||||||
|
upload_bank_account_id: int | None,
|
||||||
) -> tuple[int, int]:
|
) -> tuple[int, int]:
|
||||||
now = utc_now()
|
now = utc_now()
|
||||||
with connection:
|
with connection:
|
||||||
@@ -146,10 +155,10 @@ def _create_batch_records(
|
|||||||
source_file_id = cursor.lastrowid
|
source_file_id = cursor.lastrowid
|
||||||
cursor = connection.execute(
|
cursor = connection.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO import_batches (source_file_id, status, company_id, created_at, updated_at)
|
INSERT INTO import_batches (source_file_id, status, company_id, upload_bank_account_id, created_at, updated_at)
|
||||||
VALUES (?, 'parsing', ?, ?, ?)
|
VALUES (?, 'parsing', ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(source_file_id, company_id, now, now),
|
(source_file_id, company_id, upload_bank_account_id, now, now),
|
||||||
)
|
)
|
||||||
batch_id = cursor.lastrowid
|
batch_id = cursor.lastrowid
|
||||||
return source_file_id, batch_id
|
return source_file_id, batch_id
|
||||||
@@ -278,17 +287,24 @@ def _store_immutable(
|
|||||||
target_dir = storage_dir / sha256[:2]
|
target_dir = storage_dir / sha256[:2]
|
||||||
target_dir.mkdir(parents=True, exist_ok=True)
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
target = target_dir / f"{sha256}{suffix}"
|
target = target_dir / f"{sha256}{suffix}"
|
||||||
# Publish via a temporary file + hard link: the content-addressed target
|
# Publish via a unique temporary file + hard link: the content-addressed
|
||||||
# either appears complete or not at all, and is never overwritten.
|
# target either appears complete or not at all, and is never overwritten.
|
||||||
temp = target_dir / f".{sha256}.tmp"
|
# The temp name is unique per writer, so concurrent uploads of the same
|
||||||
temp.write_bytes(content)
|
# bytes cannot corrupt each other's staging file (B-43 baseline fix).
|
||||||
|
fd, temp_path = tempfile.mkstemp(prefix=f".{sha256}.", suffix=".tmp", dir=target_dir)
|
||||||
try:
|
try:
|
||||||
os.link(temp, target)
|
with os.fdopen(fd, "wb") as handle:
|
||||||
except FileExistsError:
|
handle.write(content)
|
||||||
# Content-addressed name means identical bytes; never overwrite.
|
try:
|
||||||
pass
|
os.link(temp_path, target)
|
||||||
|
except FileExistsError:
|
||||||
|
# Content-addressed name means identical bytes; never overwrite.
|
||||||
|
pass
|
||||||
finally:
|
finally:
|
||||||
temp.unlink(missing_ok=True)
|
try:
|
||||||
|
os.unlink(temp_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
return target
|
return target
|
||||||
|
|
||||||
|
|
||||||
@@ -299,17 +315,24 @@ def _publish_immutable(
|
|||||||
target_dir = storage_dir / sha256[:2]
|
target_dir = storage_dir / sha256[:2]
|
||||||
target_dir.mkdir(parents=True, exist_ok=True)
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
target = target_dir / f"{sha256}{suffix}"
|
target = target_dir / f"{sha256}{suffix}"
|
||||||
temp = target_dir / f".{sha256}.tmp"
|
fd, temp_path = tempfile.mkstemp(prefix=f".{sha256}.", suffix=".tmp", dir=target_dir)
|
||||||
try:
|
try:
|
||||||
# Copy keeps the same-filesystem guarantee even if the upload temp
|
with os.fdopen(fd, "wb") as handle:
|
||||||
# lives elsewhere; the hard link then publishes atomically.
|
# Copy keeps the same-filesystem guarantee even if the upload temp
|
||||||
shutil.copyfile(upload_path, temp)
|
# lives elsewhere; the hard link then publishes atomically. The
|
||||||
|
# staging file is unique per writer, so two concurrent uploads of
|
||||||
|
# the same bytes never corrupt each other's copy.
|
||||||
|
with upload_path.open("rb") as source:
|
||||||
|
shutil.copyfileobj(source, handle, length=1024 * 1024)
|
||||||
try:
|
try:
|
||||||
os.link(temp, target)
|
os.link(temp_path, target)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
temp.unlink(missing_ok=True)
|
try:
|
||||||
|
os.unlink(temp_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
upload_path.unlink(missing_ok=True)
|
upload_path.unlink(missing_ok=True)
|
||||||
return target
|
return target
|
||||||
|
|
||||||
@@ -572,7 +595,15 @@ def review_sheets(
|
|||||||
now = utc_now()
|
now = utc_now()
|
||||||
updated: list[str] = []
|
updated: list[str] = []
|
||||||
already: list[str] = []
|
already: list[str] = []
|
||||||
with connection:
|
matching_result: dict[str, object] | None = None
|
||||||
|
# BEGIN IMMEDIATE serializes concurrent confirmations: the write lock is
|
||||||
|
# taken before the read, so two cashiers confirming matching worksheets can
|
||||||
|
# never derive their match decisions from stale snapshots.
|
||||||
|
began = False
|
||||||
|
if not connection.in_transaction:
|
||||||
|
connection.execute("BEGIN IMMEDIATE")
|
||||||
|
began = True
|
||||||
|
try:
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if row["review_status"] == target:
|
if row["review_status"] == target:
|
||||||
already.append(row["sheet_name"])
|
already.append(row["sheet_name"])
|
||||||
@@ -596,6 +627,34 @@ def review_sheets(
|
|||||||
if cursor.rowcount:
|
if cursor.rowcount:
|
||||||
updated.append(row["sheet_name"])
|
updated.append(row["sheet_name"])
|
||||||
|
|
||||||
|
# Confirming a worksheet and reconciling its rows must succeed or fail
|
||||||
|
# together: any matching failure rolls the confirmation back, so there
|
||||||
|
# is never a "confirmed but unmatched" half state.
|
||||||
|
if updated and decision == "confirm":
|
||||||
|
placeholders = ",".join("?" for _ in updated)
|
||||||
|
confirmed_rows = connection.execute(
|
||||||
|
f"""
|
||||||
|
SELECT r.id FROM source_rows r
|
||||||
|
JOIN sheet_batches s ON s.id = r.sheet_batch_id
|
||||||
|
JOIN sheet_reviews rv ON rv.sheet_batch_id = s.id
|
||||||
|
WHERE rv.sheet_name IN ({placeholders})
|
||||||
|
AND rv.import_batch_id = ?
|
||||||
|
ORDER BY r.id
|
||||||
|
""",
|
||||||
|
(*updated, batch_id),
|
||||||
|
).fetchall()
|
||||||
|
matching_result = matching.reconcile_rows(
|
||||||
|
connection,
|
||||||
|
[item["id"] for item in confirmed_rows],
|
||||||
|
actor=actor,
|
||||||
|
)
|
||||||
|
if began:
|
||||||
|
connection.commit()
|
||||||
|
except Exception:
|
||||||
|
if began:
|
||||||
|
connection.rollback()
|
||||||
|
raise
|
||||||
|
|
||||||
if updated:
|
if updated:
|
||||||
auth.audit(
|
auth.audit(
|
||||||
connection,
|
connection,
|
||||||
@@ -604,4 +663,7 @@ def review_sheets(
|
|||||||
target=f"batch:{batch_id}",
|
target=f"batch:{batch_id}",
|
||||||
detail=f"sheets:{','.join(updated)}" + (f";reason:{reason}" if reason else ""),
|
detail=f"sheets:{','.join(updated)}" + (f";reason:{reason}" if reason else ""),
|
||||||
)
|
)
|
||||||
return {"updated": updated, "already": already}
|
payload: dict[str, object] = {"updated": updated, "already": already}
|
||||||
|
if matching_result is not None:
|
||||||
|
payload["matching"] = matching_result
|
||||||
|
return payload
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,281 @@
|
|||||||
|
"""Personal transit account mappings and their administrator approval.
|
||||||
|
|
||||||
|
A personal transit mapping states that a personal bank account represents a
|
||||||
|
company for a specific flow direction inside an effective interval. The key is
|
||||||
|
the normalized account number; the account holder name is display-only and
|
||||||
|
never resolves a counterparty on its own (``AGENTS.md``: never infer a
|
||||||
|
financial fact from a name alone). Only administrator-approved (``active``)
|
||||||
|
mappings inside their effective window participate in counterparty resolution.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
from .db import utc_now
|
||||||
|
from .master_data import (
|
||||||
|
ConflictError,
|
||||||
|
mask_account_number,
|
||||||
|
normalize_account_number,
|
||||||
|
record_change,
|
||||||
|
validate_date,
|
||||||
|
)
|
||||||
|
|
||||||
|
MAPPING_STATUSES = ("pending", "active", "returned", "disabled")
|
||||||
|
ALLOWED_DIRECTIONS = ("outgoing", "incoming", "both")
|
||||||
|
|
||||||
|
|
||||||
|
def get_mapping(connection: sqlite3.Connection, mapping_id: int) -> sqlite3.Row | None:
|
||||||
|
return connection.execute(
|
||||||
|
"SELECT * FROM personal_transit_mappings WHERE id = ?", (mapping_id,)
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
|
||||||
|
def submit_mapping(
|
||||||
|
connection: sqlite3.Connection,
|
||||||
|
*,
|
||||||
|
account_number: object,
|
||||||
|
account_name: object,
|
||||||
|
represented_company_id: int,
|
||||||
|
allowed_direction: str,
|
||||||
|
effective_from: object = None,
|
||||||
|
actor: sqlite3.Row | None,
|
||||||
|
) -> sqlite3.Row:
|
||||||
|
"""Create a pending personal transit mapping; returns the new row.
|
||||||
|
|
||||||
|
The account number is normalized (digits only) and unique: resubmitting a
|
||||||
|
returned request from the same company reopens the same row as pending;
|
||||||
|
any other existing row is a conflict guarded by the UNIQUE constraint.
|
||||||
|
"""
|
||||||
|
number = normalize_account_number(account_number)
|
||||||
|
holder = str(account_name or "").strip() or None
|
||||||
|
direction = str(allowed_direction or "").strip()
|
||||||
|
if direction not in ALLOWED_DIRECTIONS:
|
||||||
|
raise ValueError(f"允许方向必须是:{'、'.join(ALLOWED_DIRECTIONS)}。")
|
||||||
|
if not holder:
|
||||||
|
raise ValueError("账户户名不能为空(仅作展示,不作匹配键)。")
|
||||||
|
company = connection.execute(
|
||||||
|
"SELECT id FROM companies WHERE id = ?", (represented_company_id,)
|
||||||
|
).fetchone()
|
||||||
|
if company is None:
|
||||||
|
raise ValueError("代表的公司不存在。")
|
||||||
|
start = validate_date(effective_from, "生效日期")
|
||||||
|
now = utc_now()
|
||||||
|
|
||||||
|
existing = connection.execute(
|
||||||
|
"SELECT * FROM personal_transit_mappings WHERE account_number = ?", (number,)
|
||||||
|
).fetchone()
|
||||||
|
if existing is None:
|
||||||
|
try:
|
||||||
|
with connection:
|
||||||
|
cursor = connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO personal_transit_mappings (
|
||||||
|
account_number, account_name, represented_company_id,
|
||||||
|
allowed_direction, status, effective_from, submitted_by,
|
||||||
|
created_at, updated_at
|
||||||
|
) VALUES (?, ?, ?, ?, 'pending', ?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
number, holder, represented_company_id, direction,
|
||||||
|
start, actor["id"] if actor else None, now, now,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
except sqlite3.IntegrityError as exc:
|
||||||
|
raise ConflictError("该个人过账账号已登记,请等待现有申请处理。") from exc
|
||||||
|
mapping_id = int(cursor.lastrowid)
|
||||||
|
with connection:
|
||||||
|
record_change(
|
||||||
|
connection, "personal_transit_mapping", mapping_id, "submit", None,
|
||||||
|
{"account_number": number, "account_name": holder,
|
||||||
|
"represented_company_id": represented_company_id,
|
||||||
|
"allowed_direction": direction, "status": "pending",
|
||||||
|
"effective_from": start},
|
||||||
|
None, actor,
|
||||||
|
)
|
||||||
|
return get_mapping(connection, mapping_id)
|
||||||
|
|
||||||
|
if existing["status"] == "returned":
|
||||||
|
with connection:
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE personal_transit_mappings
|
||||||
|
SET account_name = ?, represented_company_id = ?,
|
||||||
|
allowed_direction = ?, status = 'pending', effective_from = ?,
|
||||||
|
submitted_by = ?, reviewed_by = NULL, reviewed_at = NULL,
|
||||||
|
review_reason = NULL, updated_at = ?
|
||||||
|
WHERE id = ? AND status = 'returned'
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
holder, represented_company_id, direction, start,
|
||||||
|
actor["id"] if actor else None, now, existing["id"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
record_change(
|
||||||
|
connection, "personal_transit_mapping", existing["id"], "resubmit",
|
||||||
|
None, {"account_number": number, "status": "pending",
|
||||||
|
"allowed_direction": direction, "effective_from": start},
|
||||||
|
"退回后重新提交", actor,
|
||||||
|
)
|
||||||
|
return get_mapping(connection, existing["id"])
|
||||||
|
|
||||||
|
raise ConflictError("该个人过账账号已登记,请等待现有申请处理。")
|
||||||
|
|
||||||
|
|
||||||
|
def review_mapping(
|
||||||
|
connection: sqlite3.Connection,
|
||||||
|
mapping_id: int,
|
||||||
|
decision: str,
|
||||||
|
reason: str | None,
|
||||||
|
actor: sqlite3.Row,
|
||||||
|
*,
|
||||||
|
effective_from: object = None,
|
||||||
|
effective_to: object = None,
|
||||||
|
) -> sqlite3.Row:
|
||||||
|
"""Approve, return or disable a mapping; returns the updated row."""
|
||||||
|
mapping = get_mapping(connection, mapping_id)
|
||||||
|
if mapping is None:
|
||||||
|
raise LookupError("个人过账映射不存在。")
|
||||||
|
reason = (reason or "").strip() or None
|
||||||
|
today = utc_now()[:10]
|
||||||
|
|
||||||
|
if decision == "approve":
|
||||||
|
if mapping["status"] != "pending":
|
||||||
|
raise ConflictError("只有待复核的映射可以审核通过。")
|
||||||
|
start = validate_date(effective_from, "生效日期") or mapping["effective_from"] or today
|
||||||
|
with connection:
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE personal_transit_mappings
|
||||||
|
SET status = 'active', effective_from = ?, effective_to = NULL,
|
||||||
|
reviewed_by = ?, reviewed_at = ?, review_reason = ?, updated_at = ?
|
||||||
|
WHERE id = ?
|
||||||
|
""",
|
||||||
|
(start, actor["id"], utc_now(), reason, utc_now(), mapping_id),
|
||||||
|
)
|
||||||
|
record_change(
|
||||||
|
connection, "personal_transit_mapping", mapping_id, "approve", None,
|
||||||
|
{"status": "active", "effective_from": start}, reason, actor,
|
||||||
|
)
|
||||||
|
elif decision == "return":
|
||||||
|
if mapping["status"] != "pending":
|
||||||
|
raise ConflictError("只有待复核的映射可以退回。")
|
||||||
|
if reason is None:
|
||||||
|
raise ValueError("退回必须填写原因。")
|
||||||
|
with connection:
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE personal_transit_mappings
|
||||||
|
SET status = 'returned', reviewed_by = ?, reviewed_at = ?,
|
||||||
|
review_reason = ?, updated_at = ?
|
||||||
|
WHERE id = ?
|
||||||
|
""",
|
||||||
|
(actor["id"], utc_now(), reason, utc_now(), mapping_id),
|
||||||
|
)
|
||||||
|
record_change(
|
||||||
|
connection, "personal_transit_mapping", mapping_id, "return", None,
|
||||||
|
{"status": "returned"}, reason, actor,
|
||||||
|
)
|
||||||
|
elif decision == "disable":
|
||||||
|
if mapping["status"] != "active":
|
||||||
|
raise ConflictError("只有已启用的映射可以停用。")
|
||||||
|
if reason is None:
|
||||||
|
raise ValueError("停用必须填写原因。")
|
||||||
|
end = validate_date(effective_to, "停用日期") or today
|
||||||
|
with connection:
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE personal_transit_mappings
|
||||||
|
SET status = 'disabled', effective_to = ?,
|
||||||
|
reviewed_by = ?, reviewed_at = ?, review_reason = ?, updated_at = ?
|
||||||
|
WHERE id = ?
|
||||||
|
""",
|
||||||
|
(end, actor["id"], utc_now(), reason, utc_now(), mapping_id),
|
||||||
|
)
|
||||||
|
record_change(
|
||||||
|
connection, "personal_transit_mapping", mapping_id, "disable", None,
|
||||||
|
{"status": "disabled", "effective_to": end}, reason, actor,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise ValueError("审核决定必须是 approve、return 或 disable。")
|
||||||
|
return get_mapping(connection, mapping_id)
|
||||||
|
|
||||||
|
|
||||||
|
def list_mappings(
|
||||||
|
connection: sqlite3.Connection,
|
||||||
|
company_id: int | None = None,
|
||||||
|
status: str | None = None,
|
||||||
|
) -> list[sqlite3.Row]:
|
||||||
|
conditions: list[str] = []
|
||||||
|
params: list[object] = []
|
||||||
|
if company_id is not None:
|
||||||
|
conditions.append("m.represented_company_id = ?")
|
||||||
|
params.append(company_id)
|
||||||
|
if status is not None:
|
||||||
|
if status not in MAPPING_STATUSES:
|
||||||
|
raise ValueError("无效的映射状态。")
|
||||||
|
conditions.append("m.status = ?")
|
||||||
|
params.append(status)
|
||||||
|
where = f"WHERE {' AND '.join(conditions)}" if conditions else ""
|
||||||
|
return connection.execute(
|
||||||
|
f"""
|
||||||
|
SELECT m.*, c.name AS company_name
|
||||||
|
FROM personal_transit_mappings m
|
||||||
|
JOIN companies c ON c.id = m.represented_company_id
|
||||||
|
{where}
|
||||||
|
ORDER BY m.id
|
||||||
|
""",
|
||||||
|
params,
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
def is_mapping_active(mapping: sqlite3.Row, on_date: str) -> bool:
|
||||||
|
"""True when the mapping may resolve a counterparty on ``on_date``.
|
||||||
|
|
||||||
|
``effective_to`` is the last participating day (inclusive). Disabled
|
||||||
|
mappings stop resolving new rows but keep identifying historical rows
|
||||||
|
inside their effective window, matching ``bank_accounts`` semantics.
|
||||||
|
"""
|
||||||
|
if mapping["status"] not in ("active", "disabled"):
|
||||||
|
return False
|
||||||
|
if mapping["effective_from"] and on_date < mapping["effective_from"]:
|
||||||
|
return False
|
||||||
|
if mapping["effective_to"] and on_date > mapping["effective_to"]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def direction_allowed(mapping: sqlite3.Row, row_direction: str) -> bool:
|
||||||
|
"""True when the personal account may represent the company for this flow.
|
||||||
|
|
||||||
|
``allowed_direction`` describes the transfer from the represented company's
|
||||||
|
perspective: when the personal account appears as the counterparty of an
|
||||||
|
outgoing row, the represented company is receiving (incoming); for an
|
||||||
|
incoming row the represented company is paying out (outgoing).
|
||||||
|
"""
|
||||||
|
counterparty_flow = "incoming" if row_direction == "outgoing" else "outgoing"
|
||||||
|
allowed = mapping["allowed_direction"]
|
||||||
|
return allowed == "both" or allowed == counterparty_flow
|
||||||
|
|
||||||
|
|
||||||
|
def mapping_payload(mapping: sqlite3.Row, *, full: bool) -> dict[str, object]:
|
||||||
|
"""Serialize a mapping; company-facing views only ever see masked numbers."""
|
||||||
|
payload: dict[str, object] = {
|
||||||
|
"id": mapping["id"],
|
||||||
|
"account_name": mapping["account_name"],
|
||||||
|
"represented_company_id": mapping["represented_company_id"],
|
||||||
|
"allowed_direction": mapping["allowed_direction"],
|
||||||
|
"status": mapping["status"],
|
||||||
|
"effective_from": mapping["effective_from"],
|
||||||
|
"effective_to": mapping["effective_to"],
|
||||||
|
"reviewed_at": mapping["reviewed_at"],
|
||||||
|
"review_reason": mapping["review_reason"],
|
||||||
|
"created_at": mapping["created_at"],
|
||||||
|
}
|
||||||
|
if "company_name" in mapping.keys():
|
||||||
|
payload["company_name"] = mapping["company_name"]
|
||||||
|
if full:
|
||||||
|
payload["account_number"] = mapping["account_number"]
|
||||||
|
else:
|
||||||
|
payload["account_number_masked"] = mask_account_number(mapping["account_number"])
|
||||||
|
return payload
|
||||||
@@ -17,6 +17,7 @@ from pathlib import Path
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from openpyxl import Workbook
|
from openpyxl import Workbook
|
||||||
|
|
||||||
@@ -49,6 +50,14 @@ CCB_DATA = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def ccb_row(own, cp, *, expense="", income="", at="2026-01-05 10:00:00"):
|
||||||
|
return [own, "测试公司", at, expense or "", income or "", "99900.00", "RMB", "对方", cp, "某银行", "货款", ""]
|
||||||
|
|
||||||
|
|
||||||
|
def ccb_bytes(rows):
|
||||||
|
return workbook_bytes([("正常流水", [CCB_HEADER, *rows])])
|
||||||
|
|
||||||
|
|
||||||
def workbook_bytes(sheets):
|
def workbook_bytes(sheets):
|
||||||
"""Build an xlsx in memory.
|
"""Build an xlsx in memory.
|
||||||
|
|
||||||
@@ -582,6 +591,145 @@ class ImportApiServerTests(unittest.TestCase):
|
|||||||
finally:
|
finally:
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Worksheet confirmation drives canonical matching in the same transaction
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _approve_test_account(self, company_client, number: str) -> int:
|
||||||
|
status, _, data = company_client.post_json(
|
||||||
|
"/api/company/accounts",
|
||||||
|
{"bank_name": "中信银行", "account_type": "基本户",
|
||||||
|
"account_number": number, "start_date": "2026-01-01"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
account_id = as_json(data)["account"]["id"]
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
f"/api/admin/accounts/{account_id}/review",
|
||||||
|
{"decision": "approve", "reason": "测试启用", "effective_from": "2026-01-01"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
return account_id
|
||||||
|
|
||||||
|
def _company_cashier(self, username: str, company_id: int) -> Client:
|
||||||
|
"""A company cashier bound to the given company (the class fixture binds
|
||||||
|
both cashiers to company A, so tests needing a real tenant B create one)."""
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
"/api/admin/users", {"username": username, "company_id": company_id}
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
initial = as_json(data)["initial_password"]
|
||||||
|
client = self.fresh_client()
|
||||||
|
status, _, data = client.post_json(
|
||||||
|
"/api/login",
|
||||||
|
{"username": username, "password": initial, "portal": "company"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
status, _, data = client.post_json(
|
||||||
|
"/api/password/change",
|
||||||
|
{"old_password": initial, "new_password": "Changed456"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
return client
|
||||||
|
|
||||||
|
def test_confirm_drives_bilateral_matching_atomically(self) -> None:
|
||||||
|
account_a = self._approve_test_account(self.cashier_a, "6222000000000001")
|
||||||
|
cashier_b = self._company_cashier("cashier-b2", self.company_b)
|
||||||
|
account_b = self._approve_test_account(cashier_b, "6222000000000002")
|
||||||
|
|
||||||
|
# A's side first: confirming the worksheet reconciles its row into an
|
||||||
|
# internal single (not yet eligible for the intercompany balance).
|
||||||
|
status, _, data = self.upload_for_a(
|
||||||
|
ccb_bytes([ccb_row("6222000000000001", "6222000000000002", expense="100.00")]),
|
||||||
|
filename="A方.xlsx",
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
batch_a = as_json(data)["batch_id"]
|
||||||
|
status, _, data = self.confirm(self.cashier_a, batch_a, ["正常流水"])
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
self.assertEqual(1, as_json(data)["matching"]["created_events"])
|
||||||
|
connection = connect(self.db_path)
|
||||||
|
try:
|
||||||
|
row_a = connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT r.id FROM source_rows r
|
||||||
|
JOIN sheet_batches s ON s.id = r.sheet_batch_id
|
||||||
|
WHERE s.import_batch_id = ?
|
||||||
|
""",
|
||||||
|
(batch_a,),
|
||||||
|
).fetchone()
|
||||||
|
status_a = connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT d.classification FROM transfer_observation_claims c
|
||||||
|
JOIN transfer_match_decisions d ON d.id = c.decision_id
|
||||||
|
WHERE c.source_row_id = ?
|
||||||
|
""",
|
||||||
|
(row_a["id"],),
|
||||||
|
).fetchone()
|
||||||
|
self.assertEqual("internal_single", status_a["classification"])
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
# B's side arrives later: the second confirmation merges both into one
|
||||||
|
# paired intercompany event without duplicating the first.
|
||||||
|
status, _, data = cashier_b.post_multipart(
|
||||||
|
"/api/parse", {}, "B方.xlsx",
|
||||||
|
ccb_bytes([ccb_row("6222000000000002", "6222000000000001", income="100.00")]),
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
batch_b = as_json(data)["batch_id"]
|
||||||
|
status, _, data = self.confirm(cashier_b, batch_b, ["正常流水"])
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
connection = connect(self.db_path)
|
||||||
|
try:
|
||||||
|
eligible = connection.execute(
|
||||||
|
"SELECT * FROM eligible_intercompany_events"
|
||||||
|
).fetchall()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual("100.00", eligible[0]["amount"])
|
||||||
|
self.assertEqual("paired", eligible[0]["pairing"])
|
||||||
|
# Exactly one current intercompany decision for the pair.
|
||||||
|
self.assertEqual(1, connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT COUNT(*) AS n FROM current_transfer_decisions c
|
||||||
|
JOIN transfer_match_decisions d ON d.id = c.decision_id
|
||||||
|
WHERE d.classification = 'intercompany'
|
||||||
|
"""
|
||||||
|
).fetchone()["n"])
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def test_confirm_rolls_back_when_matching_fails(self) -> None:
|
||||||
|
account_a = self._approve_test_account(self.cashier_a, "6222000000000003")
|
||||||
|
status, _, data = self.upload_for_a(
|
||||||
|
ccb_bytes([ccb_row("6222000000000003", "6222000000000004", expense="50.00")]),
|
||||||
|
filename="回滚.xlsx",
|
||||||
|
)
|
||||||
|
batch_id = as_json(data)["batch_id"]
|
||||||
|
with mock.patch(
|
||||||
|
"bank_importer.importing.matching.reconcile_rows",
|
||||||
|
side_effect=RuntimeError("simulated matching failure"),
|
||||||
|
):
|
||||||
|
status, _, data = self.confirm(self.cashier_a, batch_id, ["正常流水"])
|
||||||
|
self.assertEqual(500, status, data)
|
||||||
|
# The worksheet confirmation was rolled back with the failed matching.
|
||||||
|
sheet = self.batch_sheets(self.cashier_a, batch_id)[0]
|
||||||
|
self.assertEqual("pending", sheet["review_status"])
|
||||||
|
connection = connect(self.db_path)
|
||||||
|
try:
|
||||||
|
# No decision or claim was left behind for this batch's rows.
|
||||||
|
claims = connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT COUNT(*) AS n FROM transfer_observation_claims c
|
||||||
|
JOIN source_rows r ON r.id = c.source_row_id
|
||||||
|
JOIN sheet_batches s ON s.id = r.sheet_batch_id
|
||||||
|
WHERE s.import_batch_id = ?
|
||||||
|
""",
|
||||||
|
(batch_id,),
|
||||||
|
).fetchone()["n"]
|
||||||
|
self.assertEqual(0, claims)
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -0,0 +1,984 @@
|
|||||||
|
"""Matching engine tests: bilateral ordering, cross-day windows, ambiguity,
|
||||||
|
same-company transfers, personal transit mappings, manual decisions, locking,
|
||||||
|
idempotency, concurrency, Decimal precision and B-44 eligibility."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
from pathlib import Path
|
||||||
|
import sqlite3
|
||||||
|
import tempfile
|
||||||
|
import threading
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from bank_importer import auth, matching, master_data, personal_transit
|
||||||
|
from bank_importer.db import connect, migrate, utc_now
|
||||||
|
|
||||||
|
|
||||||
|
class MatchingBase(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.temp_dir = tempfile.TemporaryDirectory()
|
||||||
|
self.addCleanup(self.temp_dir.cleanup)
|
||||||
|
root = Path(self.temp_dir.name)
|
||||||
|
self.db_path = root / "app.db"
|
||||||
|
self.connection = connect(self.db_path)
|
||||||
|
self.addCleanup(self.connection.close)
|
||||||
|
migrate(self.connection)
|
||||||
|
self.admin = self._admin()
|
||||||
|
self.company_a = self._company("甲公司")
|
||||||
|
self.company_b = self._company("乙公司")
|
||||||
|
self.company_c = self._company("丙公司")
|
||||||
|
self.account_a = self._approved_account(self.company_a, "6222000000000001")
|
||||||
|
self.account_b = self._approved_account(self.company_b, "6222000000000002")
|
||||||
|
self.account_a2 = self._approved_account(self.company_a, "6222000000000003")
|
||||||
|
self.account_b2 = self._approved_account(self.company_b, "6222000000000004")
|
||||||
|
|
||||||
|
def _admin(self):
|
||||||
|
auth.create_user(self.connection, "admin-u", "AdminPass123", "admin")
|
||||||
|
return self.connection.execute(
|
||||||
|
"SELECT * FROM users WHERE username = 'admin-u'"
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
def _company(self, name: str) -> int:
|
||||||
|
with self.connection:
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"INSERT INTO companies (name, created_at, updated_at) VALUES (?, ?, ?)",
|
||||||
|
(name, utc_now(), utc_now()),
|
||||||
|
)
|
||||||
|
return int(cursor.lastrowid)
|
||||||
|
|
||||||
|
def _approved_account(self, company_id: int, number: str, start: str = "2026-01-01"):
|
||||||
|
account = master_data.submit_bank_account(
|
||||||
|
self.connection, company_id=company_id, bank_name="中信银行",
|
||||||
|
account_type="基本户", account_number=number, start_date=start,
|
||||||
|
actor=None,
|
||||||
|
)
|
||||||
|
return master_data.review_bank_account(
|
||||||
|
self.connection, account["id"], "approve", None, self.admin,
|
||||||
|
effective_from=start,
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_row(
|
||||||
|
self,
|
||||||
|
company_id: int,
|
||||||
|
*,
|
||||||
|
own_account: str,
|
||||||
|
own_name: str = "测试公司",
|
||||||
|
cp_account: str | None = None,
|
||||||
|
cp_name: str | None = None,
|
||||||
|
income: str = "0",
|
||||||
|
expense: str = "0",
|
||||||
|
at: str = "2026-01-05T10:00:00",
|
||||||
|
currency: str = "CNY",
|
||||||
|
reference: str | None = None,
|
||||||
|
summary: str | None = None,
|
||||||
|
sheet: str = "流水",
|
||||||
|
) -> int:
|
||||||
|
with self.connection:
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO source_files (sha256, original_filename, size_bytes, storage_path, created_at)
|
||||||
|
VALUES (?, '测试.xlsx', 1, 'data/files/测试.xlsx', ?)
|
||||||
|
""",
|
||||||
|
(utc_now(), utc_now()),
|
||||||
|
)
|
||||||
|
source_file_id = int(cursor.lastrowid)
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO import_batches (source_file_id, status, company_id, created_at, updated_at)
|
||||||
|
VALUES (?, 'parsing', ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(source_file_id, company_id, utc_now(), utc_now()),
|
||||||
|
)
|
||||||
|
batch_id = int(cursor.lastrowid)
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO sheet_batches (
|
||||||
|
import_batch_id, sheet_name, bank_name, template_id, template_version,
|
||||||
|
header_row, own_account, own_name, period_start, period_end,
|
||||||
|
transaction_count, warnings, created_at
|
||||||
|
) VALUES (?, ?, '测试银行', 'test-v1', 1, 1, NULL, NULL, NULL, NULL, 1, '[]', ?)
|
||||||
|
""",
|
||||||
|
(batch_id, sheet, utc_now()),
|
||||||
|
)
|
||||||
|
sheet_batch_id = int(cursor.lastrowid)
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO sheet_reviews (
|
||||||
|
import_batch_id, sheet_name, outcome, sheet_batch_id,
|
||||||
|
review_status, created_at
|
||||||
|
) VALUES (?, ?, 'parsed', ?, 'confirmed', ?)
|
||||||
|
""",
|
||||||
|
(batch_id, sheet, sheet_batch_id, utc_now()),
|
||||||
|
)
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO source_rows (
|
||||||
|
sheet_batch_id, source_row, transaction_at, income, expense, balance,
|
||||||
|
own_account, own_name, counterparty_account, counterparty_name,
|
||||||
|
counterparty_bank, summary, purpose, reference, currency, created_at
|
||||||
|
) VALUES (?, 1, ?, ?, ?, NULL, ?, ?, ?, ?, NULL, ?, NULL, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
sheet_batch_id, at, income, expense, own_account, own_name,
|
||||||
|
cp_account, cp_name, summary, reference, currency, utc_now(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return int(cursor.lastrowid)
|
||||||
|
|
||||||
|
def current(self, row_id: int):
|
||||||
|
return self.connection.execute(
|
||||||
|
"""
|
||||||
|
SELECT d.classification, d.pairing, d.amount, d.currency, d.effective_at,
|
||||||
|
d.mode, d.locked, d.revision
|
||||||
|
FROM transfer_observation_claims c
|
||||||
|
JOIN transfer_match_decisions d ON d.id = c.decision_id
|
||||||
|
WHERE c.source_row_id = ?
|
||||||
|
""",
|
||||||
|
(row_id,),
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
def _event_of(self, row_id: int) -> int:
|
||||||
|
return self.connection.execute(
|
||||||
|
"SELECT event_id FROM transfer_observation_claims WHERE source_row_id = ?",
|
||||||
|
(row_id,),
|
||||||
|
).fetchone()["event_id"]
|
||||||
|
|
||||||
|
def eligible(self) -> list[sqlite3.Row]:
|
||||||
|
return matching.eligible_intercompany_events(self.connection)
|
||||||
|
|
||||||
|
def event_count(self) -> int:
|
||||||
|
return self.connection.execute(
|
||||||
|
"SELECT COUNT(*) AS n FROM canonical_transfer_events"
|
||||||
|
).fetchone()["n"]
|
||||||
|
|
||||||
|
def decision_count(self) -> int:
|
||||||
|
return self.connection.execute(
|
||||||
|
"SELECT COUNT(*) AS n FROM transfer_match_decisions"
|
||||||
|
).fetchone()["n"]
|
||||||
|
|
||||||
|
|
||||||
|
class BilateralOrderTests(MatchingBase):
|
||||||
|
def test_a_outgoing_then_b_incoming_pairs_once(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", at="2026-01-05T10:00:00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("internal_single", self.current(row_a)["classification"])
|
||||||
|
# A single internal observation must not enter the B-44 balance yet.
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00", at="2026-01-05T11:00:00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_b])
|
||||||
|
for row_id in (row_a, row_b):
|
||||||
|
self.assertEqual("intercompany", self.current(row_id)["classification"])
|
||||||
|
self.assertEqual("paired", self.current(row_id)["pairing"])
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual(Decimal("100.00"), Decimal(eligible[0]["amount"]))
|
||||||
|
self.assertEqual("CNY", eligible[0]["currency"])
|
||||||
|
self.assertEqual(self.company_a, eligible[0]["payer_company_id"])
|
||||||
|
self.assertEqual(self.company_b, eligible[0]["payee_company_id"])
|
||||||
|
self.assertEqual("paired", eligible[0]["pairing"])
|
||||||
|
# One event, one paired decision for both rows.
|
||||||
|
self.assertEqual(1, self.event_count())
|
||||||
|
|
||||||
|
def test_b_incoming_then_a_outgoing_same_result(self) -> None:
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00", at="2026-01-05T11:00:00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_b])
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", at="2026-01-05T10:00:00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual("100.00", eligible[0]["amount"])
|
||||||
|
# Economic date is the payer's outgoing posting time, import-order free.
|
||||||
|
self.assertEqual("2026-01-05T10:00:00", eligible[0]["effective_at"])
|
||||||
|
self.assertEqual(self.company_a, eligible[0]["payer_company_id"])
|
||||||
|
|
||||||
|
def test_same_batch_both_sides_pairs_once(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_b, row_a])
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual("paired", self.current(row_a)["pairing"])
|
||||||
|
# One event, one auto decision carrying both observations.
|
||||||
|
self.assertEqual(1, self.event_count())
|
||||||
|
self.assertEqual(1, self.decision_count())
|
||||||
|
|
||||||
|
def test_repeated_reconcile_is_idempotent(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
before_decisions = self.decision_count()
|
||||||
|
stats = matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual(self.decision_count(), before_decisions)
|
||||||
|
self.assertEqual(2, stats["unchanged"])
|
||||||
|
self.assertEqual(0, stats["created_events"])
|
||||||
|
self.assertEqual(0, stats["updated_events"])
|
||||||
|
|
||||||
|
|
||||||
|
class DateWindowTests(MatchingBase):
|
||||||
|
def test_m1_same_reference_within_3_days(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
at="2026-01-01T09:00:00", reference="R1001",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
at="2026-01-04T15:00:00", reference="R1001",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
|
||||||
|
candidate = self.connection.execute(
|
||||||
|
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
|
||||||
|
).fetchone()
|
||||||
|
self.assertEqual("M1", candidate["rule_tier"])
|
||||||
|
|
||||||
|
def test_m2_exact_mirror_same_day_without_reference(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
|
||||||
|
candidate = self.connection.execute(
|
||||||
|
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
|
||||||
|
).fetchone()
|
||||||
|
self.assertEqual("M2", candidate["rule_tier"])
|
||||||
|
|
||||||
|
def test_over_window_goes_to_review(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
at="2026-01-01T09:00:00", reference="R1001",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
at="2026-01-05T15:00:00", reference="R1001",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
def test_reference_conflict_goes_to_review(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
reference="R-A",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
reference="R-B",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
|
||||||
|
class AmbiguityTests(MatchingBase):
|
||||||
|
def test_alias_across_companies_goes_to_review(self) -> None:
|
||||||
|
# The same observed number is an account alias of TWO companies; the
|
||||||
|
# counterparty cannot be uniquely decided, so it must go to review.
|
||||||
|
company_c_account = self._approved_account(self.company_c, "6222000000000005")
|
||||||
|
master_data.add_alias(
|
||||||
|
self.connection, self.account_b["id"], "account", "770077007700",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
master_data.add_alias(
|
||||||
|
self.connection, company_c_account["id"], "account", "770077007700",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="770077007700", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
def test_two_same_tier_candidates_go_to_review(self) -> None:
|
||||||
|
# Two identical incoming observations mirror the outgoing row exactly;
|
||||||
|
# no deterministic rule may pick one, so the pair goes to review.
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b1 = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
row_b2 = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b1, row_b2])
|
||||||
|
# The ambiguous side stays in review; the two identical observations
|
||||||
|
# may not be auto-grabbed by a processing-order tie-break.
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b1)))
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b2)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
def test_different_amounts_never_match(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.01",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
|
||||||
|
class SameCompanyTests(MatchingBase):
|
||||||
|
def test_same_company_transfer_excluded_from_intercompany(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000003", expense="50.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000003",
|
||||||
|
cp_account="6222000000000001", income="50.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("same_company_transfer", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual("same_company_transfer", matching.exposed_status(self.current(row_b)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
# The cash trail is kept: both rows remain claimed by one event.
|
||||||
|
self.assertEqual(1, self.event_count())
|
||||||
|
|
||||||
|
def test_same_company_single_observation_classified_immediately(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000003", expense="50.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("same_company_transfer", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
|
||||||
|
class UnresolvedAndExternalTests(MatchingBase):
|
||||||
|
def test_unknown_counterparty_stays_unresolved(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="9999999999999999", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("unresolved", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
unresolved = matching.unresolved_amounts(self.connection, self.company_a)
|
||||||
|
self.assertEqual(1, len(unresolved))
|
||||||
|
self.assertEqual("100.00", unresolved[0]["amount"])
|
||||||
|
|
||||||
|
def test_internal_single_counts_as_unresolved_amount(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
unresolved = matching.unresolved_amounts(self.connection, self.company_a)
|
||||||
|
self.assertEqual(1, len(unresolved))
|
||||||
|
self.assertEqual("100.00", unresolved[0]["amount"])
|
||||||
|
|
||||||
|
def test_admin_confirm_single_becomes_eligible(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
current = self.current(row_a)
|
||||||
|
result = matching.apply_manual_decision(
|
||||||
|
self.connection, self._event_of(row_a),
|
||||||
|
"assign_participant",
|
||||||
|
reason="对方公司函证确认",
|
||||||
|
expected_revision=current["revision"],
|
||||||
|
request_key="assign-1",
|
||||||
|
actor=self.admin,
|
||||||
|
participant={"role": "payee", "company_id": self.company_b},
|
||||||
|
)
|
||||||
|
self.assertEqual("intercompany", result["classification"])
|
||||||
|
self.assertTrue(result["locked"])
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual("single", eligible[0]["pairing"])
|
||||||
|
# The manual confirmation is skipped by auto reconcile.
|
||||||
|
decisions_before = self.decision_count()
|
||||||
|
stats = matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual(1, stats["skipped_locked"])
|
||||||
|
self.assertEqual(decisions_before, self.decision_count())
|
||||||
|
|
||||||
|
def test_mark_external_requires_admin_and_excludes(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="9999999999999999", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
event_id = self._event_of(row_a)
|
||||||
|
result = matching.apply_manual_decision(
|
||||||
|
self.connection, event_id, "mark_external",
|
||||||
|
reason="经核实为外部供应商付款",
|
||||||
|
expected_revision=self.current(row_a)["revision"],
|
||||||
|
request_key=None, actor=self.admin,
|
||||||
|
)
|
||||||
|
self.assertEqual("external", result["classification"])
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
def test_reverse_frees_claims_for_reconcile(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
event_id = self._event_of(row_a)
|
||||||
|
decisions_before = self.decision_count()
|
||||||
|
result = matching.apply_manual_decision(
|
||||||
|
self.connection, event_id, "reverse",
|
||||||
|
reason="配对依据有误,需要重新匹配",
|
||||||
|
expected_revision=self.current(row_a)["revision"],
|
||||||
|
request_key="rev-1", actor=self.admin,
|
||||||
|
)
|
||||||
|
self.assertEqual(decisions_before + 1, self.decision_count())
|
||||||
|
# Claims and current pointer are gone; B-44 sees nothing.
|
||||||
|
self.assertIsNone(self.connection.execute(
|
||||||
|
"SELECT 1 FROM transfer_observation_claims WHERE source_row_id = ?",
|
||||||
|
(row_a,),
|
||||||
|
).fetchone())
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
# A re-run is allowed and re-derives deterministically.
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
|
||||||
|
class PersonalTransitTests(MatchingBase):
|
||||||
|
def _submit_mapping(self, company_id: int, number: str, direction: str) -> int:
|
||||||
|
mapping = personal_transit.submit_mapping(
|
||||||
|
self.connection,
|
||||||
|
account_number=number,
|
||||||
|
account_name="张个人",
|
||||||
|
represented_company_id=company_id,
|
||||||
|
allowed_direction=direction,
|
||||||
|
effective_from="2026-01-01",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
approved = personal_transit.review_mapping(
|
||||||
|
self.connection, mapping["id"], "approve", None, self.admin,
|
||||||
|
effective_from="2026-01-01",
|
||||||
|
)
|
||||||
|
return approved["id"]
|
||||||
|
|
||||||
|
def test_personal_mapping_resolves_counterparty(self) -> None:
|
||||||
|
self._submit_mapping(self.company_b, "880088008800", "incoming")
|
||||||
|
# A pays to the personal account -> the counterparty represents B.
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="880088008800", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_a)))
|
||||||
|
unresolved = matching.unresolved_amounts(self.connection, self.company_a)
|
||||||
|
self.assertEqual(1, len(unresolved))
|
||||||
|
|
||||||
|
def test_personal_mapping_direction_mismatch_unresolved(self) -> None:
|
||||||
|
self._submit_mapping(self.company_b, "880088008800", "incoming")
|
||||||
|
# An outgoing row to the personal account is NOT covered by an
|
||||||
|
# incoming-only mapping.
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="880088008800", expense="100.00",
|
||||||
|
)
|
||||||
|
# reverse direction check: make it incoming via income
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="880088008800", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
matching.reconcile_rows(self.connection, [row_b])
|
||||||
|
self.assertEqual("unresolved", matching.exposed_status(self.current(row_b)))
|
||||||
|
|
||||||
|
def test_unapproved_mapping_never_resolves(self) -> None:
|
||||||
|
personal_transit.submit_mapping(
|
||||||
|
self.connection,
|
||||||
|
account_number="880088008801",
|
||||||
|
account_name="李个人",
|
||||||
|
represented_company_id=self.company_b,
|
||||||
|
allowed_direction="both",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="880088008801", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("unresolved", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
def test_mapping_effective_window_and_resubmit_reuse(self) -> None:
|
||||||
|
mapping = personal_transit.submit_mapping(
|
||||||
|
self.connection,
|
||||||
|
account_number="880088008802",
|
||||||
|
account_name="王个人",
|
||||||
|
represented_company_id=self.company_b,
|
||||||
|
allowed_direction="both",
|
||||||
|
effective_from="2026-03-01",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
personal_transit.review_mapping(
|
||||||
|
self.connection, mapping["id"], "approve", None, self.admin,
|
||||||
|
effective_from="2026-03-01",
|
||||||
|
)
|
||||||
|
# Outside the effective window the mapping does not resolve.
|
||||||
|
row_before = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="880088008802", expense="100.00", at="2026-02-20T10:00:00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_before])
|
||||||
|
self.assertEqual("unresolved", matching.exposed_status(self.current(row_before)))
|
||||||
|
# Inside the window it does.
|
||||||
|
row_inside = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="880088008802", expense="100.00", at="2026-03-05T10:00:00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_inside])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_inside)))
|
||||||
|
|
||||||
|
# Returned mappings reopen on resubmission reusing the same row.
|
||||||
|
returned = personal_transit.submit_mapping(
|
||||||
|
self.connection,
|
||||||
|
account_number="880088008803",
|
||||||
|
account_name="赵个人",
|
||||||
|
represented_company_id=self.company_b,
|
||||||
|
allowed_direction="both",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
personal_transit.review_mapping(
|
||||||
|
self.connection, returned["id"], "return", "资料待补充", self.admin,
|
||||||
|
)
|
||||||
|
resubmitted = personal_transit.submit_mapping(
|
||||||
|
self.connection,
|
||||||
|
account_number="8800 8800 8803",
|
||||||
|
account_name="赵个人",
|
||||||
|
represented_company_id=self.company_b,
|
||||||
|
allowed_direction="incoming",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
self.assertEqual(returned["id"], resubmitted["id"])
|
||||||
|
self.assertEqual("pending", resubmitted["status"])
|
||||||
|
|
||||||
|
|
||||||
|
class ResolutionTests(MatchingBase):
|
||||||
|
def test_name_alias_never_resolves_alone(self) -> None:
|
||||||
|
master_data.add_alias(
|
||||||
|
self.connection, self.account_b["id"], "name", "乙公司贸易部",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account=None, cp_name="乙公司贸易部", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
self.assertEqual("unresolved", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
def test_own_account_conflict_with_upload_account_goes_to_review(self) -> None:
|
||||||
|
# own_account belongs to company B while the batch is uploaded for A.
|
||||||
|
row = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", expense="100.00",
|
||||||
|
)
|
||||||
|
# Simulate an upload account pointing at A.
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE import_batches SET upload_bank_account_id = ?
|
||||||
|
WHERE id = (SELECT b.id FROM import_batches b
|
||||||
|
JOIN sheet_batches s ON s.import_batch_id = b.id
|
||||||
|
JOIN source_rows r ON r.sheet_batch_id = s.id
|
||||||
|
WHERE r.id = ?)
|
||||||
|
""",
|
||||||
|
(self.account_a["id"], row),
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row])
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row)))
|
||||||
|
|
||||||
|
def test_upload_account_fallback_resolves_own(self) -> None:
|
||||||
|
row = self.add_row(
|
||||||
|
self.company_a, own_account=None,
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
UPDATE import_batches SET upload_bank_account_id = ?
|
||||||
|
WHERE id = (SELECT b.id FROM import_batches b
|
||||||
|
JOIN sheet_batches s ON s.import_batch_id = b.id
|
||||||
|
JOIN source_rows r ON r.sheet_batch_id = s.id
|
||||||
|
WHERE r.id = ?)
|
||||||
|
""",
|
||||||
|
(self.account_a["id"], row),
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row)))
|
||||||
|
|
||||||
|
def test_alias_mirror_m3_pairs(self) -> None:
|
||||||
|
# A's own account has an account alias; B's statement references the
|
||||||
|
# alias, so the mirror is proven through the approved alias (M3).
|
||||||
|
master_data.add_alias(
|
||||||
|
self.connection, self.account_a["id"], "account", "770077007700",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", summary="货款",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="770077007700", income="100.00", summary="货款",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
|
||||||
|
candidate = self.connection.execute(
|
||||||
|
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
|
||||||
|
).fetchone()
|
||||||
|
self.assertEqual("M3", candidate["rule_tier"])
|
||||||
|
|
||||||
|
|
||||||
|
class M3EvidenceTests(MatchingBase):
|
||||||
|
"""M3 requires positive reference or summary evidence; a missing reference
|
||||||
|
on either side is never treated as agreement (None == None is not equal)."""
|
||||||
|
|
||||||
|
def _alias_for_a(self) -> None:
|
||||||
|
master_data.add_alias(
|
||||||
|
self.connection, self.account_a["id"], "account", "770077007700",
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_both_references_empty_and_summaries_different_do_not_pair(self) -> None:
|
||||||
|
self._alias_for_a()
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", summary="货款A",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="770077007700", income="100.00", summary="货款B",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
self.assertIsNone(self.connection.execute(
|
||||||
|
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
|
||||||
|
).fetchone())
|
||||||
|
|
||||||
|
def test_single_sided_reference_is_not_reference_equality(self) -> None:
|
||||||
|
self._alias_for_a()
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", reference="R-ONLY-A",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="770077007700", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b)))
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
def test_both_references_empty_but_summary_equal_still_pairs_m3(self) -> None:
|
||||||
|
self._alias_for_a()
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", summary="货款",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="770077007700", income="100.00", summary="货款",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
|
||||||
|
candidate = self.connection.execute(
|
||||||
|
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
|
||||||
|
).fetchone()
|
||||||
|
self.assertEqual("M3", candidate["rule_tier"])
|
||||||
|
|
||||||
|
|
||||||
|
class EligibleViewTests(MatchingBase):
|
||||||
|
"""``eligible_intercompany_events``: single-sided intercompany events only
|
||||||
|
enter the B-44 output when locked; paired events are unaffected."""
|
||||||
|
|
||||||
|
def _insert_intercompany(self, *, pairing: str, locked: int) -> int:
|
||||||
|
now = utc_now()
|
||||||
|
with self.connection:
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"INSERT INTO canonical_transfer_events (lifecycle, created_at) VALUES ('active', ?)",
|
||||||
|
(now,),
|
||||||
|
)
|
||||||
|
event_id = int(cursor.lastrowid)
|
||||||
|
cursor = self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_match_decisions (
|
||||||
|
event_id, revision, classification, pairing, amount, currency,
|
||||||
|
effective_at, mode, rule_version, locked, created_at
|
||||||
|
) VALUES (?, 1, 'intercompany', ?, '100.00', 'CNY',
|
||||||
|
'2026-01-05T10:00:00', 'auto', 'transfer-match-v1', ?, ?)
|
||||||
|
""",
|
||||||
|
(event_id, pairing, locked, now),
|
||||||
|
)
|
||||||
|
decision_id = int(cursor.lastrowid)
|
||||||
|
for role, company_id in (("payer", self.company_a), ("payee", self.company_b)):
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_decision_participants (
|
||||||
|
decision_id, role, company_id, bank_account_id,
|
||||||
|
resolve_method, evidence, created_at
|
||||||
|
) VALUES (?, ?, ?, NULL, 'own_exact', '{}', ?)
|
||||||
|
""",
|
||||||
|
(decision_id, role, company_id, now),
|
||||||
|
)
|
||||||
|
self.connection.execute(
|
||||||
|
"INSERT INTO current_transfer_decisions (event_id, decision_id) VALUES (?, ?)",
|
||||||
|
(event_id, decision_id),
|
||||||
|
)
|
||||||
|
return event_id
|
||||||
|
|
||||||
|
def test_unlocked_single_intercompany_is_excluded(self) -> None:
|
||||||
|
self._insert_intercompany(pairing="single", locked=0)
|
||||||
|
self.assertEqual([], self.eligible())
|
||||||
|
|
||||||
|
def test_locked_single_intercompany_is_included(self) -> None:
|
||||||
|
self._insert_intercompany(pairing="single", locked=1)
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual("single", eligible[0]["pairing"])
|
||||||
|
self.assertEqual("100.00", eligible[0]["amount"])
|
||||||
|
|
||||||
|
def test_paired_intercompany_is_included_regardless_of_lock(self) -> None:
|
||||||
|
self._insert_intercompany(pairing="paired", locked=0)
|
||||||
|
self._insert_intercompany(pairing="paired", locked=1)
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(2, len(eligible))
|
||||||
|
self.assertTrue(all(item["pairing"] == "paired" for item in eligible))
|
||||||
|
|
||||||
|
|
||||||
|
class ManualLinkTests(MatchingBase):
|
||||||
|
def test_manual_link_locks_pair(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
matching.reconcile_rows(self.connection, [row_b])
|
||||||
|
event_id = self._event_of(row_a)
|
||||||
|
current_revision = self.current(row_a)["revision"]
|
||||||
|
result = matching.apply_manual_decision(
|
||||||
|
self.connection, event_id, "link_rows",
|
||||||
|
reason="人工核对后确认是同一笔",
|
||||||
|
expected_revision=current_revision,
|
||||||
|
request_key="link-1", actor=self.admin,
|
||||||
|
source_row_ids=[row_a, row_b],
|
||||||
|
)
|
||||||
|
self.assertTrue(result["locked"])
|
||||||
|
self.assertEqual("paired", result["pairing"])
|
||||||
|
# Auto reconcile never touches locked decisions.
|
||||||
|
stats = matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual(2, stats["skipped_locked"])
|
||||||
|
|
||||||
|
def test_manual_decision_requires_reason(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
with self.assertRaises(matching.MatchInputError):
|
||||||
|
matching.apply_manual_decision(
|
||||||
|
self.connection, self._event_of(row_a), "reverse",
|
||||||
|
reason=" ", expected_revision=None, request_key=None,
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_stale_expected_revision_conflicts(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a])
|
||||||
|
event_id = self._event_of(row_a)
|
||||||
|
with self.assertRaises(matching.MatchConflictError):
|
||||||
|
matching.apply_manual_decision(
|
||||||
|
self.connection, event_id, "reverse",
|
||||||
|
reason="测试", expected_revision=999, request_key=None,
|
||||||
|
actor=self.admin,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DecimalPrecisionTests(MatchingBase):
|
||||||
|
def test_equivalent_decimal_strings_match(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.0",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
def test_cent_difference_never_matches(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.01",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
def test_large_amount_precision(self) -> None:
|
||||||
|
amount = "99999999999999999999.99"
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense=amount,
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income=amount,
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
self.assertEqual(Decimal(amount), Decimal(eligible[0]["amount"]))
|
||||||
|
|
||||||
|
def test_currency_mismatch_never_matches(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00", currency="CNY",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00", currency="USD",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
self.assertEqual("internal_single", matching.exposed_status(self.current(row_a)))
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectionRebuildTests(MatchingBase):
|
||||||
|
def test_rebuild_matches_current_projection(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
matching.reconcile_rows(self.connection, [row_a, row_b])
|
||||||
|
before = [
|
||||||
|
(item["event_id"], item["decision_id"])
|
||||||
|
for item in self.connection.execute(
|
||||||
|
"SELECT * FROM current_transfer_decisions"
|
||||||
|
).fetchall()
|
||||||
|
]
|
||||||
|
claims_before = [
|
||||||
|
(item["source_row_id"], item["event_id"], item["decision_id"])
|
||||||
|
for item in self.connection.execute(
|
||||||
|
"SELECT * FROM transfer_observation_claims"
|
||||||
|
).fetchall()
|
||||||
|
]
|
||||||
|
matching.rebuild_current_projection(self.connection)
|
||||||
|
after = [
|
||||||
|
(item["event_id"], item["decision_id"])
|
||||||
|
for item in self.connection.execute(
|
||||||
|
"SELECT * FROM current_transfer_decisions"
|
||||||
|
).fetchall()
|
||||||
|
]
|
||||||
|
claims_after = [
|
||||||
|
(item["source_row_id"], item["event_id"], item["decision_id"])
|
||||||
|
for item in self.connection.execute(
|
||||||
|
"SELECT * FROM transfer_observation_claims"
|
||||||
|
).fetchall()
|
||||||
|
]
|
||||||
|
self.assertEqual(sorted(before), sorted(after))
|
||||||
|
self.assertEqual(sorted(claims_before), sorted(claims_after))
|
||||||
|
|
||||||
|
|
||||||
|
class ConcurrentReconcileTests(MatchingBase):
|
||||||
|
def test_concurrent_reconcile_creates_one_event(self) -> None:
|
||||||
|
row_a = self.add_row(
|
||||||
|
self.company_a, own_account="6222000000000001",
|
||||||
|
cp_account="6222000000000002", expense="100.00",
|
||||||
|
)
|
||||||
|
row_b = self.add_row(
|
||||||
|
self.company_b, own_account="6222000000000002",
|
||||||
|
cp_account="6222000000000001", income="100.00",
|
||||||
|
)
|
||||||
|
errors: list[Exception] = []
|
||||||
|
|
||||||
|
def run() -> None:
|
||||||
|
db = connect(self.db_path)
|
||||||
|
try:
|
||||||
|
matching.reconcile_rows(db, [row_a, row_b])
|
||||||
|
except Exception as exc: # pragma: no cover
|
||||||
|
errors.append(exc)
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
threads = [threading.Thread(target=run) for _ in range(2)]
|
||||||
|
for thread in threads:
|
||||||
|
thread.start()
|
||||||
|
for thread in threads:
|
||||||
|
thread.join()
|
||||||
|
self.assertEqual([], errors)
|
||||||
|
self.assertEqual(1, self.event_count())
|
||||||
|
eligible = self.eligible()
|
||||||
|
self.assertEqual(1, len(eligible))
|
||||||
|
claims = self.connection.execute(
|
||||||
|
"SELECT COUNT(*) AS n FROM transfer_observation_claims"
|
||||||
|
).fetchone()["n"]
|
||||||
|
self.assertEqual(2, claims)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,463 @@
|
|||||||
|
"""HTTP integration tests for the canonical transfer event APIs (B-43).
|
||||||
|
|
||||||
|
Covers the admin event list/detail, manual decisions and reconcile endpoints,
|
||||||
|
personal transit mapping workflow, upload-account persistence, and the
|
||||||
|
company-side read scoping with masked counterparty evidence. Uses a real
|
||||||
|
``ThreadingHTTPServer`` like ``test_server_auth``.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import tempfile
|
||||||
|
import threading
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from openpyxl import Workbook
|
||||||
|
|
||||||
|
from bank_importer.db import connect, migrate
|
||||||
|
|
||||||
|
import server
|
||||||
|
from test_server_auth import Client, as_json
|
||||||
|
|
||||||
|
BOOTSTRAP_PASSWORD = "BootAdmin123"
|
||||||
|
ADMIN_PASSWORD = "AdminPass123"
|
||||||
|
CASHIER_PASSWORD = "Cashier123"
|
||||||
|
|
||||||
|
CCB_HEADER = [
|
||||||
|
"客户账号", "账户名称", "交易时间", "借方发生额(支取)", "贷方发生额(收入)",
|
||||||
|
"余额", "币种", "对方户名", "对方账号", "对方开户机构", "摘要", "备注",
|
||||||
|
]
|
||||||
|
|
||||||
|
ACCOUNT_A = "6222000000000001"
|
||||||
|
ACCOUNT_B = "6222000000000002"
|
||||||
|
ACCOUNT_C = "6222000000000003"
|
||||||
|
|
||||||
|
|
||||||
|
def workbook_bytes(rows) -> bytes:
|
||||||
|
workbook = Workbook()
|
||||||
|
sheet = workbook.active
|
||||||
|
sheet.title = "正常流水"
|
||||||
|
sheet.append(CCB_HEADER)
|
||||||
|
for row in rows:
|
||||||
|
sheet.append(row)
|
||||||
|
buffer = io.BytesIO()
|
||||||
|
workbook.save(buffer)
|
||||||
|
return buffer.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
def outgoing(own: str, cp: str, amount: str, at: str = "2026-01-05 10:00:00"):
|
||||||
|
return [own, "测试公司", at, amount, "", "50000.00", "RMB", "对方", cp, "某银行", "货款", ""]
|
||||||
|
|
||||||
|
|
||||||
|
def incoming(own: str, cp: str, amount: str, at: str = "2026-01-05 11:00:00"):
|
||||||
|
return [own, "测试公司", at, "", amount, "50000.00", "RMB", "对方", cp, "某银行", "收款", ""]
|
||||||
|
|
||||||
|
|
||||||
|
class MatchingApiTests(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls) -> None:
|
||||||
|
cls.temp_dir = tempfile.TemporaryDirectory()
|
||||||
|
root = Path(cls.temp_dir.name)
|
||||||
|
cls.db_path = root / "app.db"
|
||||||
|
cls.storage = root / "files"
|
||||||
|
|
||||||
|
cls._old_db_path = server.DB_PATH
|
||||||
|
cls._old_storage = server.STORAGE_DIR
|
||||||
|
server.DB_PATH = cls.db_path
|
||||||
|
server.STORAGE_DIR = cls.storage
|
||||||
|
|
||||||
|
os.environ["APP_BOOTSTRAP_ADMIN_PASSWORD"] = BOOTSTRAP_PASSWORD
|
||||||
|
connection = connect(cls.db_path)
|
||||||
|
migrate(connection)
|
||||||
|
assert server.ensure_bootstrap_admin(connection) is None
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
class QuietHandler(server.AppHandler):
|
||||||
|
def log_message(self, *args) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
cls.httpd = server.ThreadingHTTPServer(("127.0.0.1", 0), QuietHandler)
|
||||||
|
cls.port = cls.httpd.server_address[1]
|
||||||
|
cls.thread = threading.Thread(target=cls.httpd.serve_forever, daemon=True)
|
||||||
|
cls.thread.start()
|
||||||
|
|
||||||
|
cls.admin = Client("127.0.0.1", cls.port)
|
||||||
|
status, _, data = cls.admin.post_json(
|
||||||
|
"/api/login",
|
||||||
|
{"username": "group-admin", "password": BOOTSTRAP_PASSWORD, "portal": "admin"},
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
status, _, data = cls.admin.post_json(
|
||||||
|
"/api/password/change",
|
||||||
|
{"old_password": BOOTSTRAP_PASSWORD, "new_password": ADMIN_PASSWORD},
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
|
||||||
|
cls.company_a = cls._create_company("甲公司", "cashier-a")
|
||||||
|
cls.company_b = cls._create_company("乙公司", "cashier-b")
|
||||||
|
cls.company_c = cls._create_company("丙公司", "cashier-c")
|
||||||
|
cls.cashier_a = cls._login_company("cashier-a", cls.company_a)
|
||||||
|
cls.cashier_b = cls._login_company("cashier-b", cls.company_b)
|
||||||
|
cls.cashier_c = cls._login_company("cashier-c", cls.company_c)
|
||||||
|
|
||||||
|
cls.account_a = cls._approve_account(cls.company_a, ACCOUNT_A)
|
||||||
|
cls.account_b = cls._approve_account(cls.company_b, ACCOUNT_B)
|
||||||
|
cls.account_c = cls._approve_account(cls.company_c, ACCOUNT_C)
|
||||||
|
|
||||||
|
# One A<->B matched event and one B<->C matched event.
|
||||||
|
cls._upload_and_confirm(cls.cashier_a, cls.company_a, [outgoing(ACCOUNT_A, ACCOUNT_B, "100.00")])
|
||||||
|
cls._upload_and_confirm(cls.cashier_b, cls.company_b, [incoming(ACCOUNT_B, ACCOUNT_A, "100.00")])
|
||||||
|
cls._upload_and_confirm(cls.cashier_b, cls.company_b, [outgoing(ACCOUNT_B, ACCOUNT_C, "200.00")])
|
||||||
|
cls._upload_and_confirm(cls.cashier_c, cls.company_c, [incoming(ACCOUNT_C, ACCOUNT_B, "200.00")])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create_company(cls, name: str, username: str) -> int:
|
||||||
|
status, _, data = cls.admin.post_json(
|
||||||
|
"/api/admin/companies",
|
||||||
|
{"name": name, "username": username},
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
cls.initial_passwords.setdefault(username, as_json(data)["initial_password"])
|
||||||
|
return as_json(data)["company_id"]
|
||||||
|
|
||||||
|
initial_passwords: dict[str, str] = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _login_company(cls, username: str, company_id: int) -> Client:
|
||||||
|
client = Client("127.0.0.1", cls.port)
|
||||||
|
initial = cls.initial_passwords[username]
|
||||||
|
status, _, data = client.post_json(
|
||||||
|
"/api/login", {"username": username, "password": initial, "portal": "company"}
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
status, _, data = client.post_json(
|
||||||
|
"/api/password/change",
|
||||||
|
{"old_password": initial, "new_password": CASHIER_PASSWORD},
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
return client
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _approve_account(cls, company_id: int, number: str) -> int:
|
||||||
|
# Build the account through company submission + admin review.
|
||||||
|
company_client = {
|
||||||
|
cls.company_a: cls.cashier_a,
|
||||||
|
cls.company_b: cls.cashier_b,
|
||||||
|
cls.company_c: cls.cashier_c,
|
||||||
|
}[company_id]
|
||||||
|
status, _, data = company_client.post_json(
|
||||||
|
"/api/company/accounts",
|
||||||
|
{"bank_name": "中信银行", "account_type": "基本户",
|
||||||
|
"account_number": number, "start_date": "2026-01-01"},
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
account_id = as_json(data)["account"]["id"]
|
||||||
|
status, _, data = cls.admin.post_json(
|
||||||
|
f"/api/admin/accounts/{account_id}/review",
|
||||||
|
{"decision": "approve", "reason": "测试启用",
|
||||||
|
"effective_from": "2026-01-01"},
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
return account_id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _upload_and_confirm(cls, client, company_id: int, rows) -> int:
|
||||||
|
content = workbook_bytes(rows)
|
||||||
|
status, _, data = cls.admin.post_multipart(
|
||||||
|
"/api/parse", {"company_id": str(company_id)}, "账单.xlsx", content
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
batch_id = as_json(data)["batch_id"]
|
||||||
|
status, _, data = client.get(f"/api/batches/{batch_id}/sheets")
|
||||||
|
assert status == 200, data
|
||||||
|
names = [s["sheet_name"] for s in as_json(data)["sheets"] if s["outcome"] == "parsed"]
|
||||||
|
status, _, data = client.post_json(
|
||||||
|
f"/api/batches/{batch_id}/confirm", {"sheets": names}
|
||||||
|
)
|
||||||
|
assert status == 200, data
|
||||||
|
return batch_id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls) -> None:
|
||||||
|
cls.httpd.shutdown()
|
||||||
|
cls.httpd.server_close()
|
||||||
|
server.DB_PATH = cls._old_db_path
|
||||||
|
server.STORAGE_DIR = cls._old_storage
|
||||||
|
os.environ.pop("APP_BOOTSTRAP_ADMIN_PASSWORD", None)
|
||||||
|
cls.temp_dir.cleanup()
|
||||||
|
|
||||||
|
def events(self, client) -> list[dict]:
|
||||||
|
status, _, data = client.get("/api/admin/transfer-events")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
return as_json(data)["events"]
|
||||||
|
|
||||||
|
def company_events(self, client) -> list[dict]:
|
||||||
|
status, _, data = client.get("/api/company/transfer-events")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
return as_json(data)["events"]
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Admin event views
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_admin_lists_matched_events(self) -> None:
|
||||||
|
events = self.events(self.admin)
|
||||||
|
matched = [e for e in events if e["status"] == "matched"]
|
||||||
|
self.assertGreaterEqual(len(matched), 2)
|
||||||
|
by_amount = {e["amount"]: e for e in matched}
|
||||||
|
self.assertEqual(self.company_a, by_amount["100.00"]["payer_company_id"])
|
||||||
|
self.assertEqual(self.company_b, by_amount["100.00"]["payee_company_id"])
|
||||||
|
self.assertEqual("paired", by_amount["100.00"]["pairing"])
|
||||||
|
self.assertEqual(2, by_amount["100.00"]["evidence_count"])
|
||||||
|
|
||||||
|
def test_admin_event_detail_has_history_and_observations(self) -> None:
|
||||||
|
events = self.events(self.admin)
|
||||||
|
event = next(e for e in events if e["status"] == "matched")
|
||||||
|
status, _, data = self.admin.get(f"/api/admin/transfer-events/{event['event_id']}")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
detail = as_json(data)["event"]
|
||||||
|
self.assertEqual("matched", detail["status"])
|
||||||
|
self.assertEqual(2, len(detail["observations"]))
|
||||||
|
self.assertTrue(detail["history"])
|
||||||
|
self.assertTrue(detail["candidates"])
|
||||||
|
|
||||||
|
def test_admin_match_exceptions(self) -> None:
|
||||||
|
status, _, data = self.admin.get("/api/admin/match-exceptions")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
self.assertIsInstance(as_json(data)["exceptions"], list)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Admin manual decisions and reconcile via API
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_admin_reconcile_by_batch_is_idempotent(self) -> None:
|
||||||
|
# Re-running reconcile on an already settled batch changes nothing.
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
"/api/admin/transfer-events/reconcile", {"batch_id": 1}
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
result = as_json(data)["matching"]
|
||||||
|
self.assertEqual(0, result["created_events"])
|
||||||
|
self.assertEqual(0, result["updated_events"])
|
||||||
|
|
||||||
|
def test_admin_confirm_single_and_reverse_via_api(self) -> None:
|
||||||
|
# A uploads its side only -> internal_single.
|
||||||
|
status, _, data = self.admin.post_multipart(
|
||||||
|
"/api/parse", {"company_id": str(self.company_a)},
|
||||||
|
"单边.xlsx", workbook_bytes([outgoing(ACCOUNT_A, ACCOUNT_B, "300.00", "2026-02-01 10:00:00")]),
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
batch_id = as_json(data)["batch_id"]
|
||||||
|
status, _, data = self.cashier_a.get(f"/api/batches/{batch_id}/sheets")
|
||||||
|
names = [s["sheet_name"] for s in as_json(data)["sheets"] if s["outcome"] == "parsed"]
|
||||||
|
status, _, data = self.cashier_a.post_json(
|
||||||
|
f"/api/batches/{batch_id}/confirm", {"sheets": names}
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
events = self.events(self.admin)
|
||||||
|
single = next(e for e in events if e["status"] == "internal_single" and e["amount"] == "300.00")
|
||||||
|
detail = self._admin_detail(single["event_id"])
|
||||||
|
revision = detail["revision"]
|
||||||
|
|
||||||
|
# Company users cannot write manual decisions.
|
||||||
|
status, _, data = self.cashier_a.post_json(
|
||||||
|
f"/api/admin/transfer-events/{single['event_id']}/decisions",
|
||||||
|
{"action": "reverse", "reason": "不应允许", "expected_revision": revision},
|
||||||
|
)
|
||||||
|
self.assertEqual(403, status, data)
|
||||||
|
|
||||||
|
# Admin confirms the single event based on evidence.
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
f"/api/admin/transfer-events/{single['event_id']}/decisions",
|
||||||
|
{"action": "assign_participant", "reason": "函证确认",
|
||||||
|
"expected_revision": revision, "request_key": "confirm-300",
|
||||||
|
"participant": {"role": "payee", "company_id": self.company_b}},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
decision = as_json(data)["decision"]
|
||||||
|
self.assertEqual("intercompany", decision["classification"])
|
||||||
|
self.assertTrue(decision["locked"])
|
||||||
|
|
||||||
|
# Replaying the same request key is idempotent.
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
f"/api/admin/transfer-events/{single['event_id']}/decisions",
|
||||||
|
{"action": "assign_participant", "reason": "函证确认",
|
||||||
|
"expected_revision": revision, "request_key": "confirm-300",
|
||||||
|
"participant": {"role": "payee", "company_id": self.company_b}},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
|
||||||
|
# Stale revision conflicts.
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
f"/api/admin/transfer-events/{single['event_id']}/decisions",
|
||||||
|
{"action": "reverse", "reason": "撤销", "expected_revision": revision},
|
||||||
|
)
|
||||||
|
self.assertEqual(409, status, data)
|
||||||
|
|
||||||
|
def _admin_detail(self, event_id: int) -> dict:
|
||||||
|
status, _, data = self.admin.get(f"/api/admin/transfer-events/{event_id}")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
return as_json(data)["event"]
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Company scope and masking
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_company_sees_only_events_it_participates_in(self) -> None:
|
||||||
|
events = self.company_events(self.cashier_a)
|
||||||
|
self.assertTrue(events)
|
||||||
|
for event in events:
|
||||||
|
self.assertEqual(self.company_a, event["own_company_id"])
|
||||||
|
matched = [e for e in events if e["status"] == "matched"]
|
||||||
|
self.assertTrue(matched)
|
||||||
|
self.assertEqual(
|
||||||
|
{"乙公司"},
|
||||||
|
{e["counterparty_company_name"] for e in matched},
|
||||||
|
)
|
||||||
|
# B<->C event is invisible to A.
|
||||||
|
status, _, data = self.cashier_a.get("/api/company/transfer-events")
|
||||||
|
bc_events = [
|
||||||
|
e for e in as_json(data)["events"]
|
||||||
|
if e["counterparty_company_name"] == "丙公司"
|
||||||
|
]
|
||||||
|
self.assertEqual([], bc_events)
|
||||||
|
|
||||||
|
def test_company_detail_masks_counterparty_and_own_rows_only(self) -> None:
|
||||||
|
events = self.company_events(self.cashier_a)
|
||||||
|
event = next(e for e in events if e["status"] == "matched")
|
||||||
|
status, _, data = self.cashier_a.get(
|
||||||
|
f"/api/company/transfer-events/{event['event_id']}"
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
detail = as_json(data)["event"]
|
||||||
|
self.assertEqual("乙公司", detail["counterparty"]["company_name"])
|
||||||
|
self.assertTrue(detail["counterparty"].get("account_number_masked", "").startswith("****"))
|
||||||
|
# The counterparty's full account number never leaves the server.
|
||||||
|
self.assertNotIn(ACCOUNT_B, json.dumps(detail, ensure_ascii=False))
|
||||||
|
# Only A's own observation rows are exposed.
|
||||||
|
self.assertEqual(1, len(detail["observations"]))
|
||||||
|
observation = detail["observations"][0]
|
||||||
|
self.assertTrue(observation["own_account_masked"].startswith("****"))
|
||||||
|
self.assertEqual(self.company_a, observation.get("batch_company_id"))
|
||||||
|
|
||||||
|
def test_company_cannot_read_event_it_does_not_participate_in(self) -> None:
|
||||||
|
# The B<->C event id comes from B's own list; A probing it returns 404.
|
||||||
|
status, _, data = self.cashier_b.get("/api/company/transfer-events")
|
||||||
|
bc_event_ids = [
|
||||||
|
e["event_id"] for e in as_json(data)["events"]
|
||||||
|
if e["counterparty_company_name"] == "丙公司"
|
||||||
|
]
|
||||||
|
self.assertTrue(bc_event_ids)
|
||||||
|
for event_id in bc_event_ids:
|
||||||
|
status, _, data = self.cashier_a.get(f"/api/company/transfer-events/{event_id}")
|
||||||
|
self.assertEqual(404, status, data)
|
||||||
|
status, _, data = self.cashier_a.get(f"/api/admin/transfer-events/{event_id}")
|
||||||
|
self.assertEqual(403, status, data)
|
||||||
|
|
||||||
|
def test_company_match_exceptions_scoped_to_own_company(self) -> None:
|
||||||
|
status, _, data = self.admin.post_multipart(
|
||||||
|
"/api/parse", {"company_id": str(self.company_a)},
|
||||||
|
"未决.xlsx",
|
||||||
|
workbook_bytes([outgoing(ACCOUNT_A, "9999999999999999", "77.00", "2026-02-05 10:00:00")]),
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
batch_id = as_json(data)["batch_id"]
|
||||||
|
status, _, data = self.cashier_a.get(f"/api/batches/{batch_id}/sheets")
|
||||||
|
names = [s["sheet_name"] for s in as_json(data)["sheets"] if s["outcome"] == "parsed"]
|
||||||
|
status, _, data = self.cashier_a.post_json(
|
||||||
|
f"/api/batches/{batch_id}/confirm", {"sheets": names}
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
|
||||||
|
status, _, data = self.cashier_a.get("/api/company/match-exceptions")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
mine = [e for e in as_json(data)["exceptions"] if e["amount"] == "77.00"]
|
||||||
|
self.assertEqual(1, len(mine))
|
||||||
|
self.assertEqual("unresolved", mine[0]["status"])
|
||||||
|
|
||||||
|
status, _, data = self.cashier_b.get("/api/company/match-exceptions")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
self.assertEqual(
|
||||||
|
[],
|
||||||
|
[e for e in as_json(data)["exceptions"] if e["amount"] == "77.00"],
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_company_forbidden_on_admin_event_endpoints(self) -> None:
|
||||||
|
for call in (
|
||||||
|
lambda: self.cashier_a.get("/api/admin/transfer-events"),
|
||||||
|
lambda: self.cashier_a.get("/api/admin/match-exceptions"),
|
||||||
|
lambda: self.cashier_a.post_json(
|
||||||
|
"/api/admin/transfer-events/reconcile", {"batch_id": 1}
|
||||||
|
),
|
||||||
|
lambda: self.cashier_a.post_json(
|
||||||
|
"/api/admin/personal-transit-mappings", {}
|
||||||
|
),
|
||||||
|
lambda: self.cashier_a.get("/api/admin/personal-transit-mappings"),
|
||||||
|
):
|
||||||
|
status, _, data = call()
|
||||||
|
self.assertEqual(403, status, data)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Personal transit mappings
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_personal_transit_mapping_workflow(self) -> None:
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
"/api/admin/personal-transit-mappings",
|
||||||
|
{"account_number": "880088008800", "account_name": "张个人",
|
||||||
|
"represented_company_id": self.company_b,
|
||||||
|
"allowed_direction": "incoming", "effective_from": "2026-01-01"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
mapping_id = as_json(data)["mapping"]["id"]
|
||||||
|
self.assertEqual("pending", as_json(data)["mapping"]["status"])
|
||||||
|
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
f"/api/admin/personal-transit-mappings/{mapping_id}/review",
|
||||||
|
{"decision": "approve", "reason": "资料齐全", "effective_from": "2026-01-01"},
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
self.assertEqual("active", as_json(data)["mapping"]["status"])
|
||||||
|
|
||||||
|
status, _, data = self.admin.get("/api/admin/personal-transit-mappings")
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
mappings = as_json(data)["mappings"]
|
||||||
|
self.assertTrue(any(m["id"] == mapping_id for m in mappings))
|
||||||
|
|
||||||
|
# Duplicate account number conflicts.
|
||||||
|
status, _, data = self.admin.post_json(
|
||||||
|
"/api/admin/personal-transit-mappings",
|
||||||
|
{"account_number": "880088008800", "account_name": "张个人",
|
||||||
|
"represented_company_id": self.company_b, "allowed_direction": "both"},
|
||||||
|
)
|
||||||
|
self.assertEqual(409, status, data)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Upload account persistence
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_upload_persists_approved_bank_account(self) -> None:
|
||||||
|
content = workbook_bytes([outgoing(ACCOUNT_A, ACCOUNT_B, "55.00", "2026-03-01 10:00:00")])
|
||||||
|
status, _, data = self.cashier_a.post_multipart(
|
||||||
|
"/api/parse", {"bank_account_id": str(self.account_a)},
|
||||||
|
"带账户.xlsx", content,
|
||||||
|
)
|
||||||
|
self.assertEqual(200, status, data)
|
||||||
|
batch_id = as_json(data)["batch_id"]
|
||||||
|
connection = connect(self.db_path)
|
||||||
|
try:
|
||||||
|
row = connection.execute(
|
||||||
|
"SELECT upload_bank_account_id FROM import_batches WHERE id = ?",
|
||||||
|
(batch_id,),
|
||||||
|
).fetchone()
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
self.assertEqual(self.account_a, row["upload_bank_account_id"])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
+127
-4
@@ -41,7 +41,7 @@ class PersistenceTestCase(unittest.TestCase):
|
|||||||
class MigrationTests(PersistenceTestCase):
|
class MigrationTests(PersistenceTestCase):
|
||||||
def test_migrate_creates_schema_and_is_idempotent(self) -> None:
|
def test_migrate_creates_schema_and_is_idempotent(self) -> None:
|
||||||
first = applied_versions(self.connection)
|
first = applied_versions(self.connection)
|
||||||
self.assertEqual([1, 2, 3, 4], first)
|
self.assertEqual([1, 2, 3, 4, 5], first)
|
||||||
self.assertEqual([], migrate(self.connection))
|
self.assertEqual([], migrate(self.connection))
|
||||||
self.assertEqual(first, applied_versions(self.connection))
|
self.assertEqual(first, applied_versions(self.connection))
|
||||||
tables = {
|
tables = {
|
||||||
@@ -65,19 +65,142 @@ class MigrationTests(PersistenceTestCase):
|
|||||||
"sessions",
|
"sessions",
|
||||||
"login_attempts",
|
"login_attempts",
|
||||||
"audit_log",
|
"audit_log",
|
||||||
|
"personal_transit_mappings",
|
||||||
|
"canonical_transfer_events",
|
||||||
|
"transfer_match_decisions",
|
||||||
|
"transfer_decision_observations",
|
||||||
|
"transfer_decision_participants",
|
||||||
|
"transfer_match_candidates",
|
||||||
|
"current_transfer_decisions",
|
||||||
|
"transfer_observation_claims",
|
||||||
"schema_migrations",
|
"schema_migrations",
|
||||||
):
|
):
|
||||||
self.assertIn(table, tables)
|
self.assertIn(table, tables)
|
||||||
|
|
||||||
def test_rollback_removes_schema_and_forward_rebuilds_it(self) -> None:
|
def test_rollback_removes_schema_and_forward_rebuilds_it(self) -> None:
|
||||||
self.assertEqual([4, 3, 2, 1], rollback(self.connection, 0))
|
self.assertEqual([5, 4, 3, 2, 1], rollback(self.connection, 0))
|
||||||
self.assertEqual([], applied_versions(self.connection))
|
self.assertEqual([], applied_versions(self.connection))
|
||||||
remaining = self.connection.execute(
|
remaining = self.connection.execute(
|
||||||
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'source_rows'"
|
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'source_rows'"
|
||||||
).fetchone()
|
).fetchone()
|
||||||
self.assertIsNone(remaining)
|
self.assertIsNone(remaining)
|
||||||
self.assertEqual([1, 2, 3, 4], migrate(self.connection))
|
self.assertEqual([1, 2, 3, 4, 5], migrate(self.connection))
|
||||||
self.assertEqual([1, 2, 3, 4], applied_versions(self.connection))
|
self.assertEqual([1, 2, 3, 4, 5], applied_versions(self.connection))
|
||||||
|
|
||||||
|
def test_rollback_to_4_keeps_bank_evidence_and_drops_event_layer(self) -> None:
|
||||||
|
self.import_sample()
|
||||||
|
row_count = self.connection.execute(
|
||||||
|
"SELECT COUNT(*) AS n FROM source_rows"
|
||||||
|
).fetchone()["n"]
|
||||||
|
self.assertGreater(row_count, 0)
|
||||||
|
self.assertEqual([5], rollback(self.connection, 4))
|
||||||
|
# The pre-migration evidence and schema are untouched.
|
||||||
|
self.assertEqual(
|
||||||
|
row_count,
|
||||||
|
self.connection.execute("SELECT COUNT(*) AS n FROM source_rows").fetchone()["n"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
"parsed",
|
||||||
|
self.connection.execute(
|
||||||
|
"SELECT status FROM import_batches LIMIT 1"
|
||||||
|
).fetchone()["status"],
|
||||||
|
)
|
||||||
|
remaining = self.connection.execute(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'transfer_match_decisions'"
|
||||||
|
).fetchone()
|
||||||
|
self.assertIsNone(remaining)
|
||||||
|
|
||||||
|
def test_event_layer_views_exist_after_migration(self) -> None:
|
||||||
|
view = self.connection.execute(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type = 'view' AND name = 'eligible_intercompany_events'"
|
||||||
|
).fetchone()
|
||||||
|
self.assertIsNotNone(view)
|
||||||
|
|
||||||
|
def test_decision_log_immutability_triggers(self) -> None:
|
||||||
|
self.import_sample()
|
||||||
|
source_row_id = self.connection.execute(
|
||||||
|
"SELECT id FROM source_rows LIMIT 1"
|
||||||
|
).fetchone()["id"]
|
||||||
|
with self.connection:
|
||||||
|
self.connection.execute(
|
||||||
|
"INSERT INTO canonical_transfer_events (lifecycle, created_at) VALUES ('active', ?)",
|
||||||
|
(utc_now(),),
|
||||||
|
)
|
||||||
|
event_id = self.connection.execute(
|
||||||
|
"SELECT id FROM canonical_transfer_events LIMIT 1"
|
||||||
|
).fetchone()["id"]
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_match_decisions (
|
||||||
|
event_id, revision, classification, pairing, mode, rule_version,
|
||||||
|
locked, created_at
|
||||||
|
) VALUES (?, 1, 'unresolved', 'not_applicable', 'auto', 'transfer-match-v1', 0, ?)
|
||||||
|
""",
|
||||||
|
(event_id, utc_now()),
|
||||||
|
)
|
||||||
|
decision_id = self.connection.execute(
|
||||||
|
"SELECT id FROM transfer_match_decisions LIMIT 1"
|
||||||
|
).fetchone()["id"]
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_match_candidates (
|
||||||
|
decision_id, source_row_id, rule_tier, rule_version, created_at
|
||||||
|
) VALUES (?, ?, 'R1', 'transfer-match-v1', ?)
|
||||||
|
""",
|
||||||
|
(decision_id, source_row_id, utc_now()),
|
||||||
|
)
|
||||||
|
for statement in (
|
||||||
|
"UPDATE transfer_match_decisions SET classification = 'external'",
|
||||||
|
"DELETE FROM transfer_match_decisions",
|
||||||
|
"UPDATE transfer_match_candidates SET rule_tier = 'M1'",
|
||||||
|
"DELETE FROM transfer_match_candidates",
|
||||||
|
"DELETE FROM canonical_transfer_events",
|
||||||
|
):
|
||||||
|
with self.subTest(statement=statement):
|
||||||
|
with self.assertRaises(sqlite3.IntegrityError):
|
||||||
|
self.connection.execute(statement)
|
||||||
|
self.connection.rollback()
|
||||||
|
|
||||||
|
def test_observation_claims_source_row_is_unique(self) -> None:
|
||||||
|
self.import_sample()
|
||||||
|
source_row_id = self.connection.execute(
|
||||||
|
"SELECT id FROM source_rows LIMIT 1"
|
||||||
|
).fetchone()["id"]
|
||||||
|
with self.connection:
|
||||||
|
self.connection.execute(
|
||||||
|
"INSERT INTO canonical_transfer_events (lifecycle, created_at) VALUES ('active', ?)",
|
||||||
|
(utc_now(),),
|
||||||
|
)
|
||||||
|
event_id = self.connection.execute(
|
||||||
|
"SELECT id FROM canonical_transfer_events LIMIT 1"
|
||||||
|
).fetchone()["id"]
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_match_decisions (
|
||||||
|
event_id, revision, classification, pairing, mode, locked, created_at
|
||||||
|
) VALUES (?, 1, 'unresolved', 'not_applicable', 'auto', 0, ?)
|
||||||
|
""",
|
||||||
|
(event_id, utc_now()),
|
||||||
|
)
|
||||||
|
decision_id = self.connection.execute(
|
||||||
|
"SELECT id FROM transfer_match_decisions LIMIT 1"
|
||||||
|
).fetchone()["id"]
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_observation_claims (source_row_id, event_id, decision_id)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
""",
|
||||||
|
(source_row_id, event_id, decision_id),
|
||||||
|
)
|
||||||
|
with self.assertRaises(sqlite3.IntegrityError):
|
||||||
|
self.connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO transfer_observation_claims (source_row_id, event_id, decision_id)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
""",
|
||||||
|
(source_row_id, event_id, decision_id),
|
||||||
|
)
|
||||||
|
self.connection.rollback()
|
||||||
|
|
||||||
|
|
||||||
class ImportPersistenceTests(PersistenceTestCase):
|
class ImportPersistenceTests(PersistenceTestCase):
|
||||||
|
|||||||
+1017
-185
File diff suppressed because it is too large
Load Diff
+1163
-422
File diff suppressed because it is too large
Load Diff
+912
-151
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,693 @@
|
|||||||
|
/* ─── 金牛实业资金往来管理系统 · 共享样式 ─────────────────────────────
|
||||||
|
方向:tech-utility(数据密集型工具)。六枚基础 token 绑定设计方向,
|
||||||
|
状态色仅在此 :root 块内以 oklch 派生,组件一律引用变量。 */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--bg: oklch(98% 0.005 250);
|
||||||
|
--surface: oklch(100% 0 0);
|
||||||
|
--fg: oklch(22% 0.02 240);
|
||||||
|
--muted: oklch(50% 0.018 240);
|
||||||
|
--border: oklch(90% 0.008 240);
|
||||||
|
--accent: oklch(58% 0.16 145);
|
||||||
|
|
||||||
|
/* 状态色 — 仅此处定义 */
|
||||||
|
--success: oklch(55% 0.14 150);
|
||||||
|
--warn: oklch(62% 0.14 70);
|
||||||
|
--danger: oklch(55% 0.18 25);
|
||||||
|
--info: oklch(52% 0.12 240);
|
||||||
|
|
||||||
|
--accent-soft: color-mix(in oklch, var(--accent) 12%, transparent);
|
||||||
|
--success-soft: color-mix(in oklch, var(--success) 12%, transparent);
|
||||||
|
--warn-soft: color-mix(in oklch, var(--warn) 14%, transparent);
|
||||||
|
--danger-soft: color-mix(in oklch, var(--danger) 11%, transparent);
|
||||||
|
--info-soft: color-mix(in oklch, var(--info) 10%, transparent);
|
||||||
|
--fg-soft: color-mix(in oklch, var(--fg) 5%, transparent);
|
||||||
|
|
||||||
|
--font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
|
||||||
|
--font-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
|
||||||
|
|
||||||
|
--radius: 8px;
|
||||||
|
--radius-lg: 12px;
|
||||||
|
--side-w: 232px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── reset ─────────────────────────────────────────────────────── */
|
||||||
|
*, *::before, *::after { box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--fg);
|
||||||
|
font-family: var(--font-body);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.55;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
img, svg { display: block; }
|
||||||
|
a { color: inherit; text-decoration: none; }
|
||||||
|
button { font: inherit; cursor: pointer; }
|
||||||
|
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
|
||||||
|
p { margin: 0; }
|
||||||
|
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 应用外壳 ──────────────────────────────────────────────────── */
|
||||||
|
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
background: var(--surface);
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
.side-brand {
|
||||||
|
padding: 18px 20px 16px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.side-brand .brand-name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
|
||||||
|
.side-brand .brand-sub { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 3px; letter-spacing: 0.02em; }
|
||||||
|
.side-role {
|
||||||
|
display: inline-flex; align-items: center; gap: 6px;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 3px 9px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--accent);
|
||||||
|
font-size: 11px; font-weight: 600;
|
||||||
|
}
|
||||||
|
.side-role.company { background: var(--info-soft); color: var(--info); }
|
||||||
|
|
||||||
|
.side-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
|
||||||
|
.side-nav .nav-group { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.08em; color: var(--muted); padding: 14px 10px 6px; }
|
||||||
|
.side-nav a {
|
||||||
|
display: flex; align-items: center; gap: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 13.5px;
|
||||||
|
margin-bottom: 1px;
|
||||||
|
}
|
||||||
|
.side-nav a svg { width: 16px; height: 16px; flex: none; }
|
||||||
|
.side-nav a:hover { color: var(--fg); background: var(--fg-soft); }
|
||||||
|
.side-nav a.active {
|
||||||
|
color: var(--fg);
|
||||||
|
background: var(--accent-soft);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.side-nav a.active svg { color: var(--accent); }
|
||||||
|
.side-nav a .nav-badge {
|
||||||
|
margin-left: auto;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 10.5px;
|
||||||
|
padding: 1px 7px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--danger-soft);
|
||||||
|
color: var(--danger);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.side-foot { border-top: 1px solid var(--border); padding: 12px 16px; }
|
||||||
|
.side-foot .user-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
||||||
|
.side-foot .user-row > div { min-width: 0; }
|
||||||
|
.side-foot .avatar {
|
||||||
|
width: 30px; height: 30px; border-radius: 50%;
|
||||||
|
background: var(--fg); color: var(--surface);
|
||||||
|
display: grid; place-items: center;
|
||||||
|
font-size: 12px; font-weight: 600;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.side-foot .user-name { font-size: 13px; font-weight: 600; white-space: nowrap; }
|
||||||
|
.side-foot .user-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.side-foot .logout { margin-left: auto; color: var(--muted); font-size: 12px; padding: 4px 6px; border-radius: 6px; background: none; border: 0; flex: none; white-space: nowrap; }
|
||||||
|
.side-foot .logout:hover { color: var(--danger); background: var(--danger-soft); }
|
||||||
|
|
||||||
|
.main { min-width: 0; display: flex; flex-direction: column; }
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
position: sticky; top: 0; z-index: 20;
|
||||||
|
background: color-mix(in oklch, var(--bg) 88%, transparent);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 12px 28px;
|
||||||
|
display: flex; align-items: center; gap: 16px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.topbar .crumb { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
|
||||||
|
.topbar .crumb b { color: var(--fg); font-weight: 600; }
|
||||||
|
.topbar .topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
|
||||||
|
|
||||||
|
.content { padding: 24px 28px 64px; max-width: 1440px; width: 100%; margin-inline: auto; }
|
||||||
|
|
||||||
|
/* ─── 页头 ──────────────────────────────────────────────────────── */
|
||||||
|
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
|
||||||
|
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; }
|
||||||
|
.page-head .page-sub { color: var(--muted); font-size: 13px; margin-top: 5px; max-width: 72ch; }
|
||||||
|
.page-head .page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||||
|
|
||||||
|
/* ─── 按钮 ──────────────────────────────────────────────────────── */
|
||||||
|
.btn {
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
||||||
|
padding: 8px 14px;
|
||||||
|
min-height: 34px;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--fg);
|
||||||
|
font-size: 13px; font-weight: 550;
|
||||||
|
transition: background 0.12s ease, border-color 0.12s ease;
|
||||||
|
}
|
||||||
|
.btn:hover { border-color: color-mix(in oklch, var(--fg) 40%, var(--border)); background: var(--fg-soft); }
|
||||||
|
.btn:active { transform: translateY(1px); }
|
||||||
|
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
|
||||||
|
.btn-primary:hover { background: color-mix(in oklch, var(--accent) 88%, black); border-color: color-mix(in oklch, var(--accent) 88%, black); }
|
||||||
|
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
|
||||||
|
.btn-ghost:hover { color: var(--fg); background: var(--fg-soft); }
|
||||||
|
.btn-danger { color: var(--danger); border-color: color-mix(in oklch, var(--danger) 35%, var(--border)); }
|
||||||
|
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
|
||||||
|
.btn-sm { padding: 4px 10px; min-height: 26px; font-size: 12px; border-radius: 6px; }
|
||||||
|
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
|
||||||
|
.btn-primary[disabled] { opacity: 1; background: var(--fg-soft); border-color: var(--border); color: var(--muted); }
|
||||||
|
|
||||||
|
/* ─── 卡片 ──────────────────────────────────────────────────────── */
|
||||||
|
.card {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
padding: 18px 20px;
|
||||||
|
}
|
||||||
|
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
|
||||||
|
.card-title { font-size: 14px; font-weight: 650; letter-spacing: -0.005em; }
|
||||||
|
.card-title .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }
|
||||||
|
|
||||||
|
/* ─── 指标卡 ────────────────────────────────────────────────────── */
|
||||||
|
.stat-card { padding: 16px 18px; }
|
||||||
|
.stat-card .stat-label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
|
||||||
|
.stat-card .stat-value {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
font-size: 26px; font-weight: 650;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
.stat-card .stat-value .unit { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 2px; }
|
||||||
|
.stat-card .stat-foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
|
||||||
|
.stat-card.alert .stat-value { color: var(--danger); }
|
||||||
|
.stat-card.warn .stat-value { color: var(--warn); }
|
||||||
|
.stat-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
|
||||||
|
.stat-dot.danger { background: var(--danger); }
|
||||||
|
.stat-dot.warn { background: var(--warn); }
|
||||||
|
.stat-dot.success { background: var(--success); }
|
||||||
|
.stat-dot.info { background: var(--info); }
|
||||||
|
|
||||||
|
/* ─── 栅格与布局工具 ────────────────────────────────────────────── */
|
||||||
|
.grid { display: grid; gap: 14px; }
|
||||||
|
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||||
|
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||||
|
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||||
|
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
|
||||||
|
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
|
||||||
|
.grid-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); align-items: start; }
|
||||||
|
.grid-3-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
|
||||||
|
.row { display: flex; align-items: center; gap: 10px; }
|
||||||
|
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||||
|
.stack { display: flex; flex-direction: column; gap: 14px; }
|
||||||
|
.muted { color: var(--muted); }
|
||||||
|
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
|
||||||
|
.meta { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
|
||||||
|
.mt-0 { margin-top: 0; }
|
||||||
|
|
||||||
|
@media (max-width: 1100px) {
|
||||||
|
.grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||||
|
.grid-3, .grid-2-1, .grid-1-2, .grid-3-2 { grid-template-columns: minmax(0, 1fr); }
|
||||||
|
}
|
||||||
|
@media (max-width: 860px) {
|
||||||
|
.shell { grid-template-columns: 1fr; }
|
||||||
|
.sidebar { position: static; height: auto; }
|
||||||
|
.grid-2 { grid-template-columns: 1fr; }
|
||||||
|
.content { padding: 16px 16px 48px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 数据表 ────────────────────────────────────────────────────── */
|
||||||
|
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
|
||||||
|
.ds-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
|
||||||
|
.ds-table th, .ds-table td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
||||||
|
.ds-table th {
|
||||||
|
color: var(--muted); font-weight: 550;
|
||||||
|
font-family: var(--font-mono); font-size: 11px;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
background: var(--bg);
|
||||||
|
position: sticky; top: 0;
|
||||||
|
}
|
||||||
|
.ds-table tbody tr:hover { background: var(--fg-soft); }
|
||||||
|
.ds-table tbody tr:last-child td { border-bottom: 0; }
|
||||||
|
.ds-table .num-col { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
|
||||||
|
.ds-table td.wrap, .ds-table th.wrap { white-space: normal; min-width: 180px; }
|
||||||
|
.ds-table .cell-main { font-weight: 550; }
|
||||||
|
.ds-table .cell-sub { display: block; font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 1px; }
|
||||||
|
.ds-table tr.clickable { cursor: pointer; }
|
||||||
|
.ds-table .amt-in { color: var(--success); }
|
||||||
|
.ds-table .amt-out { color: var(--danger); }
|
||||||
|
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
|
||||||
|
|
||||||
|
/* ─── 徽章 / 状态 ───────────────────────────────────────────────── */
|
||||||
|
.pill {
|
||||||
|
display: inline-flex; align-items: center; gap: 5px;
|
||||||
|
padding: 2px 9px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 11.5px; font-weight: 600;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
|
||||||
|
.pill-success { background: var(--success-soft); color: var(--success); }
|
||||||
|
.pill-warn { background: var(--warn-soft); color: color-mix(in oklch, var(--warn) 80%, black); }
|
||||||
|
.pill-danger { background: var(--danger-soft); color: var(--danger); }
|
||||||
|
.pill-info { background: var(--info-soft); color: var(--info); }
|
||||||
|
.pill-muted { background: var(--fg-soft); color: var(--muted); }
|
||||||
|
.pill-accent { background: var(--accent-soft); color: var(--accent); }
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
display: inline-flex; align-items: center;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 筛选栏与表单 ──────────────────────────────────────────────── */
|
||||||
|
.filters {
|
||||||
|
display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
|
||||||
|
padding: 14px 16px;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
|
||||||
|
.field > label { font-size: 12px; color: var(--muted); font-weight: 550; }
|
||||||
|
.input, .select, .textarea, .field .input, .field .select, .field .textarea {
|
||||||
|
padding: 7px 11px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--fg);
|
||||||
|
font: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
min-height: 34px;
|
||||||
|
}
|
||||||
|
.input:focus, .select:focus, .textarea:focus, .field .input:focus, .field .select:focus, .field .textarea:focus {
|
||||||
|
outline: 2px solid var(--accent-soft);
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
.input.num-input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
|
||||||
|
.textarea { min-height: 84px; resize: vertical; line-height: 1.55; }
|
||||||
|
.field .hint { font-size: 11.5px; color: var(--muted); }
|
||||||
|
.field .hint.error { color: var(--danger); }
|
||||||
|
|
||||||
|
/* ─── Tabs ──────────────────────────────────────────────────────── */
|
||||||
|
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
|
||||||
|
.tabs button {
|
||||||
|
background: none; border: 0;
|
||||||
|
padding: 9px 14px;
|
||||||
|
font-size: 13px; font-weight: 550;
|
||||||
|
color: var(--muted);
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
margin-bottom: -1px;
|
||||||
|
flex: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.tabs button:hover { color: var(--fg); }
|
||||||
|
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }
|
||||||
|
.tabs button .tab-count {
|
||||||
|
font-family: var(--font-mono); font-size: 10.5px;
|
||||||
|
padding: 1px 6px; border-radius: 999px;
|
||||||
|
background: var(--fg-soft); color: var(--muted);
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
.tabs button.active .tab-count { background: var(--accent-soft); color: var(--accent); }
|
||||||
|
|
||||||
|
/* ─── 时间轴(账期) ─────────────────────────────────────────────── */
|
||||||
|
.timeline { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); padding: 0; }
|
||||||
|
.tl-cell { flex: 1; padding: 12px 10px; border-right: 1px solid var(--border); text-align: center; min-width: 0; }
|
||||||
|
.tl-cell:last-child { border-right: 0; }
|
||||||
|
.tl-cell .tl-month { font-family: var(--font-mono); font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
|
||||||
|
.tl-cell .tl-state { font-size: 12px; font-weight: 600; margin-top: 4px; display: flex; align-items: center; justify-content: center; gap: 5px; }
|
||||||
|
.tl-cell.closed { background: var(--fg-soft); }
|
||||||
|
.tl-cell.closed .tl-state { color: var(--muted); }
|
||||||
|
.tl-cell.current { background: var(--accent-soft); }
|
||||||
|
.tl-cell.current .tl-state { color: var(--accent); }
|
||||||
|
.tl-cell.open .tl-state { color: var(--fg); }
|
||||||
|
|
||||||
|
/* ─── 进度条 ────────────────────────────────────────────────────── */
|
||||||
|
.progress { height: 6px; border-radius: 999px; background: var(--fg-soft); overflow: hidden; }
|
||||||
|
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
|
||||||
|
.progress.warn > span { background: var(--warn); }
|
||||||
|
.progress.danger > span { background: var(--danger); }
|
||||||
|
|
||||||
|
/* ─── 列表行(快查 / 待办 / 通知) ────────────────────────────────── */
|
||||||
|
.list-row {
|
||||||
|
display: flex; align-items: center; gap: 12px;
|
||||||
|
padding: 10px 4px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.list-row:last-child { border-bottom: 0; }
|
||||||
|
.list-row .lr-main { min-width: 0; flex: 1; }
|
||||||
|
.list-row .lr-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.list-row .lr-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
|
||||||
|
.list-row .lr-side { text-align: right; flex: none; }
|
||||||
|
[data-detail] { cursor: pointer; }
|
||||||
|
.list-row[data-detail]:hover { background: var(--fg-soft); }
|
||||||
|
.list-row[data-detail] { margin-inline: -4px; padding-inline: 4px; border-radius: var(--radius); }
|
||||||
|
|
||||||
|
/* ─── 弹窗 ──────────────────────────────────────────────────────── */
|
||||||
|
.modal-backdrop {
|
||||||
|
position: fixed; inset: 0; z-index: 50;
|
||||||
|
background: color-mix(in oklch, var(--fg) 45%, transparent);
|
||||||
|
display: none;
|
||||||
|
align-items: center; justify-content: center;
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
.modal-backdrop.open { display: flex; }
|
||||||
|
.modal {
|
||||||
|
background: var(--surface);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
width: 100%; max-width: 560px;
|
||||||
|
max-height: 86vh; overflow-y: auto;
|
||||||
|
padding: 22px 24px;
|
||||||
|
box-shadow: 0 18px 50px color-mix(in oklch, var(--fg) 25%, transparent);
|
||||||
|
}
|
||||||
|
.modal.wide { max-width: 760px; }
|
||||||
|
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
|
||||||
|
.modal-title { font-size: 16px; font-weight: 700; }
|
||||||
|
.modal-close { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 4px 8px; border-radius: 6px; }
|
||||||
|
.modal-close:hover { background: var(--fg-soft); color: var(--fg); }
|
||||||
|
.modal-sub { font-size: 12.5px; color: var(--muted); margin-bottom: 16px; }
|
||||||
|
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
|
||||||
|
|
||||||
|
/* ─── 明细展开行 ────────────────────────────────────────────────── */
|
||||||
|
.detail-box {
|
||||||
|
background: var(--bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
padding: 12px 14px;
|
||||||
|
font-size: 12.5px;
|
||||||
|
}
|
||||||
|
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 18px; font-size: 12.5px; }
|
||||||
|
.kv dt { color: var(--muted); }
|
||||||
|
.kv dd { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
|
||||||
|
|
||||||
|
/* ─── 提示条 ────────────────────────────────────────────────────── */
|
||||||
|
.notice {
|
||||||
|
display: flex; gap: 10px; align-items: flex-start;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
font-size: 13px;
|
||||||
|
background: var(--surface);
|
||||||
|
}
|
||||||
|
.notice.warn { background: var(--warn-soft); border-color: color-mix(in oklch, var(--warn) 30%, transparent); }
|
||||||
|
.notice.danger { background: var(--danger-soft); border-color: color-mix(in oklch, var(--danger) 30%, transparent); }
|
||||||
|
.notice.info { background: var(--info-soft); border-color: color-mix(in oklch, var(--info) 25%, transparent); }
|
||||||
|
.notice .n-title { font-weight: 650; }
|
||||||
|
.notice .n-body { color: color-mix(in oklch, var(--fg) 80%, var(--muted)); margin-top: 2px; font-size: 12.5px; }
|
||||||
|
|
||||||
|
/* ─── 登录页 ────────────────────────────────────────────────────── */
|
||||||
|
.login-wrap {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
.login-aside {
|
||||||
|
background: var(--fg);
|
||||||
|
color: var(--surface);
|
||||||
|
padding: 48px 56px;
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
}
|
||||||
|
.login-aside .brand-mark { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.1em; opacity: 0.65; }
|
||||||
|
.login-aside h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-top: 18px; line-height: 1.25; }
|
||||||
|
.login-aside .aside-sub { opacity: 0.72; font-size: 14px; margin-top: 14px; max-width: 40ch; }
|
||||||
|
.login-aside .aside-list { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
|
||||||
|
.login-aside .aside-item { display: flex; gap: 10px; font-size: 13px; opacity: 0.85; align-items: baseline; }
|
||||||
|
.login-aside .aside-item .tick { font-family: var(--font-mono); color: var(--accent); }
|
||||||
|
.login-panel { display: grid; place-items: center; padding: 48px 32px; }
|
||||||
|
.login-card { width: 100%; max-width: 400px; }
|
||||||
|
.login-card h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
|
||||||
|
.login-card .login-sub { color: var(--muted); font-size: 13px; margin: 6px 0 24px; }
|
||||||
|
.role-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
|
||||||
|
.role-switch button {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--surface);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
padding: 12px 10px;
|
||||||
|
text-align: left;
|
||||||
|
transition: border-color 0.12s ease, background 0.12s ease;
|
||||||
|
}
|
||||||
|
.role-switch button .r-name { font-size: 13.5px; font-weight: 650; }
|
||||||
|
.role-switch button .r-desc { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
|
||||||
|
.role-switch button.active { border-color: var(--accent); background: var(--accent-soft); }
|
||||||
|
.role-switch button.active .r-name { color: var(--accent); }
|
||||||
|
.login-card .field { margin-bottom: 14px; }
|
||||||
|
.login-foot { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }
|
||||||
|
.login-foot a { color: var(--accent); font-weight: 550; }
|
||||||
|
.login-foot a:hover { text-decoration: underline; }
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.login-wrap { grid-template-columns: 1fr; }
|
||||||
|
.login-aside { display: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 空状态 ────────────────────────────────────────────────────── */
|
||||||
|
.empty {
|
||||||
|
padding: 40px 20px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.empty .e-title { font-weight: 600; color: var(--fg); margin-bottom: 4px; }
|
||||||
|
|
||||||
|
/* ─── 账期流程条(公司端工作台) ─────────────────────────────────── */
|
||||||
|
.flow { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); }
|
||||||
|
.flow-step { padding: 14px 16px 13px; border-right: 1px solid var(--border); min-width: 0; }
|
||||||
|
.flow-step:last-child { border-right: 0; }
|
||||||
|
a.flow-step { cursor: pointer; transition: background 0.12s ease; }
|
||||||
|
a.flow-step:hover { background: var(--fg-soft); }
|
||||||
|
.flow-step .fs-top { display: flex; align-items: center; gap: 8px; }
|
||||||
|
.flow-step .fs-idx { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
|
||||||
|
.flow-step .fs-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); flex: none; }
|
||||||
|
.flow-step .fs-name { font-size: 13.5px; font-weight: 650; }
|
||||||
|
.flow-step .fs-state { font-size: 12px; font-weight: 600; margin-top: 7px; color: var(--muted); }
|
||||||
|
.flow-step .fs-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
||||||
|
.flow-step.done .fs-dot { background: var(--success); }
|
||||||
|
.flow-step.done .fs-state { color: var(--success); }
|
||||||
|
.flow-step.part .fs-dot { background: var(--warn); }
|
||||||
|
.flow-step.part .fs-state { color: color-mix(in oklch, var(--warn) 78%, black); }
|
||||||
|
.flow-step.doing { background: var(--warn-soft); }
|
||||||
|
.flow-step.doing .fs-dot { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in oklch, var(--warn) 22%, transparent); }
|
||||||
|
.flow-step.doing .fs-state { color: color-mix(in oklch, var(--warn) 78%, black); }
|
||||||
|
a.flow-step.doing:hover { background: color-mix(in oklch, var(--warn) 16%, transparent); }
|
||||||
|
@media (max-width: 860px) {
|
||||||
|
.flow { grid-template-columns: 1fr; }
|
||||||
|
.flow-step { border-right: 0; border-bottom: 1px solid var(--border); }
|
||||||
|
.flow-step:last-child { border-bottom: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 迷你指标(2×2 数字块) ────────────────────────────────────── */
|
||||||
|
.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||||
|
.mini-stat { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 13px; min-width: 0; }
|
||||||
|
.mini-stat .ms-label { font-size: 11.5px; color: var(--muted); }
|
||||||
|
.mini-stat .ms-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; margin-top: 3px; }
|
||||||
|
.mini-stat .ms-value .unit { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 2px; }
|
||||||
|
.mini-stat .ms-value.pos { color: var(--success); }
|
||||||
|
.mini-stat .ms-value.neg { color: var(--danger); }
|
||||||
|
|
||||||
|
/* ─── 上传组件(拖放区 / 文件条 / 附件选择) ────────────────────── */
|
||||||
|
.dropzone {
|
||||||
|
border: 1.5px dashed color-mix(in oklch, var(--fg) 28%, var(--border));
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
background: var(--bg);
|
||||||
|
padding: 30px 20px;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.12s ease, background 0.12s ease;
|
||||||
|
}
|
||||||
|
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
|
||||||
|
.dropzone.dragover { border-color: var(--accent); border-style: solid; background: var(--accent-soft); }
|
||||||
|
.dropzone svg { width: 28px; height: 28px; margin: 0 auto 10px; color: var(--muted); }
|
||||||
|
.dropzone .dz-title { font-size: 14px; font-weight: 650; }
|
||||||
|
.dropzone .dz-sub { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
|
||||||
|
.dropzone .dz-sub .dz-browse { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
|
||||||
|
.dropzone .dz-formats { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 12px; letter-spacing: 0.02em; }
|
||||||
|
|
||||||
|
.file-chip {
|
||||||
|
display: flex; align-items: center; gap: 10px;
|
||||||
|
margin-top: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
background: var(--surface);
|
||||||
|
}
|
||||||
|
.file-chip svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
|
||||||
|
.file-chip .fc-info { min-width: 0; flex: 1; }
|
||||||
|
.file-chip .fc-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.file-chip .fc-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 1px; }
|
||||||
|
.file-chip .fc-remove { background: none; border: 0; color: var(--muted); font-size: 16px; line-height: 1; padding: 4px 8px; border-radius: 6px; flex: none; }
|
||||||
|
.file-chip .fc-remove:hover { color: var(--danger); background: var(--danger-soft); }
|
||||||
|
|
||||||
|
.attach-pick {
|
||||||
|
display: inline-flex; align-items: center; gap: 7px;
|
||||||
|
padding: 7px 12px;
|
||||||
|
min-height: 34px;
|
||||||
|
border: 1.5px dashed color-mix(in oklch, var(--fg) 28%, var(--border));
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
|
||||||
|
}
|
||||||
|
.attach-pick svg { width: 15px; height: 15px; }
|
||||||
|
.attach-pick:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
|
||||||
|
|
||||||
|
/* ─── 数据表合计行 ─────────────────────────────────────────────── */
|
||||||
|
.ds-table tfoot td { background: var(--bg); font-weight: 650; border-top: 1.5px solid color-mix(in oklch, var(--fg) 30%, var(--border)); border-bottom: 0; }
|
||||||
|
|
||||||
|
/* ─── 入口页(index) ────────────────────────────────────────────── */
|
||||||
|
.portal-wrap { min-height: 100vh; display: grid; place-items: center; padding: 40px 24px; }
|
||||||
|
.portal-inner { width: 100%; max-width: 880px; }
|
||||||
|
.portal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 28px; }
|
||||||
|
.portal-card {
|
||||||
|
display: block;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
padding: 24px;
|
||||||
|
transition: border-color 0.12s ease, transform 0.12s ease;
|
||||||
|
}
|
||||||
|
.portal-card:hover { border-color: var(--accent); transform: translateY(-2px); }
|
||||||
|
.portal-card .pc-role { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; color: var(--accent); }
|
||||||
|
.portal-card h3 { font-size: 17px; font-weight: 700; margin-top: 8px; }
|
||||||
|
.portal-card p { color: var(--muted); font-size: 13px; margin-top: 6px; }
|
||||||
|
.portal-card .pc-go { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-top: 14px; }
|
||||||
|
@media (max-width: 720px) { .portal-grid { grid-template-columns: 1fr; } }
|
||||||
|
|
||||||
|
/* ─── SPA 视图切换 / 无障碍结构类 ───────────────────────────────── */
|
||||||
|
.app-view { display: none; }
|
||||||
|
.app-view.is-active { display: block; }
|
||||||
|
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
||||||
|
.skip-link {
|
||||||
|
position: fixed; top: 8px; left: 50%; z-index: 500;
|
||||||
|
padding: 8px 14px;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
background: var(--accent); color: var(--surface);
|
||||||
|
font-size: 13px; font-weight: 600;
|
||||||
|
transform: translate(-50%, -150%);
|
||||||
|
transition: transform 0.12s ease;
|
||||||
|
}
|
||||||
|
.skip-link:focus { transform: translate(-50%, 0); }
|
||||||
|
|
||||||
|
/* ─── 图标按钮 / 窄屏侧栏折叠 ──────────────────────────────────── */
|
||||||
|
.icon-button {
|
||||||
|
display: inline-grid; place-items: center;
|
||||||
|
width: 34px; height: 34px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
background: var(--surface); color: var(--muted);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
|
||||||
|
}
|
||||||
|
.icon-button:hover { color: var(--fg); border-color: color-mix(in oklch, var(--fg) 40%, var(--border)); background: var(--fg-soft); }
|
||||||
|
.icon-button svg { width: 18px; height: 18px; }
|
||||||
|
.menu-button { display: none; }
|
||||||
|
@media (max-width: 860px) {
|
||||||
|
.menu-button { display: inline-grid; }
|
||||||
|
.shell { grid-template-columns: 1fr; }
|
||||||
|
.sidebar {
|
||||||
|
position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
|
||||||
|
width: var(--side-w); height: 100dvh;
|
||||||
|
transform: translateX(-100%);
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
.sidebar.is-open { transform: none; box-shadow: 0 0 48px color-mix(in oklch, var(--fg) 22%, transparent); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Toast 轻量提示 ───────────────────────────────────────────── */
|
||||||
|
.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: grid; gap: 8px; }
|
||||||
|
.toast {
|
||||||
|
display: flex; align-items: flex-start; gap: 9px;
|
||||||
|
min-width: 260px; max-width: 380px;
|
||||||
|
padding: 11px 14px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
background: var(--surface);
|
||||||
|
box-shadow: 0 12px 34px color-mix(in oklch, var(--fg) 18%, transparent);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.toast .t-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 5px; background: var(--muted); }
|
||||||
|
.toast .t-body { min-width: 0; }
|
||||||
|
.toast .t-title { font-weight: 650; }
|
||||||
|
.toast .t-detail { color: var(--muted); font-size: 12px; margin-top: 1px; }
|
||||||
|
.toast.success { border-color: color-mix(in oklch, var(--success) 35%, var(--border)); }
|
||||||
|
.toast.success .t-dot { background: var(--success); }
|
||||||
|
.toast.warn { border-color: color-mix(in oklch, var(--warn) 40%, var(--border)); }
|
||||||
|
.toast.warn .t-dot { background: var(--warn); }
|
||||||
|
.toast.danger { border-color: color-mix(in oklch, var(--danger) 35%, var(--border)); }
|
||||||
|
.toast.danger .t-dot { background: var(--danger); }
|
||||||
|
.toast.info { border-color: color-mix(in oklch, var(--info) 35%, var(--border)); }
|
||||||
|
.toast.info .t-dot { background: var(--info); }
|
||||||
|
@media (max-width: 720px) {
|
||||||
|
.toast-region { right: 12px; bottom: 12px; left: 12px; }
|
||||||
|
.toast { min-width: 0; max-width: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 侧滑详情抽屉(用 modal/card token 重画) ─────────────────── */
|
||||||
|
.drawer {
|
||||||
|
position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
|
||||||
|
width: min(400px, calc(100vw - 24px));
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
background: var(--surface);
|
||||||
|
border-left: 1px solid var(--border);
|
||||||
|
box-shadow: -18px 0 50px color-mix(in oklch, var(--fg) 22%, transparent);
|
||||||
|
transform: translateX(100%);
|
||||||
|
visibility: hidden;
|
||||||
|
transition: transform 0.22s ease, visibility 0.22s;
|
||||||
|
}
|
||||||
|
.drawer.is-open { transform: none; visibility: visible; }
|
||||||
|
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
|
||||||
|
.drawer-head .d-title { font-size: 16px; font-weight: 700; margin-top: 6px; }
|
||||||
|
.drawer-head .d-desc { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
|
||||||
|
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
|
||||||
|
.drawer-body .kv { grid-template-columns: auto 1fr; gap: 8px 18px; }
|
||||||
|
.drawer-body .kv dt { color: var(--muted); white-space: nowrap; }
|
||||||
|
.drawer-body .kv dd { text-align: right; word-break: break-all; }
|
||||||
|
.drawer-tip { margin: 0 20px 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--muted); font-size: 12.5px; }
|
||||||
|
.drawer-tip strong { display: block; color: var(--fg); margin-bottom: 4px; }
|
||||||
|
.drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
|
||||||
|
|
||||||
|
/* ─── 加载中骨架 / 表内加载行 ──────────────────────────────────── */
|
||||||
|
.skeleton { display: block; border-radius: var(--radius); background: var(--fg-soft); position: relative; overflow: hidden; }
|
||||||
|
.skeleton::after {
|
||||||
|
content: ""; position: absolute; inset: 0;
|
||||||
|
background: linear-gradient(90deg, transparent, color-mix(in oklch, var(--surface) 60%, transparent), transparent);
|
||||||
|
animation: skeleton-shimmer 1.3s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes skeleton-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
|
||||||
|
.skeleton-line { height: 12px; margin-bottom: 10px; }
|
||||||
|
.loading-row { padding: 40px 20px; text-align: center; color: var(--muted); font-family: var(--font-mono); font-size: 12.5px; letter-spacing: 0.04em; }
|
||||||
|
.loading-inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-family: var(--font-mono); font-size: 12.5px; }
|
||||||
|
.loading-inline::before {
|
||||||
|
content: ""; width: 12px; height: 12px; border-radius: 50%;
|
||||||
|
border: 2px solid var(--border); border-top-color: var(--accent);
|
||||||
|
animation: loading-spin 0.7s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes loading-spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
/* ─── 提示条补充:成功态 ───────────────────────────────────────── */
|
||||||
|
.notice.success { background: var(--success-soft); border-color: color-mix(in oklch, var(--success) 30%, transparent); }
|
||||||
|
.notice.success .n-title { color: color-mix(in oklch, var(--success) 82%, black); }
|
||||||
+30
-45
@@ -1,48 +1,33 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="description" content="河南金牛实业集团内部资金往来与银行流水管理" />
|
<title>金牛实业资金往来管理系统 · 入口</title>
|
||||||
<title>登录 · 河南金牛实业集团</title>
|
<link rel="stylesheet" href="design-system.css?v=4" />
|
||||||
<link rel="stylesheet" href="styles.css" />
|
</head>
|
||||||
</head>
|
<body>
|
||||||
<body class="entry-page">
|
<div class="portal-wrap">
|
||||||
<!--
|
<div class="portal-inner">
|
||||||
THESIS: 登录页只完成身份确认,并明确区分总账管理端与公司业务端。
|
<p class="meta" style="letter-spacing: 0.1em;">JINNIU GROUP · INTERCOMPANY TREASURY</p>
|
||||||
OWN-WORLD: 深黑身份场景、石墨玻璃表单和荧光绿当前状态,延续双端工作台的材料语言。
|
<h1 style="font-size: 26px; font-weight: 700; letter-spacing: -0.015em; margin-top: 10px;">河南金牛实业集团有限公司 · 资金往来管理系统</h1>
|
||||||
STORY: 居中集团登录卡:先确认集团身份与系统名称,再选择工作端口登录。
|
<p class="muted" style="margin-top: 10px; max-width: 64ch;">集团内部公司间资金往来记账平台。银行流水导入后自动轧算往来余额,支持从集团汇总逐级穿透至银行原始流水。本系统包含总账管理端与公司业务端两套界面。</p>
|
||||||
FIRST VIEWPORT: 一张悬浮玻璃登录卡居于氛围光中央,集团名称置顶,端口选择、账号表单与系统事实依次排列。
|
|
||||||
FORM: 用户参考图锁定的深色玻璃财务工作台,Operate 模式;seed key fe8a50aa。
|
<div class="portal-grid">
|
||||||
FINISH: unreviewed and undocumented is unfinished; this build ends with the finish review, the verdict, and DESIGN.md
|
<a class="portal-card" href="login-admin.html">
|
||||||
-->
|
<span class="pc-role">总账管理端 · 7 个页面</span>
|
||||||
<main class="entry-shell">
|
<h3>管理总览 / 往来查询 / 审核中心 / 流水管理 / 公司与账号 / 结账与期初 / 提醒管理</h3>
|
||||||
<section class="entry-card" aria-labelledby="login-title">
|
<p>面向集团总账会计:全局监控各公司流水提交与往来余额,集中处理审核事项,执行月度结账。</p>
|
||||||
<div class="entry-brand"><span class="brand-mark">金</span><span><strong id="product-name">河南金牛实业集团</strong><small>集团资金往来管理系统</small></span></div>
|
<span class="pc-go">去管理端登录 →</span>
|
||||||
<form class="entry-form" id="loginForm">
|
</a>
|
||||||
<header><h2 id="login-title">登录</h2><p>请选择与账号一致的工作端口</p></header>
|
<a class="portal-card" href="login-company.html">
|
||||||
<div class="role-switch" role="radiogroup" aria-label="工作端口">
|
<span class="pc-role">公司业务端 · 7 个页面</span>
|
||||||
<label><input type="radio" name="role" value="admin" checked /><span><svg><use href="icons.svg#shield-check"/></svg><b>总账管理端</b><small>集团管理员</small></span></label>
|
<h3>工作台 / 流水导入 / 手工记录 / 流水管理 / 往来确认 / 银行账户 / 通知</h3>
|
||||||
<label><input type="radio" name="role" value="company" /><span><svg><use href="icons.svg#building"/></svg><b>公司业务端</b><small>公司出纳</small></span></label>
|
<p>面向成员公司出纳:上传银行流水、登记手工往来、确认单边匹配与科目,跟踪本月完成进度。</p>
|
||||||
</div>
|
<span class="pc-go">去公司端登录 →</span>
|
||||||
<label class="field"><span>账号</span><input name="username" autocomplete="username" required /></label>
|
</a>
|
||||||
<label class="field"><span>密码</span><span class="password-field"><input name="password" type="password" autocomplete="current-password" required /><button type="button" class="inside-icon" id="togglePassword" aria-label="显示密码" title="显示密码"><svg><use href="icons.svg#eye"/></svg></button></span></label>
|
</div>
|
||||||
<div id="changePassword" hidden>
|
</div>
|
||||||
<p class="entry-note">首次登录须修改密码,请设置新密码后再进入工作台。</p>
|
</div>
|
||||||
<label class="field"><span>新密码</span><input name="new_password" type="password" autocomplete="new-password" /></label>
|
</body>
|
||||||
<label class="field"><span>确认新密码</span><input name="confirm_password" type="password" autocomplete="new-password" /></label>
|
|
||||||
</div>
|
|
||||||
<p class="entry-note" id="loginError" role="alert" hidden></p>
|
|
||||||
<label class="check-field"><input type="checkbox" checked />记住本次登录</label>
|
|
||||||
<button class="button primary wide" type="submit"><span id="loginAction">进入总账管理端</span><svg><use href="icons.svg#chevron-right"/></svg></button>
|
|
||||||
</form>
|
|
||||||
<dl class="entry-facts">
|
|
||||||
<div><dt>全局起算日</dt><dd>2026.01.01</dd></div>
|
|
||||||
<div><dt>当前账期</dt><dd>2026 年 7 月</dd></div>
|
|
||||||
<div><dt>覆盖银行</dt><dd>已对接 6 家</dd></div>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
</main>
|
|
||||||
<script src="app.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>登录 · 金牛实业资金往来管理系统</title>
|
||||||
|
<link rel="stylesheet" href="design-system.css?v=4" />
|
||||||
|
</head>
|
||||||
|
<body data-role="admin">
|
||||||
|
<div class="login-wrap">
|
||||||
|
<aside class="login-aside">
|
||||||
|
<span class="brand-mark">JINNIU GROUP · TREASURY</span>
|
||||||
|
<h1>河南金牛实业集团有限公司<br />资金往来管理系统</h1>
|
||||||
|
<p class="aside-sub">集团内部各公司之间资金往来的统一记账平台。导入银行流水后自动轧算公司间往来余额,从集团汇总可层层下钻至银行原始流水。</p>
|
||||||
|
<div class="aside-list">
|
||||||
|
<div class="aside-item"><span class="tick">01</span><span>银行流水自动归集,公司间往来余额实时轧算</span></div>
|
||||||
|
<div class="aside-item"><span class="tick">02</span><span>单边匹配、流水断档、科目确认集中审核</span></div>
|
||||||
|
<div class="aside-item"><span class="tick">03</span><span>月度结账检查:流水提交、账户连续、审核完成</span></div>
|
||||||
|
<div class="aside-item"><span class="tick">04</span><span>汇总 → 公司 → 账户 → 原始流水,四级穿透追溯</span></div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main class="login-panel">
|
||||||
|
<div class="login-card">
|
||||||
|
<h2>登录系统</h2>
|
||||||
|
<p class="login-sub">请输入账号密码登录总账管理端。首次登录需修改初始密码。</p>
|
||||||
|
|
||||||
|
<form id="login-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="account">账号</label>
|
||||||
|
<input class="input" id="account" placeholder="请输入账号" autocomplete="username" />
|
||||||
|
<span class="hint error" id="account-err" hidden>请输入账号</span>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="password">密码</label>
|
||||||
|
<input class="input" id="password" type="password" placeholder="请输入密码" autocomplete="current-password" />
|
||||||
|
<span class="hint error" id="password-err" hidden>请输入密码</span>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<span class="hint error" id="login-err" role="alert" hidden></span>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary" type="submit" style="width: 100%; margin-top: 6px;">登 录</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p class="login-foot">忘记密码请联系集团总账管理员重置 · <a href="index.html">返回入口页</a></p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-backdrop" id="pwd-modal">
|
||||||
|
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="pwd-title">
|
||||||
|
<div class="modal-head">
|
||||||
|
<span class="modal-title" id="pwd-title">首次登录 · 修改初始密码</span>
|
||||||
|
</div>
|
||||||
|
<p class="modal-sub">为保障资金安全,首次登录必须修改初始密码。新密码需 8 位以上,且包含字母与数字。</p>
|
||||||
|
<div class="field" style="margin-bottom: 12px;">
|
||||||
|
<label for="new-pwd">新密码</label>
|
||||||
|
<input class="input" id="new-pwd" type="password" placeholder="8 位以上,含字母与数字" autocomplete="new-password" />
|
||||||
|
<span class="hint error" id="new-pwd-err" hidden>密码需 8 位以上,且包含字母与数字</span>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="new-pwd2">确认新密码</label>
|
||||||
|
<input class="input" id="new-pwd2" type="password" placeholder="再次输入新密码" autocomplete="new-password" />
|
||||||
|
<span class="hint error" id="new-pwd2-err" hidden>两次输入的密码不一致</span>
|
||||||
|
</div>
|
||||||
|
<div class="field" style="margin-top: 12px;">
|
||||||
|
<span class="hint error" id="pwd-err" role="alert" hidden></span>
|
||||||
|
</div>
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button class="btn btn-primary" id="pwd-confirm">确认修改并进入系统</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="login.js?v=4"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>登录 · 金牛实业资金往来管理系统</title>
|
||||||
|
<link rel="stylesheet" href="design-system.css?v=4" />
|
||||||
|
</head>
|
||||||
|
<body data-role="company">
|
||||||
|
<div class="login-wrap">
|
||||||
|
<aside class="login-aside">
|
||||||
|
<span class="brand-mark">JINNIU GROUP · TREASURY</span>
|
||||||
|
<h1>河南金牛实业集团有限公司<br />资金往来管理系统</h1>
|
||||||
|
<p class="aside-sub">集团内部各公司之间资金往来的统一记账平台。导入银行流水后自动轧算公司间往来余额,从集团汇总可层层下钻至银行原始流水。</p>
|
||||||
|
<div class="aside-list">
|
||||||
|
<div class="aside-item"><span class="tick">01</span><span>银行流水自动归集,公司间往来余额实时轧算</span></div>
|
||||||
|
<div class="aside-item"><span class="tick">02</span><span>单边匹配、流水断档、科目确认集中审核</span></div>
|
||||||
|
<div class="aside-item"><span class="tick">03</span><span>月度结账检查:流水提交、账户连续、审核完成</span></div>
|
||||||
|
<div class="aside-item"><span class="tick">04</span><span>汇总 → 公司 → 账户 → 原始流水,四级穿透追溯</span></div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main class="login-panel">
|
||||||
|
<div class="login-card">
|
||||||
|
<h2>登录系统</h2>
|
||||||
|
<p class="login-sub">请输入账号密码登录公司业务端。首次登录需修改初始密码。</p>
|
||||||
|
|
||||||
|
<form id="login-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="account">账号</label>
|
||||||
|
<input class="input" id="account" placeholder="请输入账号" autocomplete="username" />
|
||||||
|
<span class="hint error" id="account-err" hidden>请输入账号</span>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="password">密码</label>
|
||||||
|
<input class="input" id="password" type="password" placeholder="请输入密码" autocomplete="current-password" />
|
||||||
|
<span class="hint error" id="password-err" hidden>请输入密码</span>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<span class="hint error" id="login-err" role="alert" hidden></span>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary" type="submit" style="width: 100%; margin-top: 6px;">登 录</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p class="login-foot">忘记密码请联系集团总账管理员重置 · <a href="index.html">返回入口页</a></p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-backdrop" id="pwd-modal">
|
||||||
|
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="pwd-title">
|
||||||
|
<div class="modal-head">
|
||||||
|
<span class="modal-title" id="pwd-title">首次登录 · 修改初始密码</span>
|
||||||
|
</div>
|
||||||
|
<p class="modal-sub">为保障资金安全,首次登录必须修改初始密码。新密码需 8 位以上,且包含字母与数字。</p>
|
||||||
|
<div class="field" style="margin-bottom: 12px;">
|
||||||
|
<label for="new-pwd">新密码</label>
|
||||||
|
<input class="input" id="new-pwd" type="password" placeholder="8 位以上,含字母与数字" autocomplete="new-password" />
|
||||||
|
<span class="hint error" id="new-pwd-err" hidden>密码需 8 位以上,且包含字母与数字</span>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="new-pwd2">确认新密码</label>
|
||||||
|
<input class="input" id="new-pwd2" type="password" placeholder="再次输入新密码" autocomplete="new-password" />
|
||||||
|
<span class="hint error" id="new-pwd2-err" hidden>两次输入的密码不一致</span>
|
||||||
|
</div>
|
||||||
|
<div class="field" style="margin-top: 12px;">
|
||||||
|
<span class="hint error" id="pwd-err" role="alert" hidden></span>
|
||||||
|
</div>
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button class="btn btn-primary" id="pwd-confirm">确认修改并进入系统</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="login.js?v=4"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
const ROLE = document.body.dataset.role || "admin";
|
||||||
|
const REDIRECT = ROLE === "admin" ? "admin.html" : "company.html";
|
||||||
|
|
||||||
|
const form = document.getElementById("login-form");
|
||||||
|
const accountInput = document.getElementById("account");
|
||||||
|
const passwordInput = document.getElementById("password");
|
||||||
|
const accountErr = document.getElementById("account-err");
|
||||||
|
const passwordErr = document.getElementById("password-err");
|
||||||
|
const loginErr = document.getElementById("login-err");
|
||||||
|
const submitButton = form.querySelector('button[type="submit"]');
|
||||||
|
|
||||||
|
const modal = document.getElementById("pwd-modal");
|
||||||
|
const newPwd = document.getElementById("new-pwd");
|
||||||
|
const newPwd2 = document.getElementById("new-pwd2");
|
||||||
|
const newPwdErr = document.getElementById("new-pwd-err");
|
||||||
|
const newPwd2Err = document.getElementById("new-pwd2-err");
|
||||||
|
const pwdErr = document.getElementById("pwd-err");
|
||||||
|
const pwdConfirm = document.getElementById("pwd-confirm");
|
||||||
|
|
||||||
|
const submitLabel = "登 录";
|
||||||
|
|
||||||
|
function setLoading(loading) {
|
||||||
|
submitButton.disabled = loading;
|
||||||
|
submitButton.textContent = loading ? "登录中…" : submitLabel;
|
||||||
|
accountInput.disabled = loading;
|
||||||
|
passwordInput.disabled = loading;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLoginError(message) {
|
||||||
|
loginErr.textContent = message || "";
|
||||||
|
loginErr.hidden = !message;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPasswordModal() {
|
||||||
|
newPwd.value = "";
|
||||||
|
newPwd2.value = "";
|
||||||
|
newPwdErr.hidden = true;
|
||||||
|
newPwd2Err.hidden = true;
|
||||||
|
pwdErr.hidden = true;
|
||||||
|
modal.classList.add("open");
|
||||||
|
newPwd.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
form.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
showLoginError("");
|
||||||
|
const account = accountInput.value.trim();
|
||||||
|
const password = passwordInput.value;
|
||||||
|
accountErr.hidden = Boolean(account);
|
||||||
|
passwordErr.hidden = Boolean(password);
|
||||||
|
if (!account || !password) return;
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
const response = await fetch("/api/login", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ username: account, password, portal: ROLE }),
|
||||||
|
}).catch(() => null);
|
||||||
|
const result = await response?.json().catch(() => ({}));
|
||||||
|
if (!response || !response.ok) {
|
||||||
|
showLoginError(result?.message || "登录服务暂时不可用,请稍后重试。");
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result.must_change_password) {
|
||||||
|
setLoading(false);
|
||||||
|
openPasswordModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.location.href = REDIRECT;
|
||||||
|
});
|
||||||
|
|
||||||
|
pwdConfirm.addEventListener("click", async () => {
|
||||||
|
const p1 = newPwd.value;
|
||||||
|
const p2 = newPwd2.value;
|
||||||
|
const valid = p1.length >= 8 && /[a-zA-Z]/.test(p1) && /\d/.test(p1);
|
||||||
|
newPwdErr.hidden = valid;
|
||||||
|
newPwd2Err.hidden = p1 === p2;
|
||||||
|
pwdErr.hidden = true;
|
||||||
|
if (!valid || p1 !== p2) return;
|
||||||
|
|
||||||
|
pwdConfirm.disabled = true;
|
||||||
|
const response = await fetch("/api/password/change", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ old_password: passwordInput.value, new_password: p1 }),
|
||||||
|
}).catch(() => null);
|
||||||
|
const result = await response?.json().catch(() => ({}));
|
||||||
|
if (!response || !response.ok) {
|
||||||
|
pwdErr.textContent = result?.message || "修改密码失败,请稍后重试。";
|
||||||
|
pwdErr.hidden = false;
|
||||||
|
pwdConfirm.disabled = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.location.href = REDIRECT;
|
||||||
|
});
|
||||||
-738
@@ -1,738 +0,0 @@
|
|||||||
:root {
|
|
||||||
color-scheme: dark;
|
|
||||||
--font-ui: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
|
|
||||||
--font-data: "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
|
|
||||||
--color-bg: #050505;
|
|
||||||
--color-bg-soft: #0a0a0a;
|
|
||||||
--color-nav: #0a0a0a;
|
|
||||||
--color-surface: rgba(22, 22, 22, 0.82);
|
|
||||||
--color-surface-solid: #161616;
|
|
||||||
--color-surface-raised: #1c1c1c;
|
|
||||||
--color-surface-muted: rgba(255, 255, 255, 0.035);
|
|
||||||
--color-line: rgba(255, 255, 255, 0.09);
|
|
||||||
--color-line-strong: rgba(255, 255, 255, 0.16);
|
|
||||||
--color-ink: #f2f7f4;
|
|
||||||
--color-ink-soft: #a6b0aa;
|
|
||||||
--color-ink-muted: #89938d;
|
|
||||||
--color-primary: #37eb89;
|
|
||||||
--color-primary-strong: #70ffae;
|
|
||||||
--color-primary-dark: #08160e;
|
|
||||||
--color-primary-wash: rgba(55, 235, 137, 0.11);
|
|
||||||
--color-positive: #37eb89;
|
|
||||||
--color-positive-wash: rgba(55, 235, 137, 0.1);
|
|
||||||
--color-warning: #ffbc52;
|
|
||||||
--color-warning-wash: rgba(255, 188, 82, 0.11);
|
|
||||||
--color-danger: #ff626d;
|
|
||||||
--color-danger-wash: rgba(255, 98, 109, 0.11);
|
|
||||||
--color-info: #66a8ff;
|
|
||||||
--color-info-wash: rgba(102, 168, 255, 0.11);
|
|
||||||
--radius-sm: 10px;
|
|
||||||
--radius-md: 16px;
|
|
||||||
--radius-lg: 22px;
|
|
||||||
--radius-xl: 28px;
|
|
||||||
--shadow-panel: 0 24px 70px rgba(0, 0, 0, 0.34), inset 0 1px rgba(255, 255, 255, 0.035);
|
|
||||||
--shadow-low: 0 12px 32px rgba(0, 0, 0, 0.22), inset 0 1px rgba(255, 255, 255, 0.06), inset 0 -1px 0 rgba(0, 0, 0, 0.22);
|
|
||||||
--shadow-glow: 0 0 28px rgba(55, 235, 137, 0.12);
|
|
||||||
--duration-fast: 150ms;
|
|
||||||
--duration-standard: 260ms;
|
|
||||||
--ease-out: cubic-bezier(0.22, 1, 0.36, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
* { box-sizing: border-box; }
|
|
||||||
html { min-width: 320px; background: var(--color-bg); scroll-behavior: smooth; }
|
|
||||||
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--color-bg); color: var(--color-ink); font: 14px/1.6 var(--font-ui); -webkit-font-smoothing: antialiased; }
|
|
||||||
button, input, select, textarea { font: inherit; }
|
|
||||||
button, a, summary { -webkit-tap-highlight-color: transparent; }
|
|
||||||
button { color: inherit; }
|
|
||||||
a { color: inherit; text-decoration: none; }
|
|
||||||
h1, h2, h3, p, dl, dd { margin: 0; }
|
|
||||||
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
|
||||||
strong, .amount, .number, dd { font-variant-numeric: tabular-nums; }
|
|
||||||
::selection { background: rgba(55, 235, 137, 0.26); color: #fff; }
|
|
||||||
::-webkit-scrollbar { width: 9px; height: 9px; }
|
|
||||||
::-webkit-scrollbar-track { background: transparent; }
|
|
||||||
::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 10px; background: rgba(255, 255, 255, 0.15); background-clip: padding-box; }
|
|
||||||
|
|
||||||
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
|
||||||
.skip-link { position: fixed; top: 8px; left: 50%; z-index: 500; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--color-primary); color: var(--color-primary-dark); transform: translate(-50%, -150%); }
|
|
||||||
.skip-link:focus { transform: translate(-50%, 0); }
|
|
||||||
:focus-visible { outline: 2px solid var(--color-primary-strong); outline-offset: 3px; }
|
|
||||||
[hidden] { display: none !important; }
|
|
||||||
|
|
||||||
/* Application frame */
|
|
||||||
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 266px minmax(0, 1fr); }
|
|
||||||
.sidebar { position: fixed; inset: 18px auto 18px 18px; z-index: 120; width: 248px; display: flex; flex-direction: column; padding: 16px 12px; border: 1px solid var(--color-line); border-radius: var(--radius-xl); background: rgba(12, 12, 12, 0.9); box-shadow: var(--shadow-panel); backdrop-filter: blur(26px) saturate(125%); }
|
|
||||||
.brand { min-height: 60px; display: flex; align-items: center; gap: 11px; padding: 7px 10px 20px; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid rgba(112, 255, 174, 0.32); border-radius: 12px; background: var(--color-primary-wash); color: var(--color-primary-strong); box-shadow: var(--shadow-glow); font-size: 18px; font-weight: 800; }
|
|
||||||
.brand-copy { display: flex; flex-direction: column; min-width: 0; }
|
|
||||||
.brand-copy strong { font-size: 15px; }
|
|
||||||
.brand-copy small, .user-block small, .company-context small { color: var(--color-ink-muted); font-size: 10px; }
|
|
||||||
.company-context { min-height: 64px; display: flex; align-items: center; gap: 10px; margin: 12px 4px 2px; padding: 10px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: var(--color-surface-muted); }
|
|
||||||
.company-context > span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--color-primary); color: var(--color-primary-dark); font-weight: 800; }
|
|
||||||
.company-context div { display: flex; flex-direction: column; }
|
|
||||||
.nav-list { display: grid; gap: 8px; padding: 14px 2px; overflow-y: auto; }
|
|
||||||
.nav-item { position: relative; width: 100%; min-height: 46px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border: 1px solid transparent; border-radius: 14px; background: transparent; color: var(--color-ink-soft); text-align: left; cursor: pointer; transition: color var(--duration-fast), background var(--duration-fast), border-color var(--duration-fast), transform var(--duration-fast); }
|
|
||||||
.nav-item:hover { color: var(--color-ink); background: rgba(255, 255, 255, 0.045); transform: translateX(2px); }
|
|
||||||
.nav-item.is-active { border-color: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.075); color: var(--color-ink); box-shadow: inset 0 1px rgba(255, 255, 255, 0.045), 0 8px 22px rgba(0, 0, 0, 0.2); }
|
|
||||||
.nav-item.is-active svg { color: var(--color-primary); filter: drop-shadow(0 0 8px rgba(55, 235, 137, 0.42)); }
|
|
||||||
.nav-item svg { width: 17px; flex: 0 0 auto; }
|
|
||||||
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
||||||
.nav-item b { min-width: 19px; height: 19px; display: grid; place-items: center; margin-left: auto; border-radius: 7px; background: var(--color-primary-wash); color: var(--color-primary); font-size: 10px; }
|
|
||||||
.sidebar-footer { display: grid; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--color-line); }
|
|
||||||
.user-block { min-height: 51px; display: flex; align-items: center; gap: 10px; padding: 7px 9px; }
|
|
||||||
.user-block > span:last-child { display: flex; flex-direction: column; }
|
|
||||||
.avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: #242c28; color: var(--color-primary-strong); font-weight: 700; }
|
|
||||||
.workspace { min-width: 0; grid-column: 2; }
|
|
||||||
.topbar { position: sticky; top: 0; z-index: 90; height: 56px; display: flex; align-items: center; gap: 13px; padding: 0 30px; border-bottom: 1px solid rgba(255, 255, 255, 0.055); background: rgba(5, 5, 5, 0.82); backdrop-filter: blur(22px); }
|
|
||||||
.topbar-spacer { flex: 1; }
|
|
||||||
.workspace-name { display: flex; flex-direction: column; min-width: 150px; }
|
|
||||||
.workspace-name span { color: var(--color-ink-muted); font-size: 10px; }
|
|
||||||
.workspace-name strong { font-size: 14px; }
|
|
||||||
.demo-badge { padding: 3px 8px; border: 1px solid rgba(255, 188, 82, 0.22); border-radius: 8px; background: var(--color-warning-wash); color: var(--color-warning); font-size: 10px; }
|
|
||||||
.topbar-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
|
|
||||||
.search-box { width: clamp(200px, 22vw, 340px); height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 13px; border: 1px solid var(--color-line); border-radius: 14px; background: rgba(255, 255, 255, 0.035); color: var(--color-ink-muted); transition: border-color var(--duration-fast), background var(--duration-fast), box-shadow var(--duration-fast); }
|
|
||||||
.search-box:focus-within { border-color: rgba(55, 235, 137, 0.4); background: rgba(255, 255, 255, 0.055); box-shadow: var(--shadow-glow); }
|
|
||||||
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--color-ink); }
|
|
||||||
.search-box input::placeholder, input::placeholder, textarea::placeholder { color: #626b66; }
|
|
||||||
.period-button, .icon-button, .inside-icon, .swap-button { display: inline-grid; place-items: center; border: 1px solid var(--color-line); background: var(--color-surface-muted); color: var(--color-ink-soft); cursor: pointer; transition: border-color var(--duration-fast), color var(--duration-fast), background var(--duration-fast), transform var(--duration-fast); }
|
|
||||||
.period-button { min-height: 40px; grid-auto-flow: column; gap: 8px; padding: 0 13px; border-radius: 14px; }
|
|
||||||
.icon-button { position: relative; width: 40px; height: 40px; border-radius: 13px; }
|
|
||||||
.inside-icon { width: 36px; height: 36px; border: 0; background: transparent; }
|
|
||||||
.period-button:hover, .icon-button:hover, .inside-icon:hover, .swap-button:hover { border-color: var(--color-line-strong); background: rgba(255, 255, 255, 0.07); color: var(--color-ink); transform: translateY(-1px); }
|
|
||||||
.notification-dot { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; display: grid; place-items: center; border: 2px solid var(--color-bg); border-radius: 9px; background: var(--color-danger); color: #fff; font: 9px var(--font-data); }
|
|
||||||
.menu-button { display: none; }
|
|
||||||
main { width: min(1560px, 100%); margin: 0 auto; padding: 12px 32px 58px; }
|
|
||||||
.app-view { display: none; }
|
|
||||||
.app-view.is-active { display: block; }
|
|
||||||
.page-heading { min-height: 56px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
|
|
||||||
.page-heading h1 { font-size: clamp(22px, 2.4vw, 30px); line-height: 1.2; letter-spacing: 0; }
|
|
||||||
.page-heading p { margin-top: 5px; color: var(--color-ink-muted); }
|
|
||||||
.content-toolbar { display: contents; }
|
|
||||||
.content-toolbar > .search-box { margin-inline: auto; width: clamp(260px, 42vw, 520px); }
|
|
||||||
.content-toolbar .toolbar-group { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
|
|
||||||
.dashboard-head { align-items: center; gap: 20px; margin-bottom: 20px; }
|
|
||||||
|
|
||||||
/* Commands and fields */
|
|
||||||
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 13px; font-weight: 700; cursor: pointer; transition: transform var(--duration-fast), box-shadow var(--duration-fast), background var(--duration-fast), border-color var(--duration-fast); }
|
|
||||||
.button:hover { transform: translateY(-1px); }
|
|
||||||
.button:active { transform: translateY(0) scale(0.985); }
|
|
||||||
.button.primary { background: var(--color-primary); color: var(--color-primary-dark); box-shadow: 0 8px 24px rgba(55, 235, 137, 0.18); }
|
|
||||||
.button.primary:hover { background: var(--color-primary-strong); box-shadow: 0 10px 30px rgba(55, 235, 137, 0.25); }
|
|
||||||
.button.secondary { border-color: var(--color-line); background: rgba(255, 255, 255, 0.045); color: var(--color-ink); }
|
|
||||||
.button.secondary:hover { border-color: var(--color-line-strong); background: rgba(255, 255, 255, 0.08); }
|
|
||||||
.button.small { min-height: 34px; padding-inline: 11px; border-radius: 11px; font-size: 11px; }
|
|
||||||
.button.wide { width: 100%; }
|
|
||||||
.button:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }
|
|
||||||
.text-button { padding: 3px 0; border: 0; background: none; color: var(--color-primary); cursor: pointer; }
|
|
||||||
.text-button:hover { color: var(--color-primary-strong); }
|
|
||||||
.full-text-button { width: 100%; padding: 13px; border-top: 1px solid var(--color-line); }
|
|
||||||
.field { min-width: 0; display: flex; flex-direction: column; gap: 6px; color: var(--color-ink-soft); }
|
|
||||||
.field > span { color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--color-line); border-radius: 11px; outline: 0; background: rgba(2, 5, 3, 0.48); color: var(--color-ink); transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background var(--duration-fast); }
|
|
||||||
.field textarea { resize: vertical; }
|
|
||||||
.field input:focus, .field select:focus, .field textarea:focus { border-color: rgba(55, 235, 137, 0.5); background: rgba(2, 5, 3, 0.7); box-shadow: 0 0 0 3px rgba(55, 235, 137, 0.08); }
|
|
||||||
.field select { color-scheme: dark; }
|
|
||||||
.field.compact { min-width: 150px; }
|
|
||||||
.password-field { display: grid; grid-template-columns: 1fr 38px; border: 1px solid var(--color-line); border-radius: 12px; background: rgba(2, 5, 3, 0.48); }
|
|
||||||
.password-field input { border: 0; background: transparent; }
|
|
||||||
.check-field { display: flex; align-items: center; gap: 8px; color: var(--color-ink-soft); }
|
|
||||||
.check-field input { accent-color: var(--color-primary); }
|
|
||||||
.swap-button { width: 38px; height: 38px; border-radius: 12px; align-self: end; }
|
|
||||||
|
|
||||||
/* Glass surfaces */
|
|
||||||
.panel, .period-ribbon, .query-band, .filter-bar, .filter-grid, .pair-report, .work-progress, .reconcile-summary { position: relative; border: 1px solid var(--color-line); border-radius: var(--radius-lg); background: linear-gradient(160deg, rgba(28, 28, 28, 0.82) 0%, rgba(16, 16, 16, 0.86) 50%, rgba(10, 10, 10, 0.88) 100%); box-shadow: var(--shadow-low); backdrop-filter: blur(22px) saturate(120%); transition: transform var(--duration-standard) var(--ease-out), box-shadow var(--duration-standard), border-color var(--duration-standard); }
|
|
||||||
.panel::before, .period-ribbon::before, .reconcile-summary::before, .work-progress::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(165deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.03) 40%, rgba(255, 255, 255, 0) 70%); pointer-events: none; }
|
|
||||||
.panel:hover { box-shadow: 0 20px 48px rgba(0, 0, 0, 0.32), inset 0 1px rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.14); }
|
|
||||||
.panel { min-width: 0; overflow: hidden; }
|
|
||||||
.panel > * { position: relative; }
|
|
||||||
.panel-heading { min-height: 67px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 14px 17px; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.panel-heading h2 { font-size: 15px; }
|
|
||||||
.panel-heading p { margin-top: 3px; color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.status { display: inline-flex; align-items: center; justify-content: center; gap: 5px; width: max-content; min-height: 23px; padding: 2px 8px; border: 1px solid transparent; border-radius: 8px; font-size: 10px; font-style: normal; white-space: nowrap; }
|
|
||||||
.status.success { border-color: rgba(55, 235, 137, 0.18); background: var(--color-positive-wash); color: var(--color-positive); }
|
|
||||||
.status.warning { border-color: rgba(255, 188, 82, 0.18); background: var(--color-warning-wash); color: var(--color-warning); }
|
|
||||||
.status.danger { border-color: rgba(255, 98, 109, 0.18); background: var(--color-danger-wash); color: var(--color-danger); }
|
|
||||||
.status.neutral { border-color: var(--color-line); background: rgba(255, 255, 255, 0.045); color: var(--color-ink-soft); }
|
|
||||||
.task-level { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; font-size: 10px; font-style: normal; font-weight: 800; }
|
|
||||||
.task-level.danger { background: var(--color-danger-wash); color: var(--color-danger); }
|
|
||||||
.task-level.warning { background: var(--color-warning-wash); color: var(--color-warning); }
|
|
||||||
.task-level.neutral { background: rgba(255, 255, 255, 0.055); color: var(--color-ink-soft); }
|
|
||||||
|
|
||||||
/* Dashboard */
|
|
||||||
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin: 0 0 18px; }
|
|
||||||
.metric-card { position: relative; min-height: 164px; display: grid; grid-template-columns: minmax(0, 1fr) 48px; align-content: space-between; gap: 14px; padding: 24px 22px; overflow: hidden; border: 1px solid var(--color-line); border-radius: var(--radius-lg); background: linear-gradient(160deg, rgba(28, 28, 28, 0.86) 0%, rgba(14, 14, 14, 0.88) 50%, rgba(8, 8, 8, 0.9) 100%); box-shadow: var(--shadow-low); backdrop-filter: blur(24px) saturate(125%); transform: perspective(900px) rotateX(0.6deg) rotateY(-0.8deg); transform-origin: center bottom; transition: transform var(--duration-standard) var(--ease-out), border-color var(--duration-standard), box-shadow var(--duration-standard); }
|
|
||||||
.metric-card::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(165deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.04) 42%, rgba(255, 255, 255, 0) 72%); pointer-events: none; }
|
|
||||||
.metric-card::after { content: ""; position: absolute; inset: auto 15% -1px 15%; height: 1px; background: currentColor; opacity: 0.35; box-shadow: 0 -8px 24px currentColor; transition: opacity var(--duration-standard), box-shadow var(--duration-standard); }
|
|
||||||
.metric-card:hover::after { opacity: 0.7; box-shadow: 0 -10px 34px currentColor; }
|
|
||||||
.metric-card:hover { transform: perspective(900px) rotateX(3.5deg) rotateY(-4.5deg) translateY(-10px); border-color: rgba(255, 255, 255, 0.32); box-shadow: 0 36px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06), inset 0 1px rgba(255, 255, 255, 0.14); }
|
|
||||||
.metric-copy { align-self: start; }
|
|
||||||
.metric-label { display: block; color: var(--color-ink-soft); font-size: 13px; }
|
|
||||||
.metric-value { display: block; margin-top: 7px; font: 700 34px/1.05 var(--font-data); letter-spacing: 0; }
|
|
||||||
.metric-value small { margin-left: 5px; color: var(--color-ink-muted); font: 11px var(--font-ui); }
|
|
||||||
.metric-icon { position: relative; width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid var(--color-line); border-radius: 50%; background: radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.02) 70%); color: var(--color-ink-soft); box-shadow: inset 0 1px rgba(255, 255, 255, 0.05); }
|
|
||||||
.metric-icon::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 1px solid currentColor; opacity: 0.12; pointer-events: none; }
|
|
||||||
.metric-foot { grid-column: 1 / -1; color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.metric-foot strong { color: var(--color-positive); }
|
|
||||||
.metric-card.warning { color: var(--color-warning); }
|
|
||||||
.metric-card.danger { color: var(--color-danger); }
|
|
||||||
.metric-card.success { color: var(--color-positive); }
|
|
||||||
.metric-card .metric-copy { color: var(--color-ink); }
|
|
||||||
.metric-card .metric-icon { color: var(--color-ink-soft); }
|
|
||||||
.metric-card .metric-foot { color: var(--color-ink-muted); }
|
|
||||||
.metric-card[data-metric-link], .metric-card[data-metric-action] { cursor: pointer; }
|
|
||||||
.metric-card.warning .metric-icon, .metric-card.warning .metric-foot strong { color: var(--color-warning); }
|
|
||||||
.metric-card.warning .metric-icon::after { opacity: 0.28; }
|
|
||||||
.metric-card.danger .metric-icon, .metric-card.danger .metric-foot strong { color: var(--color-danger); }
|
|
||||||
.metric-card.danger .metric-icon::after { opacity: 0.32; }
|
|
||||||
.metric-card.success .metric-icon { color: var(--color-positive); }
|
|
||||||
.metric-card.success .metric-icon::after { opacity: 0.22; border-color: var(--color-positive); }
|
|
||||||
.period-ribbon { display: grid; grid-template-columns: 1fr 1fr 1fr minmax(310px, 1.4fr); margin-bottom: 18px; overflow: hidden; }
|
|
||||||
.period-ribbon > div { min-height: 72px; display: flex; flex-direction: column; justify-content: center; padding: 13px 17px; border-left: 1px solid var(--color-line); }
|
|
||||||
.period-ribbon > div:first-child { border-left: 0; }
|
|
||||||
.period-ribbon span, .period-ribbon small { color: var(--color-ink-muted); }
|
|
||||||
.period-ribbon strong { margin-top: 3px; }
|
|
||||||
.period-ribbon > .period-warning { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
|
|
||||||
.period-warning > svg { color: var(--color-warning); }
|
|
||||||
.period-warning > span { display: flex; flex-direction: column; }
|
|
||||||
.period-warning > span strong { color: var(--color-ink); }
|
|
||||||
.admin-dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.42fr) minmax(310px, 0.58fr); gap: 18px; margin-bottom: 18px; }
|
|
||||||
.task-list button { width: 100%; min-height: 73px; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto 18px; align-items: center; gap: 11px; padding: 12px 16px; border: 0; border-top: 1px solid var(--color-line); background: transparent; text-align: left; cursor: pointer; transition: background var(--duration-fast); }
|
|
||||||
.task-list button:first-child { border-top: 0; }
|
|
||||||
.task-list button:hover { background: rgba(255, 255, 255, 0.035); }
|
|
||||||
.task-list button > span:nth-child(2) { display: flex; flex-direction: column; }
|
|
||||||
.task-list small, .task-list button > b { color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.task-list button > svg { color: var(--color-ink-muted); }
|
|
||||||
.quick-pair-form { display: grid; grid-template-columns: 1fr 38px 1fr; gap: 10px; padding: 16px; }
|
|
||||||
.quick-pair-form .button { grid-column: 1 / -1; }
|
|
||||||
.quick-result { margin: 0 16px 16px; padding: 14px; border: 1px solid rgba(55, 235, 137, 0.16); border-radius: var(--radius-md); background: var(--color-primary-wash); }
|
|
||||||
.quick-result span, .quick-result p { color: var(--color-ink-muted); }
|
|
||||||
.quick-result strong { display: block; margin: 4px 0; color: var(--color-primary-strong); font: 700 22px var(--font-data); }
|
|
||||||
.quick-result small { margin-left: 4px; font: 10px var(--font-ui); }
|
|
||||||
|
|
||||||
/* Key-company / account-coverage flat list (replaces the floating 3D card stack) */
|
|
||||||
.company-list { display: grid; gap: 8px; padding: 10px 12px 14px; }
|
|
||||||
.company-row { position: relative; display: grid; grid-template-columns: 34px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; min-height: 62px; padding: 11px 13px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: linear-gradient(160deg, rgba(22, 22, 22, 0.7) 0%, rgba(12, 12, 12, 0.75) 100%); cursor: pointer; transition: background var(--duration-fast), border-color var(--duration-fast), transform var(--duration-standard) var(--ease-out), box-shadow var(--duration-standard); }
|
|
||||||
.company-row:hover { background: linear-gradient(160deg, rgba(32, 32, 32, 0.8) 0%, rgba(18, 18, 18, 0.85) 100%); border-color: var(--color-line-strong); box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25); }
|
|
||||||
.company-row:focus-visible { outline: 2px solid var(--color-primary-strong); outline-offset: 2px; }
|
|
||||||
.company-row-mark { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 10px; background: var(--color-primary-wash); color: var(--color-primary); font-weight: 800; font-size: 13px; }
|
|
||||||
.company-row.is-warning .company-row-mark { background: var(--color-warning-wash); color: var(--color-warning); }
|
|
||||||
.company-row.is-danger .company-row-mark { background: var(--color-danger-wash); color: var(--color-danger); }
|
|
||||||
.company-row-body { display: flex; flex-direction: column; min-width: 0; }
|
|
||||||
.company-row-body strong { font-size: 14px; }
|
|
||||||
.company-row-body small { color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.company-row-figure { display: flex; flex-direction: column; align-items: flex-end; text-align: right; min-width: 92px; }
|
|
||||||
.company-row-figure strong { font: 600 14px var(--font-data); color: var(--color-ink); }
|
|
||||||
.company-row-figure small { color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.company-row .status { flex: 0 0 auto; }
|
|
||||||
|
|
||||||
/* Timeline-strip: horizontal calculation window ribbon */
|
|
||||||
.timeline-strip { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 14px; align-items: stretch; padding: 16px 18px; border: 1px solid var(--color-line); border-radius: var(--radius-lg); background: linear-gradient(180deg, rgba(22, 22, 22, 0.86), rgba(10, 10, 10, 0.86)); box-shadow: var(--shadow-low); backdrop-filter: blur(22px) saturate(125%); }
|
|
||||||
.timeline-strip::before { content: ""; position: absolute; }
|
|
||||||
.timeline-legend { display: flex; flex-direction: column; justify-content: center; gap: 6px; }
|
|
||||||
.timeline-legend strong { font-size: 13px; }
|
|
||||||
.timeline-legend span { color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.timeline-body { position: relative; min-height: 88px; padding-top: 6px; }
|
|
||||||
.timeline-axis { position: relative; height: 14px; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); border-bottom: 1px solid var(--color-line); }
|
|
||||||
.timeline-axis span { font: 600 10px var(--font-data); color: var(--color-ink-muted); align-self: end; padding-bottom: 4px; text-align: left; }
|
|
||||||
.timeline-axis span + span { border-left: 1px solid var(--color-line); padding-left: 4px; }
|
|
||||||
.timeline-rows { display: grid; gap: 8px; margin-top: 12px; }
|
|
||||||
.timeline-row { position: relative; display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; gap: 10px; font-size: 11px; }
|
|
||||||
.timeline-row > span { color: var(--color-ink-soft); }
|
|
||||||
.timeline-track { position: relative; height: 14px; border-radius: 7px; background: rgba(255, 255, 255, 0.04); overflow: hidden; }
|
|
||||||
.timeline-track i { position: absolute; top: 0; bottom: 0; border-radius: inherit; }
|
|
||||||
.timeline-track i.coverage { background: linear-gradient(90deg, rgba(55, 235, 137, 0.35), rgba(55, 235, 137, 0.55)); box-shadow: inset 0 0 0 1px rgba(112, 255, 174, 0.32); }
|
|
||||||
.timeline-track i.warning { background: linear-gradient(90deg, rgba(255, 188, 82, 0.32), rgba(255, 188, 82, 0.52)); box-shadow: inset 0 0 0 1px rgba(255, 188, 82, 0.32); }
|
|
||||||
.timeline-track i.danger { background: linear-gradient(90deg, rgba(255, 98, 109, 0.32), rgba(255, 98, 109, 0.52)); box-shadow: inset 0 0 0 1px rgba(255, 98, 109, 0.32); }
|
|
||||||
.timeline-today { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--color-primary-strong); box-shadow: 0 0 12px rgba(112, 255, 174, 0.6); border-radius: 1px; }
|
|
||||||
.timeline-today::after { content: ""; position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 10px; height: 10px; border-radius: 50%; background: var(--color-primary-strong); box-shadow: 0 0 0 4px rgba(112, 255, 174, 0.18); }
|
|
||||||
.timeline-strip-panel { position: relative; }
|
|
||||||
|
|
||||||
/* Ledger and queries */
|
|
||||||
.inline-search { width: min(240px, 38vw); height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--color-line); border-radius: 11px; background: rgba(0, 0, 0, 0.18); color: var(--color-ink-muted); }
|
|
||||||
.inline-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--color-ink); }
|
|
||||||
.ledger-head, .company-ledger summary { display: grid; grid-template-columns: minmax(210px, 1.4fr) repeat(2, minmax(100px, 0.75fr)) minmax(150px, 0.9fr) 86px 24px; align-items: center; gap: 10px; }
|
|
||||||
.ledger-head { min-height: 42px; padding: 0 16px; border-bottom: 1px solid var(--color-line); color: var(--color-ink-muted); font-size: 10px; }
|
|
||||||
.company-ledger { border-top: 1px solid var(--color-line); }
|
|
||||||
.company-ledger:first-child { border-top: 0; }
|
|
||||||
.company-ledger summary { min-height: 72px; padding: 10px 16px; list-style: none; cursor: pointer; transition: background var(--duration-fast); }
|
|
||||||
.company-ledger summary::-webkit-details-marker { display: none; }
|
|
||||||
.company-ledger summary:hover { background: rgba(255, 255, 255, 0.035); }
|
|
||||||
.company-ledger summary > svg { transition: transform var(--duration-standard) var(--ease-out); }
|
|
||||||
.company-ledger[open] summary > svg { transform: rotate(180deg); }
|
|
||||||
.company-name { display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; column-gap: 10px; }
|
|
||||||
.company-name i { width: 36px; height: 36px; grid-row: 1 / 3; display: grid; place-items: center; border-radius: 12px; background: var(--color-primary-wash); color: var(--color-primary); font-style: normal; font-weight: 800; }
|
|
||||||
.company-name small { color: var(--color-ink-muted); }
|
|
||||||
.amount { font: 600 13px var(--font-data); }
|
|
||||||
.amount.debit { color: var(--color-positive); }
|
|
||||||
.amount.credit { color: var(--color-warning); }
|
|
||||||
.ledger-breakdown { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--color-line); background: rgba(0, 0, 0, 0.13); }
|
|
||||||
.ledger-breakdown section { padding: 14px 16px; }
|
|
||||||
.ledger-breakdown section + section { border-left: 1px solid var(--color-line); }
|
|
||||||
.ledger-breakdown header { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--color-ink-soft); }
|
|
||||||
.subject-row { width: 100%; min-height: 48px; display: grid; grid-template-columns: minmax(0, 1fr) auto 18px; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-top: 1px solid var(--color-line); background: transparent; text-align: left; cursor: pointer; }
|
|
||||||
.subject-row:hover { background: rgba(255, 255, 255, 0.035); }
|
|
||||||
.subject-row span { display: flex; flex-direction: column; }
|
|
||||||
.subject-row small { color: var(--color-ink-muted); }
|
|
||||||
.query-band, .filter-grid { padding: 17px; margin-bottom: 18px; }
|
|
||||||
.pair-query-form { display: grid; grid-template-columns: minmax(150px, 1fr) 38px minmax(150px, 1fr) minmax(150px, 0.8fr) auto; align-items: end; gap: 11px; }
|
|
||||||
.pair-report { overflow: hidden; }
|
|
||||||
.pair-report-heading { min-height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 18px; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.pair-report-heading p { color: var(--color-ink-muted); }
|
|
||||||
.pair-result { text-align: right; }
|
|
||||||
.pair-result strong { display: block; color: var(--color-primary); font: 700 22px var(--font-data); }
|
|
||||||
.pair-balance-line { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--color-line); }
|
|
||||||
.pair-balance-line div { min-height: 76px; display: flex; flex-direction: column; justify-content: center; padding: 12px 16px; border-left: 1px solid var(--color-line); }
|
|
||||||
.pair-balance-line div:first-child { border-left: 0; }
|
|
||||||
.pair-balance-line span, .pair-balance-line small { color: var(--color-ink-muted); }
|
|
||||||
.pair-balance-line strong { margin-top: 3px; font: 600 15px var(--font-data); }
|
|
||||||
.pair-final strong { color: var(--color-primary); font-size: 19px; }
|
|
||||||
.subject-strip { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--color-line); }
|
|
||||||
.subject-strip button { min-height: 62px; display: flex; flex-direction: column; justify-content: center; padding: 9px 14px; border: 0; border-left: 1px solid var(--color-line); background: rgba(255, 255, 255, 0.018); text-align: left; cursor: pointer; }
|
|
||||||
.subject-strip button:first-child { border-left: 0; }
|
|
||||||
.subject-strip button.is-active { background: var(--color-primary-wash); color: var(--color-primary); box-shadow: inset 0 -2px var(--color-primary); }
|
|
||||||
.subject-strip span { color: var(--color-ink-muted); font-size: 10px; }
|
|
||||||
|
|
||||||
/* Filters and tables */
|
|
||||||
.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px; margin-bottom: 18px; }
|
|
||||||
.segmented { display: flex; gap: 4px; padding: 4px; overflow-x: auto; border: 1px solid var(--color-line); border-radius: 13px; background: rgba(0, 0, 0, 0.18); }
|
|
||||||
.segmented button { min-height: 32px; padding: 0 11px; border: 0; border-radius: 9px; background: transparent; color: var(--color-ink-muted); white-space: nowrap; cursor: pointer; }
|
|
||||||
.segmented button.is-active { background: rgba(255, 255, 255, 0.09); color: var(--color-ink); }
|
|
||||||
.flow-filters { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)) minmax(200px, 1.4fr) auto; align-items: end; gap: 11px; }
|
|
||||||
.flow-filters .grow { min-width: 0; }
|
|
||||||
.table-summary { min-height: 51px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--color-line); color: var(--color-ink-muted); font-size: 11px; }
|
|
||||||
.table-scroll { max-width: 100%; overflow: auto; }
|
|
||||||
.data-table { width: 100%; min-width: 860px; border-collapse: collapse; }
|
|
||||||
.data-table th { height: 42px; padding: 8px 13px; border-bottom: 1px solid var(--color-line); background: rgba(255, 255, 255, 0.025); color: var(--color-ink-muted); font-size: 10px; font-weight: 500; text-align: left; white-space: nowrap; }
|
|
||||||
.data-table td { height: 55px; padding: 9px 13px; border-bottom: 1px solid rgba(255, 255, 255, 0.055); color: var(--color-ink-soft); vertical-align: middle; }
|
|
||||||
.data-table tbody tr { transition: background var(--duration-fast); }
|
|
||||||
.data-table tbody tr:hover { background: rgba(55, 235, 137, 0.035); }
|
|
||||||
.data-table tbody tr:last-child td { border-bottom: 0; }
|
|
||||||
.data-table td strong, .data-table td small { display: block; }
|
|
||||||
.data-table td strong { color: var(--color-ink); }
|
|
||||||
.data-table td small { color: var(--color-ink-muted); }
|
|
||||||
.data-table .number { color: var(--color-ink); text-align: right; font-family: var(--font-data); font-variant-numeric: tabular-nums; }
|
|
||||||
|
|
||||||
/* Settings, reminders and company work */
|
|
||||||
.settings-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; }
|
|
||||||
.form-body { display: grid; gap: 15px; padding: 17px; }
|
|
||||||
.panel form footer, form.panel footer { display: flex; justify-content: flex-end; gap: 9px; padding: 13px 17px; border-top: 1px solid var(--color-line); }
|
|
||||||
.closing-panel { grid-column: 1 / -1; }
|
|
||||||
.closing-checks { display: grid; grid-template-columns: repeat(4, 1fr); }
|
|
||||||
.closing-checks article { min-height: 75px; display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-left: 1px solid var(--color-line); }
|
|
||||||
.closing-checks article:first-child { border-left: 0; }
|
|
||||||
.closing-checks svg { color: var(--color-positive); }
|
|
||||||
.closing-checks .is-blocked svg { color: var(--color-danger); }
|
|
||||||
.closing-checks span { display: flex; flex-direction: column; }
|
|
||||||
.closing-checks small { color: var(--color-ink-muted); }
|
|
||||||
.closing-footer { min-height: 62px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--color-line); }
|
|
||||||
.closing-footer > span { margin-right: auto; color: var(--color-ink-muted); }
|
|
||||||
.reminder-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; }
|
|
||||||
.notification-list article { min-height: 76px; display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--color-line); }
|
|
||||||
.notification-list article:first-child { border-top: 0; }
|
|
||||||
.notification-list article.is-unread { background: rgba(102, 168, 255, 0.045); }
|
|
||||||
.notification-list article > span:nth-child(2) { display: flex; flex-direction: column; }
|
|
||||||
.notification-list small, .notification-list p { color: var(--color-ink-muted); }
|
|
||||||
.notification-list p { margin-top: 4px; }
|
|
||||||
.notification-icon { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 12px; background: rgba(255, 255, 255, 0.055); color: var(--color-ink-soft); }
|
|
||||||
.notification-icon.danger { background: var(--color-danger-wash); color: var(--color-danger); }
|
|
||||||
.notification-icon.warning { background: var(--color-warning-wash); color: var(--color-warning); }
|
|
||||||
.notification-icon.success { background: var(--color-positive-wash); color: var(--color-positive); }
|
|
||||||
.company-alert { min-height: 78px; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 14px; margin-bottom: 18px; padding: 14px 16px; border: 1px solid rgba(255, 98, 109, 0.22); border-radius: var(--radius-lg); background: var(--color-danger-wash); box-shadow: var(--shadow-low); }
|
|
||||||
.company-alert > svg { color: var(--color-danger); }
|
|
||||||
.company-alert p { color: #c18e92; }
|
|
||||||
.company-dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr); gap: 18px; }
|
|
||||||
.cashier-tasks article { min-height: 92px; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--color-line); }
|
|
||||||
.cashier-tasks article:first-child { border-top: 0; }
|
|
||||||
.cashier-tasks p, .cashier-tasks small { color: var(--color-ink-muted); }
|
|
||||||
.coverage-list article { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--color-line); }
|
|
||||||
.coverage-list article:first-child { border-top: 0; }
|
|
||||||
.coverage-list article > span { display: flex; flex-direction: column; }
|
|
||||||
.coverage-list small { color: var(--color-ink-muted); }
|
|
||||||
.work-progress { display: grid; grid-template-columns: minmax(130px, 1fr) 40px minmax(130px, 1fr) 40px minmax(130px, 1fr) 40px minmax(130px, 1fr); align-items: center; margin-top: 18px; padding: 18px; }
|
|
||||||
.work-progress div { display: flex; align-items: center; gap: 10px; }
|
|
||||||
.work-progress div > span { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 11px; background: var(--color-positive); color: var(--color-primary-dark); font-weight: 800; }
|
|
||||||
.work-progress p { display: flex; flex-direction: column; }
|
|
||||||
.work-progress small { color: var(--color-ink-muted); }
|
|
||||||
.work-progress i { height: 1px; background: var(--color-line-strong); }
|
|
||||||
.work-progress .pending > span { background: rgba(255, 255, 255, 0.065); color: var(--color-ink-muted); }
|
|
||||||
.reconcile-summary { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; overflow: hidden; }
|
|
||||||
.reconcile-summary div { min-height: 86px; display: flex; flex-direction: column; justify-content: center; padding: 14px 18px; border-left: 1px solid var(--color-line); }
|
|
||||||
.reconcile-summary div:first-child { border-left: 0; }
|
|
||||||
.reconcile-summary span, .reconcile-summary small { color: var(--color-ink-muted); }
|
|
||||||
.reconcile-summary strong { font: 600 19px var(--font-data); }
|
|
||||||
.review-list > article { padding: 16px; border-top: 1px solid var(--color-line); }
|
|
||||||
.review-list > article:first-child { border-top: 0; }
|
|
||||||
.review-main { display: grid; grid-template-columns: 38px 1fr; gap: 10px; }
|
|
||||||
.review-main p { color: var(--color-ink-muted); }
|
|
||||||
.candidate { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 13px 0 0 48px; padding: 12px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: rgba(0, 0, 0, 0.15); }
|
|
||||||
.candidate-options { display: grid; gap: 8px; margin: 13px 0 0 48px; padding: 12px; border: 1px solid var(--color-line); border-radius: var(--radius-md); }
|
|
||||||
.candidate-options legend { padding: 0 5px; color: var(--color-ink-muted); }
|
|
||||||
.candidate-options label { display: flex; align-items: center; gap: 9px; padding: 9px; border-radius: 11px; background: rgba(255, 255, 255, 0.035); }
|
|
||||||
.candidate-options input { accent-color: var(--color-primary); }
|
|
||||||
.candidate-options label span { display: flex; flex-direction: column; }
|
|
||||||
.candidate-options small { color: var(--color-ink-muted); }
|
|
||||||
.review-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 10px; }
|
|
||||||
.review-history { padding: 14px 16px; border-top: 1px solid var(--color-line); background: var(--color-positive-wash); }
|
|
||||||
.evidence-block { padding: 12px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: rgba(0, 0, 0, 0.16); }
|
|
||||||
.evidence-block strong, .evidence-block small { display: block; }
|
|
||||||
.evidence-block small { color: var(--color-ink-muted); }
|
|
||||||
.account-directory { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 16px; }
|
|
||||||
.account-directory article { overflow: hidden; border: 1px solid var(--color-line); border-radius: var(--radius-lg); background: var(--color-surface); box-shadow: var(--shadow-low); }
|
|
||||||
.account-directory header { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 15px; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.account-directory header div { display: flex; flex-direction: column; }
|
|
||||||
.account-directory header small { color: var(--color-ink-muted); }
|
|
||||||
.bank-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; background: var(--color-primary-wash); color: var(--color-primary); font-weight: 800; }
|
|
||||||
.account-directory dl { display: grid; grid-template-columns: repeat(3, 1fr); }
|
|
||||||
.account-directory dl div { padding: 12px; border-left: 1px solid var(--color-line); }
|
|
||||||
.account-directory dl div:first-child { border-left: 0; }
|
|
||||||
.account-directory dt { color: var(--color-ink-muted); font-size: 10px; }
|
|
||||||
.account-directory dd { margin-top: 3px; font-size: 11px; }
|
|
||||||
.manual-layout { display: grid; grid-template-columns: minmax(340px, 390px) minmax(0, 1fr); align-items: start; gap: 18px; }
|
|
||||||
.manual-records-table { min-width: 900px; }
|
|
||||||
|
|
||||||
/* Dialogs and feedback */
|
|
||||||
.dialog { width: min(580px, calc(100% - 28px)); padding: 0; overflow: hidden; border: 1px solid var(--color-line-strong); border-radius: var(--radius-lg); background: rgba(17, 17, 17, 0.96); color: var(--color-ink); box-shadow: var(--shadow-panel); backdrop-filter: blur(28px); }
|
|
||||||
.dialog::backdrop { background: rgba(0, 0, 0, 0.74); backdrop-filter: blur(6px); }
|
|
||||||
.dialog > form > header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.dialog header p { color: var(--color-ink-muted); }
|
|
||||||
.dialog-body { display: grid; gap: 15px; padding: 18px; }
|
|
||||||
.dialog > form > footer { display: flex; justify-content: flex-end; gap: 9px; padding: 13px 18px; border-top: 1px solid var(--color-line); }
|
|
||||||
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
||||||
.form-callout { display: flex; align-items: center; gap: 9px; padding: 10px; border: 1px solid rgba(102, 168, 255, 0.22); border-radius: 12px; background: var(--color-info-wash); color: #9ac6ff; }
|
|
||||||
.dropzone { min-height: 168px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 1px dashed rgba(255, 255, 255, 0.24); border-radius: var(--radius-md); background: rgba(0, 0, 0, 0.15); color: var(--color-ink-soft); text-align: center; transition: border-color var(--duration-fast), background var(--duration-fast); }
|
|
||||||
.dropzone:hover, .dropzone.is-dragging { border-color: var(--color-primary); background: var(--color-primary-wash); }
|
|
||||||
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
|
|
||||||
.dropzone > svg { width: 30px; height: 30px; color: var(--color-primary); }
|
|
||||||
.file-preview { display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--color-line); border-radius: var(--radius-md); }
|
|
||||||
.file-preview > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
|
|
||||||
.file-preview strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
||||||
.file-preview small { color: var(--color-ink-muted); }
|
|
||||||
.file-type { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--color-primary-wash); color: var(--color-primary); }
|
|
||||||
.parse-result { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: 10px; padding: 11px; border: 1px solid rgba(55, 235, 137, 0.22); border-radius: var(--radius-md); background: var(--color-positive-wash); }
|
|
||||||
.parse-result p { color: #9bd7b6; }
|
|
||||||
.parse-result.is-exception { border-color: rgba(255, 188, 82, 0.25); background: var(--color-warning-wash); }
|
|
||||||
.parse-result.is-exception p { color: #e7bd78; }
|
|
||||||
.sheet-review { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--color-line); }
|
|
||||||
.sheet-review h3 { font-size: 14px; }
|
|
||||||
.sheet-review-hint { margin-top: 4px; color: var(--color-ink-muted); font-size: 12px; line-height: 1.5; }
|
|
||||||
.sheet-list { display: grid; gap: 8px; margin-top: 10px; max-height: 220px; overflow-y: auto; }
|
|
||||||
.sheet-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 10px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: var(--color-surface-muted); }
|
|
||||||
.sheet-item.is-pending { border-color: rgba(255, 188, 82, 0.45); }
|
|
||||||
.sheet-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
||||||
.sheet-item-head strong { font-size: 13px; }
|
|
||||||
.sheet-item-head small { color: var(--color-ink-muted); }
|
|
||||||
.sheet-item-meta { margin-top: 5px; color: var(--color-ink-muted); font-size: 12px; line-height: 1.5; }
|
|
||||||
.sheet-item-actions { display: flex; align-items: center; gap: 6px; }
|
|
||||||
.sheet-item-actions .text-button { font-size: 12px; padding: 4px 8px; }
|
|
||||||
.sheet-item-reason { margin-top: 6px; padding: 6px 8px; border: 1px solid var(--color-line); border-radius: var(--radius-sm); color: var(--color-ink-muted); font-size: 12px; }
|
|
||||||
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: grid; gap: 8px; }
|
|
||||||
.toast { min-width: 280px; max-width: 390px; padding: 13px 15px; border: 1px solid var(--color-line-strong); border-radius: var(--radius-md); background: rgba(20, 20, 20, 0.96); color: var(--color-ink); box-shadow: var(--shadow-panel); backdrop-filter: blur(20px); }
|
|
||||||
.toast strong, .toast small { display: block; }
|
|
||||||
.toast small { color: var(--color-ink-muted); }
|
|
||||||
|
|
||||||
/* Login */
|
|
||||||
.entry-page { overflow-x: hidden; }
|
|
||||||
.entry-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(430px, 0.85fr); }
|
|
||||||
.entry-context { position: relative; min-height: 100vh; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(32px, 5vw, 76px); border-right: 1px solid var(--color-line); background: #080808; }
|
|
||||||
.entry-context::after { content: ""; position: absolute; inset: 12% 8% 12% auto; width: 1px; background: rgba(55, 235, 137, 0.32); box-shadow: 0 0 38px rgba(55, 235, 137, 0.45); }
|
|
||||||
.entry-brand { display: flex; align-items: center; gap: 12px; }
|
|
||||||
.entry-brand > span:last-child { display: flex; flex-direction: column; }
|
|
||||||
.entry-brand small { color: var(--color-ink-muted); }
|
|
||||||
.entry-statement { max-width: 680px; margin: 80px 0; }
|
|
||||||
.entry-statement h1 { max-width: 640px; font-size: clamp(38px, 5vw, 70px); line-height: 1.12; letter-spacing: 0; }
|
|
||||||
.entry-statement p { margin-top: 20px; color: var(--color-ink-muted); }
|
|
||||||
.entry-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 670px; }
|
|
||||||
.entry-facts div { padding: 15px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: var(--color-surface-muted); }
|
|
||||||
.entry-facts dt { color: var(--color-ink-muted); }
|
|
||||||
.entry-facts dd { margin-top: 4px; color: var(--color-primary); }
|
|
||||||
.entry-form-wrap { min-height: 100vh; display: grid; place-items: center; padding: 40px; background: var(--color-bg); }
|
|
||||||
.entry-form { width: min(420px, 100%); display: grid; gap: 18px; padding: 28px; border: 1px solid var(--color-line); border-radius: var(--radius-xl); background: var(--color-surface); box-shadow: var(--shadow-panel); backdrop-filter: blur(24px); }
|
|
||||||
.entry-form header h2 { font-size: 25px; }
|
|
||||||
.entry-form header p, .entry-note { color: var(--color-ink-muted); }
|
|
||||||
.role-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
|
|
||||||
.role-switch label { cursor: pointer; }
|
|
||||||
.role-switch input { position: absolute; opacity: 0; }
|
|
||||||
.role-switch span { min-height: 83px; display: grid; grid-template-columns: 30px 1fr; align-content: center; gap: 1px 9px; padding: 12px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: rgba(0, 0, 0, 0.14); transition: border-color var(--duration-fast), background var(--duration-fast), transform var(--duration-fast); }
|
|
||||||
.role-switch svg { grid-row: 1 / 3; align-self: center; color: var(--color-ink-muted); }
|
|
||||||
.role-switch small { color: var(--color-ink-muted); }
|
|
||||||
.role-switch input:checked + span { border-color: rgba(55, 235, 137, 0.4); background: var(--color-primary-wash); transform: translateY(-1px); }
|
|
||||||
.role-switch input:checked + span svg { color: var(--color-primary); }
|
|
||||||
.entry-note { font-size: 10px; }
|
|
||||||
|
|
||||||
@media (max-width: 1180px) {
|
|
||||||
.app-shell { grid-template-columns: 88px minmax(0, 1fr); }
|
|
||||||
.sidebar { width: 70px; padding-inline: 9px; }
|
|
||||||
.workspace { grid-column: 2; }
|
|
||||||
.brand { justify-content: center; padding-inline: 0; }
|
|
||||||
.brand-copy, .nav-item span, .nav-item b, .user-block > span:last-child, .company-context div { display: none; }
|
|
||||||
.nav-item { justify-content: center; padding: 0; }
|
|
||||||
.user-block, .company-context { justify-content: center; padding-inline: 0; }
|
|
||||||
.metric-grid { grid-template-columns: repeat(2, 1fr); }
|
|
||||||
.period-ribbon { grid-template-columns: repeat(3, 1fr); }
|
|
||||||
.period-ribbon > .period-warning { grid-column: 1 / -1; border-top: 1px solid var(--color-line); border-left: 0; }
|
|
||||||
.admin-dashboard-grid, .company-dashboard-grid { grid-template-columns: 1fr; }
|
|
||||||
.flow-filters { grid-template-columns: repeat(3, 1fr); }
|
|
||||||
.flow-filters .button { min-height: 40px; }
|
|
||||||
.manual-layout { grid-template-columns: 1fr; }
|
|
||||||
.account-directory { grid-template-columns: repeat(2, 1fr); }
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
|
||||||
main { padding-inline: 20px; }
|
|
||||||
.search-box { display: none; }
|
|
||||||
.settings-layout, .reminder-layout { grid-template-columns: 1fr; }
|
|
||||||
.pair-query-form { grid-template-columns: 1fr 40px 1fr; }
|
|
||||||
.pair-query-form .field:nth-of-type(3) { grid-column: 1 / 3; }
|
|
||||||
.pair-query-form .button { grid-column: 3; }
|
|
||||||
.ledger-head { display: none; }
|
|
||||||
.company-ledger summary { grid-template-columns: minmax(180px, 1.4fr) repeat(2, minmax(100px, 0.7fr)) 28px; }
|
|
||||||
.company-ledger summary > span:nth-child(4), .company-ledger summary > span:nth-child(5) { display: none; }
|
|
||||||
.ledger-breakdown { grid-template-columns: 1fr; }
|
|
||||||
.ledger-breakdown section + section { border-top: 1px solid var(--color-line); border-left: 0; }
|
|
||||||
.pair-balance-line { grid-template-columns: repeat(3, 1fr); }
|
|
||||||
.pair-balance-line .pair-final { grid-column: 1 / -1; border-top: 1px solid var(--color-line); border-left: 0; }
|
|
||||||
.subject-strip { grid-template-columns: repeat(3, 1fr); }
|
|
||||||
.work-progress { grid-template-columns: 1fr 24px 1fr; row-gap: 16px; }
|
|
||||||
.work-progress i:nth-of-type(2) { display: none; }
|
|
||||||
.entry-shell { grid-template-columns: 1fr; }
|
|
||||||
.entry-context { min-height: 58vh; border-right: 0; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.entry-form-wrap { min-height: auto; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 720px) {
|
|
||||||
.app-shell { display: block; }
|
|
||||||
.sidebar { inset: 10px auto 10px 10px; width: 242px; transform: translateX(calc(-100% - 20px)); transition: transform var(--duration-standard) var(--ease-out); }
|
|
||||||
.sidebar.is-open { transform: none; }
|
|
||||||
.sidebar.is-open .brand-copy, .sidebar.is-open .nav-item span, .sidebar.is-open .nav-item b, .sidebar.is-open .user-block > span:last-child, .sidebar.is-open .company-context div { display: flex; }
|
|
||||||
.sidebar.is-open .nav-item { justify-content: flex-start; padding: 0 12px; }
|
|
||||||
.sidebar.is-open .company-context { justify-content: flex-start; padding-inline: 10px; }
|
|
||||||
.workspace { display: block; }
|
|
||||||
.topbar { height: 64px; padding: 0 13px; gap: 9px; }
|
|
||||||
.menu-button { display: inline-grid; }
|
|
||||||
.workspace-name { min-width: 0; }
|
|
||||||
.workspace-name span { display: none; }
|
|
||||||
.demo-badge { padding: 2px 6px; }
|
|
||||||
.period-button { display: none; }
|
|
||||||
.topbar-actions .button { width: 40px; padding: 0; font-size: 0; }
|
|
||||||
main { padding: 12px 13px 42px; }
|
|
||||||
.page-heading { min-height: auto; flex-direction: column; margin-bottom: 18px; }
|
|
||||||
.page-heading h1 { font-size: 27px; }
|
|
||||||
.page-heading > .button { align-self: stretch; }
|
|
||||||
.metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
|
|
||||||
.metric-card { min-height: 128px; grid-template-columns: minmax(0, 1fr) 38px; padding: 15px; }
|
|
||||||
.metric-icon { width: 38px; height: 38px; border-radius: 12px; }
|
|
||||||
.metric-value { font-size: 25px; }
|
|
||||||
.period-ribbon { grid-template-columns: 1fr 1fr; }
|
|
||||||
.period-ribbon > div { min-height: 64px; }
|
|
||||||
.period-ribbon > div:nth-child(3) { border-top: 1px solid var(--color-line); border-left: 0; }
|
|
||||||
.period-warning { grid-column: 1 / -1; }
|
|
||||||
.panel-heading { min-height: 60px; padding: 11px 13px; }
|
|
||||||
.inline-search { display: none; }
|
|
||||||
.task-list button { grid-template-columns: 30px minmax(0, 1fr) 18px; padding-inline: 12px; }
|
|
||||||
.task-list button > b { display: none; }
|
|
||||||
.quick-pair-form { grid-template-columns: 1fr 38px 1fr; padding-inline: 12px; }
|
|
||||||
.quick-result { margin-inline: 12px; }
|
|
||||||
.company-ledger summary { grid-template-columns: minmax(145px, 1fr) 100px 24px; padding-inline: 12px; }
|
|
||||||
.company-ledger summary > strong:nth-of-type(2), .company-ledger summary > span:nth-child(4), .company-ledger summary > span:nth-child(5) { display: none; }
|
|
||||||
.company-name { grid-template-columns: 30px minmax(0, 1fr); }
|
|
||||||
.company-name i { width: 28px; height: 28px; }
|
|
||||||
.filter-bar { align-items: stretch; flex-direction: column; }
|
|
||||||
.segmented { width: 100%; }
|
|
||||||
.flow-filters { grid-template-columns: 1fr 1fr; }
|
|
||||||
.flow-filters .grow, .flow-filters .button { grid-column: 1 / -1; }
|
|
||||||
.pair-query-form { grid-template-columns: 1fr 38px 1fr; }
|
|
||||||
.pair-query-form .field:nth-of-type(3), .pair-query-form .button { grid-column: 1 / -1; }
|
|
||||||
.pair-report-heading { align-items: flex-start; flex-direction: column; }
|
|
||||||
.pair-balance-line { grid-template-columns: 1fr 1fr; }
|
|
||||||
.pair-balance-line .pair-final { grid-column: auto; border-left: 1px solid var(--color-line); }
|
|
||||||
.subject-strip { grid-template-columns: 1fr 1fr; }
|
|
||||||
.company-alert { grid-template-columns: 28px 1fr; }
|
|
||||||
.company-alert .button { grid-column: 1 / -1; }
|
|
||||||
.cashier-tasks article { grid-template-columns: 30px minmax(0, 1fr); }
|
|
||||||
.cashier-tasks .button { grid-column: 2; justify-self: start; }
|
|
||||||
.work-progress { grid-template-columns: 1fr; }
|
|
||||||
.work-progress i { display: none; }
|
|
||||||
.reconcile-summary { grid-template-columns: 1fr; }
|
|
||||||
.reconcile-summary div { min-height: 70px; border-top: 1px solid var(--color-line); border-left: 0; }
|
|
||||||
.reconcile-summary div:first-child { border-top: 0; }
|
|
||||||
.candidate, .candidate-options { align-items: stretch; flex-direction: column; margin-left: 0; }
|
|
||||||
.account-directory { grid-template-columns: 1fr; }
|
|
||||||
.account-directory dl { grid-template-columns: 1fr 1fr; }
|
|
||||||
.closing-checks { grid-template-columns: 1fr; }
|
|
||||||
.closing-checks article { border-top: 1px solid var(--color-line); border-left: 0; }
|
|
||||||
.closing-footer { align-items: stretch; flex-direction: column; }
|
|
||||||
.notification-list article { grid-template-columns: 34px minmax(0, 1fr); }
|
|
||||||
.notification-list article > em { grid-column: 2; justify-self: start; }
|
|
||||||
.table-summary { align-items: flex-start; flex-direction: column; justify-content: center; padding-block: 9px; }
|
|
||||||
.dialog { width: 100%; max-width: none; height: 100%; max-height: none; border-radius: 0; }
|
|
||||||
.dialog > form { min-height: 100%; display: flex; flex-direction: column; }
|
|
||||||
.dialog-body { flex: 1; }
|
|
||||||
.form-grid { grid-template-columns: 1fr; }
|
|
||||||
.toast-region { right: 12px; bottom: 12px; left: 12px; }
|
|
||||||
.toast { min-width: 0; max-width: none; }
|
|
||||||
.entry-context { min-height: auto; padding: 30px 22px; }
|
|
||||||
.entry-statement { margin: 54px 0 42px; }
|
|
||||||
.entry-statement h1 { font-size: 39px; }
|
|
||||||
.entry-facts { grid-template-columns: 1fr; }
|
|
||||||
.entry-form-wrap { padding: 32px 16px 48px; }
|
|
||||||
.entry-form { padding: 22px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 460px) {
|
|
||||||
.metric-card { min-height: 150px; padding: 13px; }
|
|
||||||
.metric-copy { min-height: 52px; }
|
|
||||||
.metric-label { font-size: 11px; }
|
|
||||||
.metric-value { font-size: 23px; }
|
|
||||||
.role-switch { grid-template-columns: 1fr; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 1180px) {
|
|
||||||
.timeline-strip { grid-template-columns: 1fr; }
|
|
||||||
.timeline-legend { padding-bottom: 4px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
|
||||||
.company-row { grid-template-columns: 34px minmax(0, 1fr) auto; }
|
|
||||||
.company-row-figure { display: none; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 720px) {
|
|
||||||
.timeline-strip { padding: 14px; }
|
|
||||||
.timeline-rows { gap: 6px; }
|
|
||||||
.timeline-row { grid-template-columns: 80px minmax(0, 1fr); }
|
|
||||||
.timeline-axis span { font-size: 9px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ===== 参考图对齐:胶囊搜索条 / 账期时间轴 / 右侧详情面板 ===== */
|
|
||||||
.content-toolbar > .search-box { border-radius: 999px; background: rgba(255, 255, 255, 0.045); backdrop-filter: blur(18px) saturate(120%); }
|
|
||||||
|
|
||||||
.timeline-panel { margin-top: 18px; padding: 18px; }
|
|
||||||
.timeline { padding: 10px 4px 0; }
|
|
||||||
.timeline-bar { position: relative; height: 14px; border: 1px solid var(--color-line); border-radius: 999px; background: rgba(255, 255, 255, 0.05); }
|
|
||||||
.timeline-seg, .timeline-gap { position: absolute; top: 2px; bottom: 2px; border-radius: 999px; }
|
|
||||||
.timeline-seg.is-closed { background: linear-gradient(90deg, rgba(55, 235, 137, 0.5), rgba(55, 235, 137, 0.28)); }
|
|
||||||
.timeline-seg.is-current { background: linear-gradient(90deg, rgba(255, 188, 82, 0.4), rgba(255, 188, 82, 0.18)); }
|
|
||||||
.timeline-gap { background: repeating-linear-gradient(45deg, rgba(255, 98, 109, 0.75) 0 6px, rgba(255, 98, 109, 0.35) 6px 12px); box-shadow: 0 0 12px rgba(255, 98, 109, 0.25); }
|
|
||||||
.timeline-today { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--color-primary-strong); box-shadow: 0 0 10px rgba(55, 235, 137, 0.6); }
|
|
||||||
.timeline-today::after { content: "今天"; position: absolute; top: -19px; right: 5px; font-size: 10px; font-style: normal; color: var(--color-primary-strong); white-space: nowrap; }
|
|
||||||
.timeline-ticks { position: relative; height: 34px; margin-top: 8px; }
|
|
||||||
.timeline-ticks span { position: absolute; display: flex; flex-direction: column; transform: translateX(-50%); font-size: 10px; color: var(--color-ink-muted); text-align: center; }
|
|
||||||
.timeline-ticks span:first-child { transform: none; text-align: left; }
|
|
||||||
.timeline-ticks span:last-child { transform: translateX(-100%); text-align: right; }
|
|
||||||
.timeline-ticks small { color: var(--color-ink-soft); }
|
|
||||||
.timeline-panel .timeline-legend { display: flex; flex-direction: row; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 11px; color: var(--color-ink-soft); }
|
|
||||||
.timeline-panel .timeline-legend li { display: flex; align-items: center; gap: 6px; }
|
|
||||||
.timeline-panel .dot { width: 8px; height: 8px; border-radius: 50%; }
|
|
||||||
.dot.success { background: var(--color-positive); }
|
|
||||||
.dot.warning { background: var(--color-warning); }
|
|
||||||
.dot.danger { background: var(--color-danger); }
|
|
||||||
.dot.today { background: var(--color-primary-strong); box-shadow: 0 0 6px rgba(55, 235, 137, 0.7); }
|
|
||||||
|
|
||||||
.detail-drawer { position: fixed; top: 16px; right: 16px; bottom: 16px; z-index: 80; width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; border: 1px solid var(--color-line-strong); border-radius: var(--radius-lg); background: linear-gradient(160deg, rgba(28, 28, 28, 0.92), rgba(12, 12, 12, 0.94)); box-shadow: var(--shadow-panel); backdrop-filter: blur(26px) saturate(125%); transform: translateX(calc(100% + 32px)); visibility: hidden; transition: transform var(--duration-standard) var(--ease-out), visibility var(--duration-standard); }
|
|
||||||
.detail-drawer.is-open { transform: none; visibility: visible; }
|
|
||||||
.detail-drawer > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 18px 12px; border-bottom: 1px solid var(--color-line); }
|
|
||||||
.detail-drawer h2 { margin-top: 8px; font-size: 17px; }
|
|
||||||
.detail-drawer .detail-desc { margin-top: 4px; color: var(--color-ink-muted); font-size: 12px; }
|
|
||||||
.detail-fields { display: grid; gap: 10px; margin: 0; padding: 14px 18px; overflow-y: auto; }
|
|
||||||
.detail-fields > div { display: flex; justify-content: space-between; gap: 14px; padding-bottom: 10px; border-bottom: 1px dashed var(--color-line); }
|
|
||||||
.detail-fields dt { flex-shrink: 0; color: var(--color-ink-muted); font-size: 12px; }
|
|
||||||
.detail-fields dd { margin: 0; text-align: right; font-size: 12px; }
|
|
||||||
.detail-tip { margin: 0 18px 12px; padding: 12px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: var(--color-surface-muted); color: var(--color-ink-soft); font-size: 12px; }
|
|
||||||
.detail-tip strong { display: block; margin-bottom: 4px; color: var(--color-ink); }
|
|
||||||
.detail-drawer > footer { display: flex; gap: 10px; margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--color-line); }
|
|
||||||
.detail-drawer > footer .button { flex: 1; justify-content: center; }
|
|
||||||
.detail-drawer .status { align-self: flex-start; }
|
|
||||||
[data-detail] { cursor: pointer; }
|
|
||||||
|
|
||||||
@media (max-width: 720px) {
|
|
||||||
.detail-drawer { top: 8px; right: 8px; bottom: 8px; width: calc(100vw - 16px); }
|
|
||||||
.timeline-panel { padding: 14px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ===== 质感打磨:玻璃光泽 / 氛围光 / 对比与呼吸感 ===== */
|
|
||||||
:root {
|
|
||||||
--radius-lg: 24px;
|
|
||||||
--radius-xl: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
body::before { content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none; background: radial-gradient(52vw 42vh at 62% 32%, rgba(55, 235, 137, 0.055), transparent 62%), radial-gradient(40vw 34vh at 90% 4%, rgba(102, 168, 255, 0.032), transparent 60%), radial-gradient(46vw 40vh at 28% 96%, rgba(55, 235, 137, 0.028), transparent 60%); }
|
|
||||||
.app-shell { position: relative; z-index: 0; }
|
|
||||||
|
|
||||||
.metric-card { border-color: rgba(255, 255, 255, 0.12); background: radial-gradient(120% 90% at 50% 108%, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.02) 42%, transparent 60%), linear-gradient(160deg, rgba(41, 41, 41, 0.86) 0%, rgba(23, 23, 23, 0.88) 50%, rgba(12, 12, 12, 0.9) 100%); }
|
|
||||||
.metric-card::before { background: radial-gradient(130% 100% at 50% 112%, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.03) 45%, transparent 62%), linear-gradient(165deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.05) 42%, transparent 72%); }
|
|
||||||
.panel::before, .period-ribbon::before, .reconcile-summary::before, .work-progress::before { background: radial-gradient(150% 110% at 50% 118%, rgba(255, 255, 255, 0.05), transparent 55%), linear-gradient(165deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.03) 40%, transparent 70%); }
|
|
||||||
|
|
||||||
.nav-item.is-active { border-color: rgba(255, 255, 255, 0.16); background: linear-gradient(160deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06)); box-shadow: inset 0 1px rgba(255, 255, 255, 0.14), 0 10px 26px rgba(0, 0, 0, 0.32), 0 0 18px rgba(55, 235, 137, 0.08); }
|
|
||||||
.metric-value { font-size: clamp(28px, 2.6vw, 38px); font-weight: 800; color: #ffffff; white-space: nowrap; }
|
|
||||||
|
|
||||||
.metric-grid { gap: 20px; margin-bottom: 20px; }
|
|
||||||
.admin-dashboard-grid { gap: 20px; margin-bottom: 20px; }
|
|
||||||
.company-dashboard-grid { gap: 20px; }
|
|
||||||
.page-heading { margin-bottom: 22px; }
|
|
||||||
|
|
||||||
@media (max-width: 720px) {
|
|
||||||
.metric-grid { gap: 10px; margin-bottom: 14px; }
|
|
||||||
.page-heading { margin-bottom: 18px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ===== 反馈修正:侧栏质感 + 模块间距统一 ===== */
|
|
||||||
.sidebar { border-color: rgba(255, 255, 255, 0.13); background: linear-gradient(170deg, rgba(26, 26, 26, 0.92), rgba(10, 10, 10, 0.94)); box-shadow: var(--shadow-panel), 0 0 44px rgba(55, 235, 137, 0.05); }
|
|
||||||
.sidebar::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(150% 110% at 50% 118%, rgba(255, 255, 255, 0.06), transparent 55%), linear-gradient(170deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02) 45%, transparent 70%); pointer-events: none; }
|
|
||||||
.nav-list { gap: 10px; }
|
|
||||||
.nav-item { min-height: 48px; border-radius: 16px; }
|
|
||||||
.user-block { border: 1px solid var(--color-line); border-radius: 16px; background: var(--color-surface-muted); }
|
|
||||||
|
|
||||||
.company-alert { margin-bottom: 20px; }
|
|
||||||
.period-ribbon { margin-bottom: 20px; }
|
|
||||||
.company-stack-panel { margin-bottom: 20px; }
|
|
||||||
.work-progress { margin-top: 20px; }
|
|
||||||
.timeline-panel { margin-top: 20px; }
|
|
||||||
|
|
||||||
/* ===== 反馈修正:整体提亮 + 列表改为玻璃行(去掉线条隔断) ===== */
|
|
||||||
:root {
|
|
||||||
--color-ink-soft: #b6c0ba;
|
|
||||||
--color-ink-muted: #99a39d;
|
|
||||||
}
|
|
||||||
|
|
||||||
.panel, .period-ribbon, .query-band, .filter-bar, .filter-grid, .pair-report, .work-progress, .reconcile-summary { border-color: rgba(255, 255, 255, 0.12); background: linear-gradient(160deg, rgba(37, 37, 37, 0.84) 0%, rgba(21, 21, 21, 0.87) 50%, rgba(12, 12, 12, 0.89) 100%); }
|
|
||||||
.panel::before, .period-ribbon::before, .reconcile-summary::before, .work-progress::before { background: radial-gradient(150% 110% at 50% 118%, rgba(255, 255, 255, 0.06), transparent 55%), linear-gradient(165deg, rgba(255, 255, 255, 0.13) 0%, rgba(255, 255, 255, 0.04) 40%, transparent 70%); }
|
|
||||||
|
|
||||||
.task-list, .cashier-tasks, .coverage-list, .notification-list, .review-list { display: grid; gap: 8px; padding: 12px 14px 14px; }
|
|
||||||
.task-list button, .cashier-tasks article, .coverage-list article, .notification-list article, .review-list > article, .subject-row { border: 1px solid var(--color-line); border-radius: var(--radius-md); background: linear-gradient(160deg, rgba(32, 32, 32, 0.72) 0%, rgba(15, 15, 15, 0.78) 100%); transition: background var(--duration-fast), border-color var(--duration-fast), box-shadow var(--duration-fast), transform var(--duration-fast); }
|
|
||||||
.task-list button:hover, .cashier-tasks article:hover, .coverage-list article:hover, .notification-list article:hover, .review-list > article:hover, .subject-row:hover { border-color: rgba(255, 255, 255, 0.2); background: linear-gradient(160deg, rgba(44, 44, 44, 0.82) 0%, rgba(22, 22, 22, 0.86) 100%); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28); }
|
|
||||||
.notification-list article.is-unread { border-color: rgba(102, 168, 255, 0.3); background: linear-gradient(160deg, rgba(102, 168, 255, 0.1), rgba(102, 168, 255, 0.04)); }
|
|
||||||
.company-ledger { margin: 8px 14px; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: linear-gradient(160deg, rgba(32, 32, 32, 0.72) 0%, rgba(15, 15, 15, 0.78) 100%); overflow: hidden; }
|
|
||||||
.company-ledger[open] { border-color: rgba(255, 255, 255, 0.18); }
|
|
||||||
.company-ledger:last-child { margin-bottom: 14px; }
|
|
||||||
|
|
||||||
.data-table { border-collapse: separate; border-spacing: 0 8px; }
|
|
||||||
.data-table th { height: 28px; padding: 0 13px; border-bottom: 0; background: transparent; }
|
|
||||||
.data-table td { border-bottom: 0; border-top: 1px solid var(--color-line); border-bottom: 1px solid var(--color-line); background: linear-gradient(160deg, rgba(32, 32, 32, 0.72) 0%, rgba(15, 15, 15, 0.78) 100%); }
|
|
||||||
.data-table td:first-child { border-left: 1px solid var(--color-line); border-radius: 12px 0 0 12px; }
|
|
||||||
.data-table td:last-child { border-right: 1px solid var(--color-line); border-radius: 0 12px 12px 0; }
|
|
||||||
.data-table tbody tr:hover td { background: linear-gradient(160deg, rgba(44, 44, 44, 0.85) 0%, rgba(22, 22, 22, 0.88) 100%); }
|
|
||||||
.data-table tbody tr:last-child td { border-bottom: 1px solid var(--color-line); }
|
|
||||||
.table-scroll { padding: 2px 14px 8px; }
|
|
||||||
.table-summary { margin: 0 14px; }
|
|
||||||
|
|
||||||
/* ===== 登录页重做:居中集团登录卡 ===== */
|
|
||||||
.entry-shell { display: grid; grid-template-columns: 1fr; place-items: center; min-height: 100vh; padding: 48px 20px; }
|
|
||||||
.entry-card { position: relative; width: min(470px, 100%); overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.13); border-radius: var(--radius-xl); background: linear-gradient(165deg, rgba(36, 36, 36, 0.9) 0%, rgba(16, 16, 16, 0.92) 60%, rgba(10, 10, 10, 0.94) 100%); box-shadow: var(--shadow-panel), 0 0 60px rgba(55, 235, 137, 0.06); backdrop-filter: blur(28px) saturate(125%); }
|
|
||||||
.entry-card::before { content: ""; position: absolute; inset: 0; background: radial-gradient(150% 110% at 50% 118%, rgba(255, 255, 255, 0.07), transparent 55%), linear-gradient(165deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.03) 42%, transparent 70%); pointer-events: none; }
|
|
||||||
.entry-card::after { content: ""; position: absolute; top: 0; left: 18%; right: 18%; height: 2px; background: linear-gradient(90deg, transparent, rgba(55, 235, 137, 0.65), transparent); }
|
|
||||||
.entry-brand { flex-direction: column; justify-content: center; gap: 15px; min-height: 0; padding: 36px 28px 24px; border-bottom: 1px solid var(--color-line); text-align: center; }
|
|
||||||
.entry-brand .brand-mark { width: 54px; height: 54px; border-radius: 17px; font-size: 26px; }
|
|
||||||
.entry-brand > span:last-child { align-items: center; }
|
|
||||||
.entry-brand strong { font-size: 21px; letter-spacing: 0.03em; }
|
|
||||||
.entry-brand small { margin-top: 4px; font-size: 12px; letter-spacing: 0.08em; }
|
|
||||||
.entry-form { width: 100%; gap: 16px; padding: 24px 28px 10px; border: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
|
|
||||||
.entry-form header { text-align: center; }
|
|
||||||
.entry-form header h2 { font-size: 22px; }
|
|
||||||
.entry-form header p { margin-top: 4px; color: var(--color-ink-muted); font-size: 12px; }
|
|
||||||
.entry-facts { max-width: none; gap: 10px; padding: 16px 28px 28px; }
|
|
||||||
.entry-facts div { padding: 12px; text-align: center; }
|
|
||||||
.entry-facts dd { margin-top: 2px; font-size: 12px; }
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
|
||||||
*, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user