Compare commits

..

2 Commits

4 changed files with 16 additions and 7 deletions

View File

@@ -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

View File

@@ -1 +1,2 @@
Flask==3.0.3
python-dateutil==2.9.0

View File

@@ -249,6 +249,8 @@ window.switchTab = switchTab;
window.switchTenant = (tenant) => {
state.tenant = tenant;
state.projectView = null;
const label = tenant.replace("·无界", "");
document.querySelector("#workspaceTitle").textContent = label + " OPC 工作台";
load();
};
@@ -457,7 +459,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 + "万" } } } },
});
}

View File

@@ -31,7 +31,7 @@
<div>
<p class="eyebrow text-xs font-semibold uppercase tracking-[0.18em] text-blue-700">OPC Manager</p>
<div class="flex items-center gap-3 mt-1">
<h1 class="text-2xl font-semibold">无界 OPC 工作台</h1>
<h1 class="text-2xl font-semibold" id="workspaceTitle">科普 OPC 工作台</h1>
<select id="tenantSelect" class="rounded-md border border-slate-200 bg-white px-3 py-1.5 text-sm font-medium text-slate-700 outline-none focus:border-blue-500" onchange="switchTenant(this.value)">
<option value="科普·无界">科普·无界</option>
<option value="科研·无界">科研·无界</option>