From 1b0049e34272005abe1494c097f2c4eec34895cc Mon Sep 17 00:00:00 2001 From: mac Date: Tue, 16 Jun 2026 15:56:21 +0800 Subject: [PATCH] =?UTF-8?q?v2.0.6=20=E2=80=94=20X=E8=BD=B412=E6=9C=88(?= =?UTF-8?q?=E5=89=8D9+=E5=BD=93=E5=89=8D+=E5=90=8E2)=20+=20Y=E8=BD=B4?= =?UTF-8?q?=E4=B8=87=E5=85=83=20+=20=E5=87=80=E5=88=A9=E5=8F=A3=E5=BE=84?= =?UTF-8?q?=3D=E7=A1=AE=E8=AE=A4=E6=94=B6=E5=85=A5-=E4=BA=BA=E5=8A=9B-?= =?UTF-8?q?=E8=B4=B9=E7=94=A8-=E9=87=87=E8=B4=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/flask_app.py | 16 +++++++++++----- backend/requirements.txt | 1 + static/app.js | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/flask_app.py b/backend/flask_app.py index 4eb6ee4..d54c061 100644 --- a/backend/flask_app.py +++ b/backend/flask_app.py @@ -317,19 +317,26 @@ def attach_common(conn, resource, items): def monthly_finance(conn, tenant="科普·无界"): + from datetime import date + today = date.today() + # 12 months: 9 before + current + 2 after + from dateutil.relativedelta import relativedelta + start = today + relativedelta(months=-9) + months = [] + for i in range(12): + m = start + relativedelta(months=i) + months.append(m.strftime("%Y-%m")) data = [] - for item in rows(conn, "SELECT DISTINCT month FROM finance_records WHERE tenant=? ORDER BY month", (tenant,)): - month = item["month"] + for month in months: def s(cat): return one(conn, "SELECT COALESCE(SUM(amount),0) AS v FROM finance_records WHERE month=? AND category=? AND tenant=?", (month, cat, tenant))["v"] revenue = s("确认收入") + s("签单") labor = s("人力成本") expense = s("费用") purchase = s("外部采购") - sign = s("签单") net = revenue - labor - expense - purchase data.append({ - "month": month, "revenue": revenue, "sign": sign, + "month": month, "revenue": revenue, "labor": labor, "expense": expense, "purchase": purchase, "net_profit": net, }) @@ -372,7 +379,6 @@ def bootstrap(): labor_month = sum_cat([current_month], "人力成本") expense_month = sum_cat([current_month], "费用") purchase_month = sum_cat([current_month], "外部采购") - cost_month = sum_finance([current_month], "cost_expense") # Contract aggregates — time-based signed_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] == "已签约") from datetime import date diff --git a/backend/requirements.txt b/backend/requirements.txt index 95fef4e..26a5be3 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1 +1,2 @@ Flask==3.0.3 +python-dateutil==2.9.0 diff --git a/static/app.js b/static/app.js index 278185b..96766f3 100644 --- a/static/app.js +++ b/static/app.js @@ -457,7 +457,7 @@ function renderFinanceChart() { { label: "月度净利", data: financeMonthly.map((x) => x.net_profit), borderColor: "#059669", tension: 0.3, borderDash: [5,3] }, ], }, - options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: "bottom", labels: { boxWidth: 12, font: { size: 11 } } } }, scales: { x: { ticks: { font: { size: 11 } }, grid: { display: false } }, y: { ticks: { font: { size: 11 } } } } }, + options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: "bottom", labels: { boxWidth: 12, font: { size: 11 } } } }, scales: { x: { ticks: { font: { size: 11 } }, grid: { display: false } }, y: { ticks: { font: { size: 11 }, callback: (v) => v + "万" } } } }, }); }