diff --git a/backend/migrations/tables.py b/backend/migrations/tables.py index 2bc68f5..df6e67e 100644 --- a/backend/migrations/tables.py +++ b/backend/migrations/tables.py @@ -146,6 +146,20 @@ def migrate_create_tables(): budget_data TEXT, created_at VARCHAR(30) NOT NULL DEFAULT '', updated_at VARCHAR(30) NOT NULL DEFAULT '' +)""", + """CREATE TABLE IF NOT EXISTS purchase_records ( + id INT AUTO_INCREMENT PRIMARY KEY, + tenant VARCHAR(100) NOT NULL DEFAULT '科普·无界', + project_name VARCHAR(200) NOT NULL DEFAULT '', + purchase_item VARCHAR(300) NOT NULL DEFAULT '', + supplier VARCHAR(200) NOT NULL DEFAULT '', + amount DOUBLE NOT NULL DEFAULT 0, + purchase_date VARCHAR(30) NOT NULL DEFAULT '', + status VARCHAR(50) NOT NULL DEFAULT '待审批', + category VARCHAR(100) NOT NULL DEFAULT '', + notes VARCHAR(1000) NOT NULL DEFAULT '', + created_at VARCHAR(30) NOT NULL DEFAULT '', + updated_at VARCHAR(30) NOT NULL DEFAULT '' )""", ] diff --git a/backend/routes.py b/backend/routes.py index 26ce6bd..4dc6f3f 100644 --- a/backend/routes.py +++ b/backend/routes.py @@ -24,6 +24,7 @@ TABLES = { "finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]), "tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "priority", "tenant"]), "projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "status", "sales_person", "owner", "total_rev", "total_gross", "total_payment", "total_cost", "total_paid", "budget_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]), + "purchase": ("purchase_records", ["project_name", "purchase_item", "supplier", "amount", "purchase_date", "status", "category", "notes", "tenant"]), } # ---------- 鉴权装饰器 ---------- @@ -321,7 +322,7 @@ def bootstrap(): "recent": sorted(all_recent, key=lambda x: x.get("id", 0), reverse=True)[:8], "risks": [], } - return jsonify({"summary": summary, "sales": [], "proposals": [], "operations": [], "products": [], "finance": [], "projectFinances": [], "financeMonthly": merged_monthly, "tasks": [], "tenant": tenant, "tenants": allowed}) + return jsonify({"summary": summary, "sales": [], "proposals": [], "operations": [], "products": [], "finance": [], "projectFinances": [], "financeMonthly": merged_monthly, "tasks": [], "purchase": [], "tenant": tenant, "tenants": allowed}) def q(sql, *args): return rows(conn, sql, args) @@ -332,6 +333,7 @@ def bootstrap(): finance = q("SELECT * FROM finance_records WHERE tenant=? ORDER BY month DESC, id DESC", tenant) tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant) pfs = q("SELECT * FROM project_finances WHERE tenant=? ORDER BY id DESC", tenant) + purchase = q("SELECT * FROM purchase_records WHERE tenant=? ORDER BY id DESC", tenant) signed_pfs = [x for x in pfs if x["status"] == "已签约"] def parse_budget(pf): @@ -434,7 +436,7 @@ def bootstrap(): "recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant), "risks": [{"title": "执行提醒", "content": x["next_action"]} for x in operations if x["next_action"]][:5], } - return jsonify({"summary": summary, "sales": sales, "proposals": proposals, "operations": operations, "products": products, "finance": finance, "projectFinances": pfs, "financeMonthly": monthly_finance(conn, tenant), "tasks": tasks, "tenant": tenant, "tenants": allowed}) + return jsonify({"summary": summary, "sales": sales, "proposals": proposals, "operations": operations, "products": products, "finance": finance, "projectFinances": pfs, "financeMonthly": monthly_finance(conn, tenant), "tasks": tasks, "purchase": purchase, "tenant": tenant, "tenants": allowed}) finally: conn.close() diff --git a/static/modules/finance.js b/static/modules/finance.js index 4881e3b..3fe5b28 100644 --- a/static/modules/finance.js +++ b/static/modules/finance.js @@ -99,20 +99,15 @@ function renderFinance() { } })(); const sm = pf.sign_month || ""; - const signMonthCell = `${sm || '—'}`; - return `${esc(pf.customer_name)}${signMonthCell}${money(pf.sign_amount)}${mCols}${totalCol}`; + const signMonthCell = `${sm || '—'}`; + return `${esc(pf.customer_name)}${signMonthCell}${money(pf.sign_amount)}${mCols}${totalCol}`; }; const finHeaderBase = `|筛选:状态:`; const finAddBtn = ``; document.querySelector("#finance").innerHTML = `
-
- ${[["已签项目","" + signed.length,"file-check-2"],["签约金额",moneyWan(sumSign),"coins"],["待签项目","" + pending.length,"file-question"],["待签金额",moneyWan(sumPending),"hourglass"]].map(([l,v,icon]) => `
${l}${v}
`).join("")} -
-
- ${[["本月确收",moneyInt(thisMonthRev),"trending-up"],["本月毛利",moneyInt(thisMonthGross),"percent"],["本月回款",moneyInt(monthPayment),"wallet"],["本月应付",moneyInt(monthCost),"receipt"],["本月现金流",moneyInt(monthCashflow),"repeat"]].map(([l,v,icon]) => `
${l}${v}
`).join("")} -
+
${finHeaderBase}
${finAddBtn}
@@ -114,6 +119,7 @@ +