This commit is contained in:
@@ -80,13 +80,14 @@ def monthly_finance(conn, tenant="科普·无界"):
|
||||
"gross": float(b.get("gross") or 0),
|
||||
"payment": float(b.get("payment") or 0),
|
||||
"cost": float(b.get("cost") or 0),
|
||||
"paid": float(b.get("paid") or 0),
|
||||
}
|
||||
parsed_budgets.append((pf, budget_map))
|
||||
|
||||
data = []
|
||||
for month in months:
|
||||
key = month.replace("-", "_")
|
||||
revenue = gross = payment = cost = sign = 0
|
||||
revenue = gross = payment = cost = paid = sign = 0
|
||||
for pf, budget_map in parsed_budgets:
|
||||
if pf["status"] == "已签约" and (pf.get("sign_month") or "") == month:
|
||||
sign += float(pf["sign_amount"] or 0)
|
||||
@@ -96,10 +97,14 @@ def monthly_finance(conn, tenant="科普·无界"):
|
||||
gross += b["gross"]
|
||||
payment += b["payment"]
|
||||
cost += b["cost"]
|
||||
paid += b["paid"]
|
||||
data.append({
|
||||
"month": month, "revenue": revenue,
|
||||
"labor": 0, "expense": 0, "purchase": 0,
|
||||
"gross": gross,
|
||||
"sign": sign, "payment": payment, "cost": cost,
|
||||
"month": month,
|
||||
"revenue": round(revenue, 2),
|
||||
"gross": round(gross, 2),
|
||||
"payment": round(payment, 2),
|
||||
"cost": round(cost, 2),
|
||||
"paid": round(paid, 2),
|
||||
"sign": round(sign, 2),
|
||||
})
|
||||
return data
|
||||
|
||||
@@ -322,15 +322,30 @@ def bootstrap():
|
||||
all_metrics[-1]["expense_month"] = t_expense_sum([_now_month])
|
||||
all_metrics[-1]["expense_prev_q"] = t_expense_sum(_prev_q_range)
|
||||
all_metrics[-1]["expense_prev_month"] = t_expense_sum([_prev_month]) if _prev_month else 0
|
||||
all_metrics[-1]["paid_annual"] = t_sum_budget("paid", range(1, 13))
|
||||
all_metrics[-1]["paid_q2"] = t_sum_budget("paid", _q_range)
|
||||
all_metrics[-1]["paid_month"] = t_sum_budget("paid", [_now_month])
|
||||
all_metrics[-1]["paid_prev_q"] = t_sum_budget("paid", _prev_q_range)
|
||||
all_metrics[-1]["paid_prev_month"] = t_sum_budget("paid", [_prev_month]) if _prev_month else 0
|
||||
all_metrics[-1]["cashflow_annual"] = all_metrics[-1]["payment_annual"] - all_metrics[-1]["paid_annual"]
|
||||
all_metrics[-1]["cashflow_q2"] = all_metrics[-1]["payment_q2"] - all_metrics[-1]["paid_q2"]
|
||||
all_metrics[-1]["cashflow_month"] = all_metrics[-1]["payment_month"] - all_metrics[-1]["paid_month"]
|
||||
all_metrics[-1]["cashflow_prev_q"] = all_metrics[-1]["payment_prev_q"] - all_metrics[-1]["paid_prev_q"]
|
||||
all_metrics[-1]["cashflow_prev_month"] = all_metrics[-1]["payment_prev_month"] - all_metrics[-1]["paid_prev_month"]
|
||||
all_metrics[-1]["profit_annual"] = all_metrics[-1]["gross_annual"] - all_metrics[-1]["expense_annual"]
|
||||
all_metrics[-1]["profit_q2"] = all_metrics[-1]["gross_q2"] - all_metrics[-1]["expense_q2"]
|
||||
all_metrics[-1]["profit_month"] = all_metrics[-1]["monthly_net_profit"] - all_metrics[-1]["expense_month"]
|
||||
all_metrics[-1]["profit_prev_q"] = all_metrics[-1]["gross_prev_q"] - all_metrics[-1]["expense_prev_q"]
|
||||
all_metrics[-1]["profit_prev_month"] = all_metrics[-1]["gross_prev_month"] - all_metrics[-1]["expense_prev_month"]
|
||||
all_monthly.append(monthly_finance(conn, t))
|
||||
all_recent.extend(rows(conn, "SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 4", [t]))
|
||||
agg = {}
|
||||
for key in ["total_projects","total_proposals","total_products","upcoming_products","signed_amount","signed_annual","signed_q2","signed_month","signed_prev_q","signed_prev_month","revenue_annual","revenue_q2","monthly_revenue","revenue_prev_q","revenue_prev_month","gross_annual","gross_q2","monthly_net_profit","gross_prev_q","gross_prev_month","payment_annual","payment_q2","payment_month","payment_prev_q","payment_prev_month","cost_annual","cost_q2","cost_month","cost_prev_q","cost_prev_month","expense_annual","expense_q2","expense_month","expense_prev_q","expense_prev_month"]:
|
||||
for key in ["total_projects","total_proposals","total_products","upcoming_products","signed_amount","signed_annual","signed_q2","signed_month","signed_prev_q","signed_prev_month","revenue_annual","revenue_q2","monthly_revenue","revenue_prev_q","revenue_prev_month","gross_annual","gross_q2","monthly_net_profit","gross_prev_q","gross_prev_month","payment_annual","payment_q2","payment_month","payment_prev_q","payment_prev_month","cost_annual","cost_q2","cost_month","cost_prev_q","cost_prev_month","expense_annual","expense_q2","expense_month","expense_prev_q","expense_prev_month","paid_annual","paid_q2","paid_month","paid_prev_q","paid_prev_month","cashflow_annual","cashflow_q2","cashflow_month","cashflow_prev_q","cashflow_prev_month","profit_annual","profit_q2","profit_month","profit_prev_q","profit_prev_month"]:
|
||||
agg[key] = sum(m.get(key, 0) for m in all_metrics)
|
||||
merged_monthly = []
|
||||
for i in range(12):
|
||||
m = {"month": all_monthly[0][i]["month"] if all_monthly and len(all_monthly[0]) > i else f"2026-{i+1:02d}"}
|
||||
for field in ["revenue","gross","payment","cost","sign"]:
|
||||
for field in ["revenue","gross","payment","cost","paid","sign"]:
|
||||
m[field] = sum(tl[i][field] if i < len(tl) else 0 for tl in all_monthly)
|
||||
merged_monthly.append(m)
|
||||
summary = {
|
||||
@@ -412,6 +427,21 @@ def bootstrap():
|
||||
expense_month_val = expense_sum([_now_month])
|
||||
expense_prev_q = expense_sum(_prev_q_range)
|
||||
expense_prev_month = expense_sum([_prev_month]) if _prev_month else 0
|
||||
paid_annual = sum_budget("paid", range(1, 13))
|
||||
paid_q2 = sum_budget("paid", _q_range)
|
||||
paid_month = sum_budget("paid", [_now_month])
|
||||
paid_prev_q = sum_budget("paid", _prev_q_range)
|
||||
paid_prev_month = sum_budget("paid", [_prev_month]) if _prev_month else 0
|
||||
cashflow_annual = payment_annual - paid_annual
|
||||
cashflow_q2 = payment_q2 - paid_q2
|
||||
cashflow_month = payment_month - paid_month
|
||||
cashflow_prev_q = payment_prev_q - paid_prev_q
|
||||
cashflow_prev_month = payment_prev_month - paid_prev_month
|
||||
profit_annual = gross_annual - expense_annual
|
||||
profit_q2 = gross_q2 - expense_q2
|
||||
profit_month = gross_month - expense_month_val
|
||||
profit_prev_q = gross_prev_q - expense_prev_q
|
||||
profit_prev_month = gross_prev_month - expense_prev_month
|
||||
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("已签约")
|
||||
@@ -468,6 +498,21 @@ def bootstrap():
|
||||
"expense_month": expense_month_val,
|
||||
"expense_prev_q": expense_prev_q,
|
||||
"expense_prev_month": expense_prev_month,
|
||||
"paid_annual": paid_annual,
|
||||
"paid_q2": paid_q2,
|
||||
"paid_month": paid_month,
|
||||
"paid_prev_q": paid_prev_q,
|
||||
"paid_prev_month": paid_prev_month,
|
||||
"cashflow_annual": cashflow_annual,
|
||||
"cashflow_q2": cashflow_q2,
|
||||
"cashflow_month": cashflow_month,
|
||||
"cashflow_prev_q": cashflow_prev_q,
|
||||
"cashflow_prev_month": cashflow_prev_month,
|
||||
"profit_annual": profit_annual,
|
||||
"profit_q2": profit_q2,
|
||||
"profit_month": profit_month,
|
||||
"profit_prev_q": profit_prev_q,
|
||||
"profit_prev_month": profit_prev_month,
|
||||
"signed_not_executed": signed_not_executed,
|
||||
},
|
||||
"recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant),
|
||||
|
||||
@@ -186,12 +186,12 @@ function renderFinance() {
|
||||
<p class="text-lg font-bold text-purple-700" id="budgetTotalPaid">¥0</p>
|
||||
</div>
|
||||
<div class="bg-orange-50 rounded-lg p-3 text-center border border-orange-100" id="budgetTotalExpenseCard">
|
||||
<p class="text-xs text-orange-600 font-medium">总费用</p>
|
||||
<p class="text-xs text-orange-600 font-medium">总项目费用</p>
|
||||
<p class="text-lg font-bold text-orange-700" id="budgetTotalExpense">¥0</p>
|
||||
</div>
|
||||
</div>
|
||||
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="budgetTable">
|
||||
<thead><tr class="bg-slate-50 border-b border-slate-200"><th class="p-2.5 text-left font-medium text-slate-500" style="min-width:140px">月份</th><th class="p-2.5 text-right font-medium text-slate-500">确收</th><th class="p-2.5 text-right font-medium text-slate-500">毛利</th><th class="p-2.5 text-right font-medium text-slate-500">回款</th><th class="p-2.5 text-right font-medium text-slate-500">应付</th><th class="p-2.5 text-right font-medium text-slate-500">已付</th><th class="p-2.5 text-right font-medium text-slate-500">费用</th><th class="p-2.5 w-8"></th></tr></thead>
|
||||
<thead><tr class="bg-slate-50 border-b border-slate-200"><th class="p-2.5 text-left font-medium text-slate-500" style="min-width:140px">月份</th><th class="p-2.5 text-right font-medium text-slate-500">确收</th><th class="p-2.5 text-right font-medium text-slate-500">毛利</th><th class="p-2.5 text-right font-medium text-slate-500">回款</th><th class="p-2.5 text-right font-medium text-slate-500">应付</th><th class="p-2.5 text-right font-medium text-slate-500">已付</th><th class="p-2.5 text-right font-medium text-slate-500">项目费用</th><th class="p-2.5 w-8"></th></tr></thead>
|
||||
<tbody id="budgetTbody"></tbody>
|
||||
</table>
|
||||
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="addBudgetRow()"><i data-lucide="plus"></i>添加月份</button>
|
||||
@@ -235,14 +235,14 @@ function renderFinance() {
|
||||
{ label: '执行率', value: ctx => ctx.sumRev && ctx.signTotal ? Math.round(ctx.sumRev / ctx.signTotal * 100) + '%' : '—', color: 'text-slate-500' },
|
||||
{ label: '毛利', value: ctx => money(ctx.sumGross), color: 'text-green-700' },
|
||||
{ label: '毛利率', value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||
{ label: '费用', value: ctx => money(ctx.sumExpense), color: 'text-orange-700' },
|
||||
{ label: '项目费用', value: ctx => money(ctx.sumExpense), color: 'text-orange-700' },
|
||||
{ label: '已回款', value: ctx => moneyWan(ctx.sumPay), color: 'text-amber-700' },
|
||||
{ label: '回款率', value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||
{ label: '应付', value: ctx => moneyWan(ctx.sumCost), color: 'text-rose-700' },
|
||||
{ label: '已付', value: ctx => moneyWan(ctx.sumPaid), color: 'text-purple-700' },
|
||||
{ label: '付款率', value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
||||
{ label: '现金流', value: ctx => { const v = ctx.sumPay - ctx.sumPaid; return { val: money(v), cls: v >= 0 ? 'text-green-600' : 'text-red-600' }; }, color: null },
|
||||
{ label: '利润', value: ctx => { const v = ctx.sumGross - ctx.sumExpense; return { val: moneyWan(v), cls: v >= 0 ? 'text-green-600' : 'text-red-600' }; }, color: null },
|
||||
{ label: '项目利润', value: ctx => { const v = ctx.sumGross - ctx.sumExpense; return { val: moneyWan(v), cls: v >= 0 ? 'text-green-600' : 'text-red-600' }; }, color: null },
|
||||
];
|
||||
|
||||
const renderView = (rows, sumRev, sumPay, sumCost, sumPaid, sumGross, sumExpense, signTotal, signCnt, emptyText) => {
|
||||
@@ -264,9 +264,9 @@ function renderFinance() {
|
||||
'<th class="p-2 text-center font-semibold align-middle text-rose-600">应付</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle text-purple-600">已付</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle">付款率</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle text-orange-600">费用</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle text-orange-600">项目费用</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle text-slate-700">现金流</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle">利润</th>' +
|
||||
'<th class="p-2 text-center font-semibold align-middle">项目利润</th>' +
|
||||
'</tr></thead>';
|
||||
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="15" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
||||
|
||||
|
||||
@@ -39,12 +39,26 @@ function renderHome() {
|
||||
["上季度累计", moneyInt(m.cost_prev_q || 0)],
|
||||
["上月累计", moneyInt(m.cost_prev_month || 0)],
|
||||
];
|
||||
const rows6 = [
|
||||
["年度累计", moneyInt(m.expense_annual || 0)],
|
||||
["季度累计", moneyInt(m.expense_q2 || 0)],
|
||||
["本月新增", moneyInt(m.expense_month || 0)],
|
||||
["上季度累计", moneyInt(m.expense_prev_q || 0)],
|
||||
["上月累计", moneyInt(m.expense_prev_month || 0)],
|
||||
const rows7 = [
|
||||
["年度累计", moneyInt(m.paid_annual || 0)],
|
||||
["季度累计", moneyInt(m.paid_q2 || 0)],
|
||||
["本月新增", moneyInt(m.paid_month || 0)],
|
||||
["上季度累计", moneyInt(m.paid_prev_q || 0)],
|
||||
["上月累计", moneyInt(m.paid_prev_month || 0)],
|
||||
];
|
||||
const rows8 = [
|
||||
["年度累计", moneyInt(m.cashflow_annual || 0)],
|
||||
["季度累计", moneyInt(m.cashflow_q2 || 0)],
|
||||
["本月新增", moneyInt(m.cashflow_month || 0)],
|
||||
["上季度累计", moneyInt(m.cashflow_prev_q || 0)],
|
||||
["上月累计", moneyInt(m.cashflow_prev_month || 0)],
|
||||
];
|
||||
const rows9 = [
|
||||
["年度累计", moneyInt(m.profit_annual || 0)],
|
||||
["季度累计", moneyInt(m.profit_q2 || 0)],
|
||||
["本月新增", moneyInt(m.profit_month || 0)],
|
||||
["上季度累计", moneyInt(m.profit_prev_q || 0)],
|
||||
["上月累计", moneyInt(m.profit_prev_month || 0)],
|
||||
];
|
||||
const qoq = (cur, prev) => {
|
||||
if (!prev) return '<span class="text-slate-300">—</span>';
|
||||
@@ -53,49 +67,73 @@ function renderHome() {
|
||||
const sign = pct >= 0 ? '+' : '';
|
||||
return '<span class="' + cls + '">' + sign + pct + '%</span>';
|
||||
};
|
||||
const COLORS = ['text-slate-700','text-blue-600','text-green-600','text-amber-600','text-rose-600','text-orange-600'];
|
||||
const LABELS = ['合同金额','确收金额','确收毛利','回款金额','应付金额','费用'];
|
||||
const ALL_ROWS = [rows1, rows2, rows3, rows4, rows5, rows6];
|
||||
// 季度环比:Q 值 vs prev_Q 值;月度环比:month 值 vs prev_month 值
|
||||
const Q_FIELDS = [m.signed_q2||0, m.revenue_q2, m.gross_q2, m.payment_q2||0, m.cost_q2||0, m.expense_q2||0];
|
||||
const Q_PREV = [m.signed_prev_q||0, m.revenue_prev_q||0, m.gross_prev_q||0, m.payment_prev_q||0, m.cost_prev_q||0, m.expense_prev_q||0];
|
||||
const M_FIELDS = [m.signed_month||0, m.monthly_revenue, m.monthly_net_profit, m.payment_month||0, m.cost_month||0, m.expense_month||0];
|
||||
const M_PREV = [m.signed_prev_month||0, m.revenue_prev_month||0, m.gross_prev_month||0, m.payment_prev_month||0, m.cost_prev_month||0, m.expense_prev_month||0];
|
||||
var thead = '<tr class="border-b border-slate-200"><th class="py-2 text-left text-slate-500"></th>';
|
||||
for (var ci = 0; ci < 6; ci++) {
|
||||
thead += '<th class="py-2 text-right font-semibold ' + COLORS[ci] + '">' + LABELS[ci] + '</th><th class="py-2 text-right font-semibold text-slate-400" style="font-size:11px">环比</th>';
|
||||
}
|
||||
thead += '</tr>';
|
||||
const COLORS = ['text-slate-700','text-blue-600','text-green-600','text-amber-600','text-rose-600','text-purple-600','text-cyan-600','text-indigo-600'];
|
||||
const LABELS = ['合同金额','确收金额','确收毛利','回款金额','应付金额','已付','现金流','项目利润'];
|
||||
const Q_FIELDS = [m.signed_q2||0, m.revenue_q2, m.gross_q2, m.payment_q2||0, m.cost_q2||0, m.paid_q2||0, m.cashflow_q2||0, m.profit_q2||0];
|
||||
const Q_PREV = [m.signed_prev_q||0, m.revenue_prev_q||0, m.gross_prev_q||0, m.payment_prev_q||0, m.cost_prev_q||0, m.paid_prev_q||0, m.cashflow_prev_q||0, m.profit_prev_q||0];
|
||||
const M_FIELDS = [m.signed_month||0, m.monthly_revenue, m.monthly_net_profit, m.payment_month||0, m.cost_month||0, m.paid_month||0, m.cashflow_month||0, m.profit_month||0];
|
||||
const M_PREV = [m.signed_prev_month||0, m.revenue_prev_month||0, m.gross_prev_month||0, m.payment_prev_month||0, m.cost_prev_month||0, m.paid_prev_month||0, m.cashflow_prev_month||0, m.profit_prev_month||0];
|
||||
const ROWS = [rows1, rows2, rows3, rows4, rows5, rows7, rows8, rows9];
|
||||
var thead = '<tr class="border-b border-slate-200"><th class="py-2 text-left text-slate-500">指标</th><th class="py-2 text-right font-semibold text-slate-700">年度累计</th><th class="py-2 text-right font-semibold text-slate-700">季度累计</th><th class="py-2 text-right font-semibold text-slate-400">季环比</th><th class="py-2 text-right font-semibold text-slate-700">本月新增</th><th class="py-2 text-right font-semibold text-slate-400">月环比</th><th class="py-2 text-right font-semibold text-slate-700">上季度累计</th><th class="py-2 text-right font-semibold text-slate-700">上月累计</th></tr>';
|
||||
var tbody = '';
|
||||
for (var ri = 0; ri < 5; ri++) {
|
||||
var rowLabel = rows1[ri][0];
|
||||
var rowHtml = '<tr class="border-b border-slate-100 last:border-0"><td class="py-2 text-slate-500">' + rowLabel + '</td>';
|
||||
for (var ci = 0; ci < 6; ci++) {
|
||||
rowHtml += '<td class="py-2 text-right font-semibold text-slate-800">' + ALL_ROWS[ci][ri][1] + '</td>';
|
||||
var momHtml = '';
|
||||
if (ri === 1) momHtml = qoq(Q_FIELDS[ci], Q_PREV[ci]); // 季度累计行:季度环比
|
||||
else if (ri === 2) momHtml = qoq(M_FIELDS[ci], M_PREV[ci]); // 本月新增行:月度环比
|
||||
else momHtml = '<span class="text-slate-300">—</span>';
|
||||
rowHtml += '<td class="py-2 text-right" style="font-size:12px">' + momHtml + '</td>';
|
||||
}
|
||||
rowHtml += '</tr>';
|
||||
tbody += rowHtml;
|
||||
for (var ri = 0; ri < 8; ri++) {
|
||||
var vals = ROWS[ri];
|
||||
tbody += '<tr class="border-b border-slate-100 last:border-0"><td class="py-2 text-left font-semibold text-slate-700">' + LABELS[ri] + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + vals[0][1] + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + vals[1][1] + '</td>' +
|
||||
'<td class="py-2 text-right">' + qoq(Q_FIELDS[ri], Q_PREV[ri]) + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + vals[2][1] + '</td>' +
|
||||
'<td class="py-2 text-right">' + qoq(M_FIELDS[ri], M_PREV[ri]) + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + vals[3][1] + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + vals[4][1] + '</td></tr>';
|
||||
}
|
||||
document.querySelector("#home").innerHTML = `
|
||||
<div class="grid gap-5">
|
||||
${state.tenant === "总工作台" ? "" : `<div class="grid grid-cols-4 gap-3">
|
||||
${[
|
||||
["经营管理", m.total_projects, "finance"],
|
||||
["项目管理", m.total_projects, "finance"],
|
||||
["重点工作与台账", m.total_proposals, "projects"],
|
||||
["业务方案", m.total_products, "proposals"],
|
||||
["产品迭代", m.upcoming_products, "products"],
|
||||
].map(([label, value, tab]) => `<button class="metric-card" onclick="switchTab('${tab}')"><span class="flex items-center gap-2 text-xs text-slate-500"><i data-lucide="gauge"></i>${label}</span><strong class="mt-2 block text-2xl">${value}</strong></button>`).join("")}
|
||||
</div>`}
|
||||
${card(`<h3 class="text-sm font-bold text-slate-700 mb-3">财务概览</h3><div class="overflow-x-auto"><table class="w-full text-sm"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`, "p-4")}
|
||||
<div class="grid grid-cols-3 gap-5">
|
||||
${card(`<h3 class="text-sm font-bold text-slate-700 mb-3">部门经营情况</h3><div class="overflow-x-auto"><table class="w-full text-sm"><thead><tr class="border-b border-slate-200"><th class="py-2 text-left text-slate-500">指标</th><th class="py-2 text-right font-semibold text-slate-700">年度累计</th><th class="py-2 text-right font-semibold text-slate-700">季度累计</th><th class="py-2 text-right font-semibold text-slate-400">季环比</th><th class="py-2 text-right font-semibold text-slate-700">本月新增</th><th class="py-2 text-right font-semibold text-slate-400">月环比</th><th class="py-2 text-right font-semibold text-slate-700">上季度累计</th><th class="py-2 text-right font-semibold text-slate-700">上月累计</th></tr></thead><tbody>
|
||||
${(() => {
|
||||
var d = [
|
||||
['部门利润', [m.profit_annual||0, m.profit_q2||0, m.profit_month||0, m.profit_prev_q||0, m.profit_prev_month||0],
|
||||
[m.profit_q2||0,m.profit_prev_q||0], [m.profit_month||0,m.profit_prev_month||0]],
|
||||
['部门费用', [m.expense_annual||0, m.expense_q2||0, (m.expense_month||0), m.expense_prev_q||0, m.expense_prev_month||0],
|
||||
[m.expense_q2||0,m.expense_prev_q||0], [(m.expense_month||0),m.expense_prev_month||0]],
|
||||
['部门净利', [
|
||||
(m.profit_annual||0)-(m.expense_annual||0), (m.profit_q2||0)-(m.expense_q2||0), (m.profit_month||0)-(m.expense_month||0),
|
||||
(m.profit_prev_q||0)-(m.expense_prev_q||0), (m.profit_prev_month||0)-(m.expense_prev_month||0)
|
||||
], [
|
||||
(m.profit_q2||0)-(m.expense_q2||0), (m.profit_prev_q||0)-(m.expense_prev_q||0)
|
||||
], [
|
||||
(m.profit_month||0)-(m.expense_month||0), (m.profit_prev_month||0)-(m.expense_prev_month||0)
|
||||
]]
|
||||
];
|
||||
var h = '';
|
||||
for (var di = 0; di < 3; di++) {
|
||||
var r = d[di];
|
||||
h += '<tr class="border-b border-slate-100 last:border-0"><td class="py-2 text-left font-semibold text-slate-700">' + r[0] + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + moneyInt(r[1][0]) + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + moneyInt(r[1][1]) + '</td>' +
|
||||
'<td class="py-2 text-right">' + qoq(r[2][0], r[2][1]) + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + moneyInt(r[1][2]) + '</td>' +
|
||||
'<td class="py-2 text-right">' + qoq(r[3][0], r[3][1]) + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + moneyInt(r[1][3]) + '</td>' +
|
||||
'<td class="py-2 text-right font-semibold text-slate-800">' + moneyInt(r[1][4]) + '</td></tr>';
|
||||
}
|
||||
return h;
|
||||
})()}
|
||||
</tbody></table></div>`, "p-4")}
|
||||
${card(`<h3 class="text-sm font-bold text-slate-700 mb-3">业务(项目)财务概览</h3><div class="overflow-x-auto"><table class="w-full text-sm"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`, "p-4")}
|
||||
<div class="grid grid-cols-4 gap-5">
|
||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度签约趋势</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartSign"></canvas></div>`, "p-4")}
|
||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度确收与毛利</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartRev"></canvas></div>`, "p-4")}
|
||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度回款与费用</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartCash"></canvas></div>`, "p-4")}
|
||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度回款与已付</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartCash"></canvas></div>`, "p-4")}
|
||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度项目利润</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartProfit"></canvas></div>`, "p-4")}
|
||||
</div>
|
||||
${card(`<h2 class="text-lg font-bold">近期动态</h2><div class="mt-4 grid gap-2">${summary.recent.map((r) => `<div class="flex items-start justify-between rounded-md bg-slate-50 px-3 py-2 text-sm group"><span class="break-words">${r.content}</span><div class="flex items-center gap-2 flex-shrink-0 ml-2"><span class="text-xs text-slate-400">${r.followed_at}</span><button class="btn btn-ghost btn-sm text-red-400 opacity-0 group-hover:opacity-100 p-0 w-5 h-5" onclick="event.preventDefault();deleteActivity(${r.id})" title="删除动态"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></div></div>`).join("")}</div>`, "p-5")}
|
||||
</div>
|
||||
@@ -149,15 +187,28 @@ function renderCharts(data) {
|
||||
});
|
||||
}
|
||||
|
||||
// 图3:月度回款与费用
|
||||
// 图3:月度回款与已付
|
||||
const c3 = document.querySelector("#chartCash");
|
||||
if (c3 && window.Chart) {
|
||||
if (state.chart3) state.chart3.destroy();
|
||||
state.chart3 = new Chart(c3, {
|
||||
type: "bar",
|
||||
type: "line",
|
||||
data: { labels, datasets: [
|
||||
{ label: "回款", data: data.map((x) => x.payment || 0), backgroundColor: "#d97706", borderRadius: 4 },
|
||||
{ label: "费用", data: data.map((x) => x.cost || 0), backgroundColor: "#ef4444", borderRadius: 4 },
|
||||
{ label: "回款", data: data.map((x) => x.payment || 0), borderColor: "#d97706", backgroundColor: "rgba(217,119,6,0.06)", fill: true, tension: 0.3 },
|
||||
{ label: "已付", data: data.map((x) => x.cost || 0), borderColor: "#7c3aed", backgroundColor: "rgba(124,58,237,0.06)", fill: true, tension: 0.3 },
|
||||
]},
|
||||
options: baseOpts,
|
||||
});
|
||||
}
|
||||
|
||||
// 图4:月度项目利润
|
||||
const c4 = document.querySelector("#chartProfit");
|
||||
if (c4 && window.Chart) {
|
||||
if (state.chart4) state.chart4.destroy();
|
||||
state.chart4 = new Chart(c4, {
|
||||
type: "line",
|
||||
data: { labels, datasets: [
|
||||
{ label: "利润", data: data.map((x) => (x.gross || 0)), borderColor: "#6366f1", backgroundColor: "rgba(99,102,241,0.06)", fill: true, tension: 0.3 },
|
||||
]},
|
||||
options: baseOpts,
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ const state = {
|
||||
chart: null,
|
||||
chart2: null,
|
||||
chart3: null,
|
||||
chart4: null,
|
||||
productPlatform: "all",
|
||||
uploadTasks: [],
|
||||
expenseFilter: "全部",
|
||||
|
||||
Reference in New Issue
Block a user