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="科普·无界"):
|
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 = []
|
data = []
|
||||||
for item in rows(conn, "SELECT DISTINCT month FROM finance_records WHERE tenant=? ORDER BY month", (tenant,)):
|
for month in months:
|
||||||
month = item["month"]
|
|
||||||
def s(cat):
|
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"]
|
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("签单")
|
revenue = s("确认收入") + s("签单")
|
||||||
labor = s("人力成本")
|
labor = s("人力成本")
|
||||||
expense = s("费用")
|
expense = s("费用")
|
||||||
purchase = s("外部采购")
|
purchase = s("外部采购")
|
||||||
sign = s("签单")
|
|
||||||
net = revenue - labor - expense - purchase
|
net = revenue - labor - expense - purchase
|
||||||
data.append({
|
data.append({
|
||||||
"month": month, "revenue": revenue, "sign": sign,
|
"month": month, "revenue": revenue,
|
||||||
"labor": labor, "expense": expense, "purchase": purchase,
|
"labor": labor, "expense": expense, "purchase": purchase,
|
||||||
"net_profit": net,
|
"net_profit": net,
|
||||||
})
|
})
|
||||||
@@ -372,7 +379,6 @@ def bootstrap():
|
|||||||
labor_month = sum_cat([current_month], "人力成本")
|
labor_month = sum_cat([current_month], "人力成本")
|
||||||
expense_month = sum_cat([current_month], "费用")
|
expense_month = sum_cat([current_month], "费用")
|
||||||
purchase_month = sum_cat([current_month], "外部采购")
|
purchase_month = sum_cat([current_month], "外部采购")
|
||||||
cost_month = sum_finance([current_month], "cost_expense")
|
|
||||||
# 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
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
Flask==3.0.3
|
Flask==3.0.3
|
||||||
|
python-dateutil==2.9.0
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ function renderFinanceChart() {
|
|||||||
{ label: "月度净利", data: financeMonthly.map((x) => x.net_profit), borderColor: "#059669", tension: 0.3, borderDash: [5,3] },
|
{ 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 + "万" } } } },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user