Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b0049e342 |
@@ -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
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
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] },
|
||||
],
|
||||
},
|
||||
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