首页:新增回款/费用卡片 + 统计口径对齐 + UI 优化
- 新增回款金额、费用金额 2 个卡片(5 列布局) - 卡片标题统一为 年度累计/季度累计/本月新增 - 季度计算改为动态本季度(不再写死 Q2) - 卡片数字统一取整(moneyInt) - 财务趋势图只统计已签约项目(与卡片口径对齐) - net_profit 字段重命名为 gross(消除命名误导) - 近期动态删除图标改为 trash-2(与附件删除一致)
This commit is contained in:
@@ -685,7 +685,7 @@ def attach_common(conn, resource, items):
|
||||
def monthly_finance(conn, tenant="科普·无界"):
|
||||
months = [f"2026-{m:02d}" for m in range(1, 13)]
|
||||
pfs = rows(conn,
|
||||
"SELECT sign_amount, sign_month, status, budget_data FROM project_finances WHERE tenant=?",
|
||||
"SELECT sign_amount, sign_month, status, budget_data FROM project_finances WHERE tenant=? AND status='已签约'",
|
||||
[tenant])
|
||||
|
||||
# 预解析 budget_data:{pf_index: {month_key: {rev, gross, payment, cost}}}
|
||||
@@ -722,7 +722,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
||||
data.append({
|
||||
"month": month, "revenue": revenue,
|
||||
"labor": 0, "expense": 0, "purchase": 0,
|
||||
"net_profit": gross,
|
||||
"gross": gross,
|
||||
"sign": sign, "payment": payment, "cost": cost,
|
||||
})
|
||||
return data
|
||||
@@ -777,22 +777,33 @@ def bootstrap():
|
||||
total += float(b.get(field) or 0)
|
||||
return total
|
||||
|
||||
# 本季度月份范围(Q1=1-3, Q2=4-6, Q3=7-9, Q4=10-12),基于当前月
|
||||
_now_month = date.today().month
|
||||
_q_start = ((_now_month - 1) // 3) * 3 + 1
|
||||
_q_range = range(_q_start, _q_start + 3)
|
||||
rev_annual = sum_budget("rev", range(1, 13))
|
||||
gross_annual = sum_budget("gross", range(1, 13))
|
||||
rev_q2 = sum_budget("rev", range(4, 7))
|
||||
gross_q2 = sum_budget("gross", range(4, 7))
|
||||
rev_month = sum_budget("rev", [6])
|
||||
gross_month = sum_budget("gross", [6])
|
||||
rev_q2 = sum_budget("rev", _q_range)
|
||||
gross_q2 = sum_budget("gross", _q_range)
|
||||
rev_month = sum_budget("rev", [_now_month])
|
||||
gross_month = sum_budget("gross", [_now_month])
|
||||
payment_annual = sum_budget("payment", range(1, 13))
|
||||
cost_annual = sum_budget("cost", range(1, 13))
|
||||
payment_q2 = sum_budget("payment", _q_range)
|
||||
cost_q2 = sum_budget("cost", _q_range)
|
||||
payment_month = sum_budget("payment", [_now_month])
|
||||
cost_month = sum_budget("cost", [_now_month])
|
||||
# Contract aggregates — from project_finances (经营管理项目)
|
||||
def pf_status_sum(status):
|
||||
return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status)
|
||||
signed_amount = pf_status_sum("已签约")
|
||||
# 年度签约 = 所有已签约项目 2026 年的签约金额
|
||||
signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约")
|
||||
# Q2 签约 = 签约月份在 2026-04~2026-06 的已签约项目
|
||||
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in ["2026-04","2026-05","2026-06"])
|
||||
# 本月签约 = 签约月份为 2026-06 的已签约项目
|
||||
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "") == "2026-06")
|
||||
# 本季度签约 = 签约月份在当前季度的已签约项目
|
||||
_q_months = [f"2026-{m:02d}" for m in _q_range]
|
||||
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months)
|
||||
# 本月签约 = 签约月份为当月的已签约项目
|
||||
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_now_month:02d}")
|
||||
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
||||
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
||||
summary = {
|
||||
@@ -819,6 +830,12 @@ def bootstrap():
|
||||
"revenue_q2": rev_q2,
|
||||
"gross_annual": gross_annual,
|
||||
"gross_q2": gross_q2,
|
||||
"payment_annual": payment_annual,
|
||||
"payment_q2": payment_q2,
|
||||
"payment_month": payment_month,
|
||||
"cost_annual": cost_annual,
|
||||
"cost_q2": cost_q2,
|
||||
"cost_month": cost_month,
|
||||
"signed_not_executed": signed_not_executed,
|
||||
},
|
||||
"recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant),
|
||||
|
||||
Reference in New Issue
Block a user