v2.0.6 — X轴12月(前9+当前+后2) + Y轴万元 + 净利口径=确认收入-人力-费用-采购
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user