Add deals feature for reconciled transactions

- Create deals schema and routes to group matched transactions
- Display deals in a new card on the Transactions page
- Generate deals during reconciliation and refresh them on demand
This commit is contained in:
2026-05-05 20:13:11 +08:00
parent 6d15c2a51f
commit 784da617a9
5 changed files with 261 additions and 29 deletions
+36 -2
View File
@@ -20,6 +20,7 @@ export default function Transactions() {
const [reconciling, setReconciling] = useState(false);
const [classifying, setClassifying] = useState(false);
const [classifyProgress, setClassifyProgress] = useState(0);
const [deals, setDeals] = useState(null);
// 恢复分类进度(刷新后轮询)
useEffect(() => {
@@ -86,9 +87,15 @@ export default function Transactions() {
);
}
async function loadDeals() {
try { const res = await fetch("/api/deals"); const d = await res.json(); setDeals(d.deals); } catch (e) {}
}
useEffect(() => { loadDeals(); }, []);
async function handleReconcile() {
setReconciling(true);
try { const r = await runReconciliation(); alert(`对账完成!成功匹配 ${r.matched} 对`); loadTransactions(); } catch (err) {}
try { const r = await runReconciliation(); loadDeals(); alert(`对账完成!成功匹配 ${r.matched} 对`); loadTransactions(); } catch (err) {}
setReconciling(false);
}
@@ -225,7 +232,34 @@ export default function Transactions() {
)}
</div>
{editingTx && (
{/* 关联交易 */}
{deals && deals.length > 0 && (
<div className="card" style={{ marginTop: 20 }}>
<div className="card-header"><h3>🔗 关联交易(Deal)</h3><span style={{ fontSize: 13, color: "var(--text-secondary)" }}>共 {deals.length} 条对账关联</span></div>
<div className="table-container"><table>
<thead><tr><th>日期</th><th>金额</th><th>对方</th><th>关联明细</th></tr></thead>
<tbody>
{deals.map(d => (
<tr key={d.id}>
<td style={{ whiteSpace: "nowrap", fontSize: 13 }}>{d.deal_date}</td>
<td style={{ fontWeight: 600, whiteSpace: "nowrap" }} className={parseFloat(d.amount) >= 0 ? "stat-value income" : "stat-value expense"}>{formatAmount(d.amount)}</td>
<td>{d.counterparty || "--"}</td>
<td style={{ fontSize: 12, color: "var(--text-secondary)" }}>
{d.transactions?.map((t,i) => (
<span key={i} style={{ marginRight: 8 }}>
<span className={"source-type-label source-" + t.source_type}>{SOURCE_TYPE_MAP[t.source_type]}</span>
{" "}{t.description?.substring(0,20)}↔
</span>
))}
</td>
</tr>
))}
</tbody>
</table></div>
</div>
)}
{editingTx && (
<div className="modal-overlay" onClick={() => setEditingTx(null)}>
<div className="modal" onClick={e => e.stopPropagation()}>
<h3>编辑交易</h3>