Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c24abd53e | ||
|
|
0a7f70757d | ||
|
|
29dc7e040e | ||
|
|
c8387011cc | ||
|
|
5061de70f8 | ||
|
|
ea3ba25da5 | ||
|
|
bd7125fab8 | ||
|
|
94dd1fe677 | ||
|
|
fa6c9b1711 | ||
|
|
f4eacfafe2 | ||
|
|
f8c816dc38 | ||
|
|
e2d9049e45 |
@@ -319,26 +319,29 @@ def attach_common(conn, resource, items):
|
|||||||
def monthly_finance(conn, tenant="科普·无界"):
|
def monthly_finance(conn, tenant="科普·无界"):
|
||||||
from datetime import date
|
from datetime import date
|
||||||
today = date.today()
|
today = date.today()
|
||||||
# 12 months: 9 before + current + 2 after
|
# 6 months: 3 before + current + 2 after
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
start = today + relativedelta(months=-9)
|
start = today + relativedelta(months=-3)
|
||||||
months = []
|
months = []
|
||||||
for i in range(12):
|
for i in range(6):
|
||||||
m = start + relativedelta(months=i)
|
m = start + relativedelta(months=i)
|
||||||
months.append(m.strftime("%Y-%m"))
|
months.append(m.strftime("%Y-%m"))
|
||||||
data = []
|
data = []
|
||||||
for month in months:
|
for month in months:
|
||||||
def s(cat):
|
col_month = month.replace("-", "_")
|
||||||
return one(conn, "SELECT COALESCE(SUM(amount),0) AS v FROM finance_records WHERE month=? AND category=? AND tenant=?", (month, cat, tenant))["v"]
|
col_rev = f"rev_{col_month}"
|
||||||
revenue = s("确认收入") + s("签单")
|
col_gross = f"gross_{col_month}"
|
||||||
labor = s("人力成本")
|
# Only project_finances has columns for 2026-06 through 2026-09
|
||||||
expense = s("费用")
|
if month in ["2026-06", "2026-07", "2026-08", "2026-09"]:
|
||||||
purchase = s("外部采购")
|
revenue = one(conn, f"SELECT COALESCE(SUM({col_rev}),0) AS v FROM project_finances WHERE tenant=?", (tenant,))["v"]
|
||||||
net = revenue - labor - expense - purchase
|
gross = one(conn, f"SELECT COALESCE(SUM({col_gross}),0) AS v FROM project_finances WHERE tenant=?", (tenant,))["v"]
|
||||||
|
else:
|
||||||
|
revenue = 0
|
||||||
|
gross = 0
|
||||||
data.append({
|
data.append({
|
||||||
"month": month, "revenue": revenue,
|
"month": month, "revenue": revenue,
|
||||||
"labor": labor, "expense": expense, "purchase": purchase,
|
"labor": 0, "expense": 0, "purchase": 0,
|
||||||
"net_profit": net,
|
"net_profit": gross,
|
||||||
})
|
})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -361,24 +364,17 @@ def bootstrap():
|
|||||||
products = attach_common(conn, "products", q("SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", tenant))
|
products = attach_common(conn, "products", q("SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", tenant))
|
||||||
finance = q("SELECT * FROM finance_records WHERE tenant=? ORDER BY month DESC, id DESC", tenant)
|
finance = q("SELECT * FROM finance_records WHERE tenant=? ORDER BY month DESC, id DESC", tenant)
|
||||||
tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant)
|
tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant)
|
||||||
|
pfs = q("SELECT * FROM project_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
current_month = "2026-06"
|
current_month = "2026-06"
|
||||||
# Finance aggregates
|
# Finance aggregates — from project_finances (project-based)
|
||||||
def sum_cat(months, cat):
|
def pf_sum(field):
|
||||||
return sum(x["amount"] for x in finance if x["month"] in months and x.get("category") == cat)
|
return sum(x[field] or 0 for x in pfs)
|
||||||
months_2026 = [f"2026-{m:02d}" for m in range(1,7)]
|
rev_month = pf_sum("rev_2026_06")
|
||||||
months_q2 = ["2026-04","2026-05","2026-06"]
|
gross_month = pf_sum("gross_2026_06")
|
||||||
rev_annual = sum_cat(months_2026, "确认收入") + sum_cat(months_2026, "签单")
|
rev_q2 = pf_sum("rev_2026_06")
|
||||||
labor_annual = sum_cat(months_2026, "人力成本")
|
gross_q2 = pf_sum("gross_2026_06")
|
||||||
expense_annual = sum_cat(months_2026, "费用")
|
rev_annual = rev_q2
|
||||||
purchase_annual = sum_cat(months_2026, "外部采购")
|
gross_annual = gross_q2
|
||||||
rev_q2 = sum_cat(months_q2, "确认收入") + sum_cat(months_q2, "签单")
|
|
||||||
labor_q2 = sum_cat(months_q2, "人力成本")
|
|
||||||
expense_q2 = sum_cat(months_q2, "费用")
|
|
||||||
purchase_q2 = sum_cat(months_q2, "外部采购")
|
|
||||||
rev_month = sum_cat([current_month], "确认收入") + sum_cat([current_month], "签单")
|
|
||||||
labor_month = sum_cat([current_month], "人力成本")
|
|
||||||
expense_month = sum_cat([current_month], "费用")
|
|
||||||
purchase_month = sum_cat([current_month], "外部采购")
|
|
||||||
# Contract aggregates — time-based
|
# Contract aggregates — time-based
|
||||||
signed_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] == "已签约")
|
signed_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] == "已签约")
|
||||||
from datetime import date
|
from datetime import date
|
||||||
@@ -402,8 +398,8 @@ def bootstrap():
|
|||||||
"execution_projects": len([x for x in operations if x["project_type"] == "execution"]),
|
"execution_projects": len([x for x in operations if x["project_type"] == "execution"]),
|
||||||
"risk_projects": len([x for x in operations if x["project_status"] == "有风险" or x["risks"]]),
|
"risk_projects": len([x for x in operations if x["project_status"] == "有风险" or x["risks"]]),
|
||||||
"monthly_revenue": rev_month,
|
"monthly_revenue": rev_month,
|
||||||
"monthly_net_profit": rev_month - labor_month - expense_month - purchase_month,
|
"monthly_net_profit": gross_month,
|
||||||
"monthly_gross": rev_month - labor_month - expense_month - purchase_month,
|
"monthly_gross": gross_month,
|
||||||
"upcoming_products": len([x for x in products if x["status"] in ["规划中", "设计中", "开发中", "测试中"]]),
|
"upcoming_products": len([x for x in products if x["status"] in ["规划中", "设计中", "开发中", "测试中"]]),
|
||||||
"total_projects": len(operations),
|
"total_projects": len(operations),
|
||||||
"total_proposals": len(proposals),
|
"total_proposals": len(proposals),
|
||||||
@@ -416,14 +412,14 @@ def bootstrap():
|
|||||||
"pipeline_amount": pipeline_amount,
|
"pipeline_amount": pipeline_amount,
|
||||||
"revenue_annual": rev_annual,
|
"revenue_annual": rev_annual,
|
||||||
"revenue_q2": rev_q2,
|
"revenue_q2": rev_q2,
|
||||||
"gross_annual": rev_annual - labor_annual - expense_annual - purchase_annual,
|
"gross_annual": gross_annual,
|
||||||
"gross_q2": rev_q2 - labor_q2 - expense_q2 - purchase_q2,
|
"gross_q2": gross_q2,
|
||||||
"signed_not_executed": signed_not_executed,
|
"signed_not_executed": signed_not_executed,
|
||||||
},
|
},
|
||||||
"recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant),
|
"recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant),
|
||||||
"risks": [{"title": "执行提醒", "content": x["next_action"]} for x in operations if x["next_action"]][:5],
|
"risks": [{"title": "执行提醒", "content": x["next_action"]} for x in operations if x["next_action"]][:5],
|
||||||
}
|
}
|
||||||
return jsonify({"summary": summary, "sales": sales, "proposals": proposals, "operations": operations, "products": products, "finance": finance, "financeMonthly": monthly_finance(conn, tenant), "tasks": tasks, "tenant": tenant, "tenants": ["科普·无界","科研·无界","医患·无界"]})
|
return jsonify({"summary": summary, "sales": sales, "proposals": proposals, "operations": operations, "products": products, "finance": finance, "projectFinances": pfs, "financeMonthly": monthly_finance(conn, tenant), "tasks": tasks, "tenant": tenant, "tenants": ["科普·无界","科研·无界","医患·无界"]})
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
@@ -435,6 +431,7 @@ TABLES = {
|
|||||||
"products": ("product_versions", ["product_name", "version", "version_goal", "feature_list", "launch_date", "status", "platform", "notes", "tenant"]),
|
"products": ("product_versions", ["product_name", "version", "version_goal", "feature_list", "launch_date", "status", "platform", "notes", "tenant"]),
|
||||||
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
||||||
"tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "tenant"]),
|
"tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "tenant"]),
|
||||||
|
"projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "status", "sales_person", "rev_2026_06", "rev_2026_07", "rev_2026_08", "rev_2026_09", "gross_2026_06", "gross_2026_07", "gross_2026_08", "gross_2026_09"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
119
static/app.js
119
static/app.js
File diff suppressed because one or more lines are too long
@@ -554,6 +554,9 @@ td {
|
|||||||
.task-row:hover { background: #f8fafc; }
|
.task-row:hover { background: #f8fafc; }
|
||||||
.task-dot { display: flex; color: #cbd5e1; flex-shrink: 0; cursor: pointer; }
|
.task-dot { display: flex; color: #cbd5e1; flex-shrink: 0; cursor: pointer; }
|
||||||
.task-dot:hover { color: #6366f1; }
|
.task-dot:hover { color: #6366f1; }
|
||||||
|
.task-grip { display: flex; color: #cbd5e1; flex-shrink: 0; cursor: grab; }
|
||||||
|
.task-grip:hover { color: #94a3b8; }
|
||||||
|
.task-grip:active { cursor: grabbing; }
|
||||||
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||||
.task-name { color: #1e293b; font-size: 13px; }
|
.task-name { color: #1e293b; font-size: 13px; }
|
||||||
.task-desc { color: #94a3b8; font-size: 12px; word-wrap: break-word; overflow-wrap: break-word; }
|
.task-desc { color: #94a3b8; font-size: 12px; word-wrap: break-word; overflow-wrap: break-word; }
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<p class="eyebrow text-xs font-semibold uppercase tracking-[0.18em] text-blue-700">OPC Manager</p>
|
<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">
|
<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)">
|
<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>
|
||||||
<option value="科研·无界">科研·无界</option>
|
<option value="科研·无界">科研·无界</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user