Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
347c8aa818 | ||
|
|
e21d41b218 | ||
|
|
a57cba8043 | ||
|
|
fdb16d053a | ||
|
|
61ba9c4c5d | ||
|
|
eba4945fba | ||
|
|
2445dea4dd |
@@ -65,7 +65,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
|||||||
_year = date.today().year
|
_year = date.today().year
|
||||||
months = [f"{_year}-{m:02d}" for m in range(1, 13)]
|
months = [f"{_year}-{m:02d}" for m in range(1, 13)]
|
||||||
pfs = rows(conn,
|
pfs = rows(conn,
|
||||||
"SELECT sign_amount, sign_month, status, budget_data, expense_data FROM project_finances WHERE tenant=? AND status='已签约'",
|
"SELECT sign_amount, sign_month, budget_data, expense_data FROM project_finances WHERE tenant=?",
|
||||||
[tenant])
|
[tenant])
|
||||||
|
|
||||||
parsed_budgets = []
|
parsed_budgets = []
|
||||||
@@ -104,7 +104,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
|||||||
key = month.replace("-", "_")
|
key = month.replace("-", "_")
|
||||||
revenue = gross = payment = cost = paid = sign = 0
|
revenue = gross = payment = cost = paid = sign = 0
|
||||||
for pf, budget_map in parsed_budgets:
|
for pf, budget_map in parsed_budgets:
|
||||||
if pf["status"] == "已签约" and (pf.get("sign_month") or "") == month:
|
if (pf.get("sign_month") or "") == month:
|
||||||
sign += float(pf["sign_amount"] or 0)
|
sign += float(pf["sign_amount"] or 0)
|
||||||
b = budget_map.get(key)
|
b = budget_map.get(key)
|
||||||
if b:
|
if b:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ def run_migrations():
|
|||||||
"""
|
"""
|
||||||
from migrations.tables import migrate_create_tables
|
from migrations.tables import migrate_create_tables
|
||||||
from migrations.columns import migrate_add_columns
|
from migrations.columns import migrate_add_columns
|
||||||
from migrations.data_fixes import migrate_fix_task_status, migrate_rename_tenant, migrate_drop_product_fields, migrate_fix_service_fee_standard, migrate_fix_expense_status, migrate_move_pending_to_plan
|
from migrations.data_fixes import migrate_fix_task_status, migrate_rename_tenant, migrate_drop_product_fields, migrate_fix_service_fee_standard, migrate_fix_expense_status
|
||||||
from migrations.data_split import migrate_data_split
|
from migrations.data_split import migrate_data_split
|
||||||
from migrations.seed import migrate_seed_users, migrate_seed_demo_data
|
from migrations.seed import migrate_seed_users, migrate_seed_demo_data
|
||||||
|
|
||||||
@@ -28,7 +28,6 @@ def run_migrations():
|
|||||||
migrate_drop_product_fields()
|
migrate_drop_product_fields()
|
||||||
migrate_fix_service_fee_standard()
|
migrate_fix_service_fee_standard()
|
||||||
migrate_fix_expense_status()
|
migrate_fix_expense_status()
|
||||||
migrate_move_pending_to_plan()
|
|
||||||
migrate_data_split()
|
migrate_data_split()
|
||||||
migrate_seed_users()
|
migrate_seed_users()
|
||||||
migrate_seed_demo_data()
|
migrate_seed_demo_data()
|
||||||
|
|||||||
@@ -114,5 +114,20 @@ def migrate_add_columns():
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print("[migrate] 加列迁移完成")
|
print("[migrate] 加列迁移完成")
|
||||||
|
|
||||||
|
# 删除 plan_finances.status 列(计划模块不再需要状态字段)
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute("SHOW COLUMNS FROM plan_finances LIKE 'status'")
|
||||||
|
if cur.fetchone():
|
||||||
|
cur.execute("ALTER TABLE plan_finances DROP COLUMN status")
|
||||||
|
conn.commit()
|
||||||
|
print("[migrate] plan_finances.status 列已删除")
|
||||||
|
# 删除 project_finances.status 列(实际模块不再需要状态字段)
|
||||||
|
cur.execute("SHOW COLUMNS FROM project_finances LIKE 'status'")
|
||||||
|
if cur.fetchone():
|
||||||
|
cur.execute("ALTER TABLE project_finances DROP COLUMN status")
|
||||||
|
conn.commit()
|
||||||
|
print("[migrate] project_finances.status 列已删除")
|
||||||
|
cur.close()
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
@@ -114,29 +114,3 @@ def migrate_fix_expense_status():
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def migrate_move_pending_to_plan():
|
|
||||||
"""迁移业务待签约项目到计划模块(幂等)"""
|
|
||||||
from db import db
|
|
||||||
|
|
||||||
conn = db()
|
|
||||||
try:
|
|
||||||
cur = conn.cursor()
|
|
||||||
# 仅迁移 id 不存在于计划表的待签约项目
|
|
||||||
cur.execute(
|
|
||||||
"INSERT INTO plan_finances "
|
|
||||||
"SELECT * FROM project_finances WHERE status='待签约' "
|
|
||||||
"AND id NOT IN (SELECT id FROM plan_finances)"
|
|
||||||
)
|
|
||||||
moved = cur.rowcount
|
|
||||||
if moved:
|
|
||||||
# 删除已迁移的原记录
|
|
||||||
cur.execute(
|
|
||||||
"DELETE FROM project_finances WHERE status='待签约' "
|
|
||||||
"AND id IN (SELECT id FROM plan_finances)"
|
|
||||||
)
|
|
||||||
deleted = cur.rowcount
|
|
||||||
conn.commit()
|
|
||||||
print(f"[migrate] 待签约项目迁移到计划: {moved} 条 (已删除 {deleted} 条)")
|
|
||||||
cur.close()
|
|
||||||
finally:
|
|
||||||
conn.close()
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def make_budget_data(sign_amount, signed_month, status):
|
|||||||
"""生成12个月的预算数据"""
|
"""生成12个月的预算数据"""
|
||||||
months = []
|
months = []
|
||||||
start_m = int(signed_month.split("-")[1]) if signed_month else 1
|
start_m = int(signed_month.split("-")[1]) if signed_month else 1
|
||||||
rev_total = sign_amount if status == "已签约" else int(sign_amount * random.uniform(0.3, 0.7))
|
rev_total = sign_amount
|
||||||
gross_rate = random.uniform(0.25, 0.55)
|
gross_rate = random.uniform(0.25, 0.55)
|
||||||
payment_rate = random.uniform(0.7, 0.95)
|
payment_rate = random.uniform(0.7, 0.95)
|
||||||
|
|
||||||
@@ -135,17 +135,17 @@ def seed_db():
|
|||||||
cust_idx += i % 3
|
cust_idx += i % 3
|
||||||
|
|
||||||
# 70% 已签约, 30% 待签约
|
# 70% 已签约, 30% 待签约
|
||||||
status = "已签约" if random.random() < 0.7 else "待签约"
|
status = "已签约"
|
||||||
sign_month = f"2026-{random.randint(1, 6):02d}" if status == "已签约" else ""
|
sign_month = f"2026-{random.randint(1, 6):02d}"
|
||||||
project_code = f"{tenant[:2]}-2026-{i+1:03d}"
|
project_code = f"{tenant[:2]}-2026-{i+1:03d}"
|
||||||
business_type = random.choice(["学术推广", "医生教育", "患者管理", "科研合作", "科普内容"])
|
business_type = random.choice(["学术推广", "医生教育", "患者管理", "科研合作", "科普内容"])
|
||||||
|
|
||||||
# 如果签约,总额 = 签约额;否则为0
|
# 如果签约,总额 = 签约额;否则为0
|
||||||
total_rev = int(sign_amount * random.uniform(0.8, 1.0)) if status == "已签约" else 0
|
total_rev = int(sign_amount * random.uniform(0.8, 1.0))
|
||||||
total_gross = int(total_rev * random.uniform(0.25, 0.5)) if status == "已签约" else 0
|
total_gross = int(total_rev * random.uniform(0.25, 0.5))
|
||||||
total_payment = int(total_rev * random.uniform(0.7, 0.9)) if status == "已签约" else 0
|
total_payment = int(total_rev * random.uniform(0.7, 0.9))
|
||||||
total_cost = int(total_rev * random.uniform(0.3, 0.5)) if status == "已签约" else 0
|
total_cost = int(total_rev * random.uniform(0.3, 0.5))
|
||||||
total_paid = int(total_cost * random.uniform(0.7, 0.95)) if status == "已签约" else 0
|
total_paid = int(total_cost * random.uniform(0.7, 0.95))
|
||||||
|
|
||||||
budget_data = make_budget_data(sign_amount, sign_month, status)
|
budget_data = make_budget_data(sign_amount, sign_month, status)
|
||||||
expense_data = make_expense_data() if status == "已签约" else "[]"
|
expense_data = make_expense_data() if status == "已签约" else "[]"
|
||||||
@@ -157,16 +157,16 @@ def seed_db():
|
|||||||
|
|
||||||
cur = _exec(conn, """
|
cur = _exec(conn, """
|
||||||
INSERT INTO project_finances
|
INSERT INTO project_finances
|
||||||
(tenant, project_id, business_type, customer_name, sign_amount, sign_month, status,
|
(tenant, project_id, business_type, customer_name, sign_amount, sign_month,
|
||||||
sales_person, total_rev, total_gross, total_payment, total_cost, total_paid,
|
sales_person, total_rev, total_gross, total_payment, total_cost, total_paid,
|
||||||
budget_data, expense_data, task_data,
|
budget_data, expense_data, task_data,
|
||||||
project_code, start_date, end_date, task_type, task_count,
|
project_code, start_date, end_date, task_type, task_count,
|
||||||
service_fee_standard, project_manager, contact_name, contact_phone, other_info,
|
service_fee_standard, project_manager, contact_name, contact_phone, other_info,
|
||||||
created_at, updated_at)
|
created_at, updated_at)
|
||||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||||
""", (
|
""", (
|
||||||
tenant, f"PF-{tenant[:2]}-{i+1:04d}", business_type, cust_name,
|
tenant, f"PF-{tenant[:2]}-{i+1:04d}", business_type, cust_name,
|
||||||
sign_amount, sign_month, status,
|
sign_amount, sign_month,
|
||||||
f"销售{random.choice(['A','B','C','D'])}", total_rev, total_gross,
|
f"销售{random.choice(['A','B','C','D'])}", total_rev, total_gross,
|
||||||
total_payment, total_cost, total_paid,
|
total_payment, total_cost, total_paid,
|
||||||
budget_data, expense_data, task_data,
|
budget_data, expense_data, task_data,
|
||||||
@@ -178,7 +178,7 @@ def seed_db():
|
|||||||
today, today,
|
today, today,
|
||||||
))
|
))
|
||||||
# Store for later use
|
# Store for later use
|
||||||
pf_ids.setdefault(tenant, []).append((cur.lastrowid, proj_name, cust_name, status))
|
pf_ids.setdefault(tenant, []).append((cur.lastrowid, proj_name, cust_name))
|
||||||
|
|
||||||
# operation_projects: 每个工作台 3-5 个
|
# operation_projects: 每个工作台 3-5 个
|
||||||
op_count = random.randint(3, 5)
|
op_count = random.randint(3, 5)
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ TABLES = {
|
|||||||
"products": ("product_versions", ["product_name", "version", "version_goal", "priority", "start_date", "plan_date", "dev_done_date", "test_date", "launch_date", "status", "notes", "tenant"]),
|
"products": ("product_versions", ["product_name", "version", "version_goal", "priority", "start_date", "plan_date", "dev_done_date", "test_date", "launch_date", "status", "notes", "tenant"]),
|
||||||
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
"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"]),
|
"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", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
"projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "sales_person", "owner", "total_rev", "total_gross", "total_payment", "total_cost", "total_paid", "budget_data", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
||||||
"expense": ("expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
"expense": ("expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
||||||
"planFinances": ("plan_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", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
"planFinances": ("plan_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "sales_person", "owner", "total_rev", "total_gross", "total_payment", "total_cost", "total_paid", "budget_data", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
||||||
"planExpense": ("plan_expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
"planExpense": ("plan_expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ def bootstrap():
|
|||||||
t_products = attach_common(conn, "products", rows(conn, "SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", [t]))
|
t_products = attach_common(conn, "products", rows(conn, "SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", [t]))
|
||||||
t_expense = rows(conn, "SELECT * FROM expense_records WHERE tenant=?", [t])
|
t_expense = rows(conn, "SELECT * FROM expense_records WHERE tenant=?", [t])
|
||||||
t_proposals = attach_common(conn, "proposals", rows(conn, "SELECT * FROM business_proposals WHERE tenant=? ORDER BY id DESC", [t]))
|
t_proposals = attach_common(conn, "proposals", rows(conn, "SELECT * FROM business_proposals WHERE tenant=? ORDER BY id DESC", [t]))
|
||||||
t_signed_pfs = [x for x in t_pfs if x["status"] == "已签约"]
|
t_signed_pfs = t_pfs
|
||||||
def t_parse_budget(pf):
|
def t_parse_budget(pf):
|
||||||
try:
|
try:
|
||||||
budget = json.loads(pf.get("budget_data") or "[]")
|
budget = json.loads(pf.get("budget_data") or "[]")
|
||||||
@@ -326,12 +326,12 @@ def bootstrap():
|
|||||||
"total_proposals": len(t_ops),
|
"total_proposals": len(t_ops),
|
||||||
"total_products": len(t_proposals),
|
"total_products": len(t_proposals),
|
||||||
"upcoming_products": len(t_products),
|
"upcoming_products": len(t_products),
|
||||||
"signed_amount": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"),
|
"signed_amount": sum(x["sign_amount"] or 0 for x in t_pfs),
|
||||||
"signed_annual": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"),
|
"signed_annual": sum(x["sign_amount"] or 0 for x in t_pfs),
|
||||||
"signed_q2": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months),
|
"signed_q2": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] in _q_months),
|
||||||
"signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}"),
|
"signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}"),
|
||||||
"signed_prev_q": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months),
|
"signed_prev_q": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] in _prev_q_months),
|
||||||
"signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0,
|
"signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0,
|
||||||
"revenue_annual": t_sum_budget("rev", range(1, 13)),
|
"revenue_annual": t_sum_budget("rev", range(1, 13)),
|
||||||
"revenue_q2": t_sum_budget("rev", _q_range),
|
"revenue_q2": t_sum_budget("rev", _q_range),
|
||||||
"monthly_revenue": t_sum_budget("rev", [_now_month]),
|
"monthly_revenue": t_sum_budget("rev", [_now_month]),
|
||||||
@@ -442,7 +442,7 @@ def bootstrap():
|
|||||||
expense = q("SELECT * FROM expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
expense = q("SELECT * FROM expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
planPfs = q("SELECT * FROM plan_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
planPfs = q("SELECT * FROM plan_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
planExpense = q("SELECT * FROM plan_expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
planExpense = q("SELECT * FROM plan_expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
signed_pfs = [x for x in pfs if x["status"] == "已签约"]
|
signed_pfs = pfs
|
||||||
|
|
||||||
def parse_budget(pf):
|
def parse_budget(pf):
|
||||||
try:
|
try:
|
||||||
@@ -563,16 +563,14 @@ def bootstrap():
|
|||||||
profit_month = gross_month - proj_expense_month
|
profit_month = gross_month - proj_expense_month
|
||||||
profit_prev_q = gross_prev_q - proj_expense_prev_q
|
profit_prev_q = gross_prev_q - proj_expense_prev_q
|
||||||
profit_prev_month = gross_prev_month - proj_expense_prev_month
|
profit_prev_month = gross_prev_month - proj_expense_prev_month
|
||||||
def pf_status_sum(status):
|
signed_amount = sum(x["sign_amount"] or 0 for x in pfs)
|
||||||
return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status)
|
signed_annual = sum(x["sign_amount"] or 0 for x in pfs)
|
||||||
signed_amount = pf_status_sum("已签约")
|
|
||||||
signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约")
|
|
||||||
_q_months = [f"{_year}-{m:02d}" for m in _q_range]
|
_q_months = [f"{_year}-{m:02d}" for m in _q_range]
|
||||||
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months)
|
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] in _q_months)
|
||||||
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}")
|
signed_month = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}")
|
||||||
_prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range]
|
_prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range]
|
||||||
signed_prev_q = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months)
|
signed_prev_q = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] in _prev_q_months)
|
||||||
signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0
|
signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0
|
||||||
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
||||||
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
||||||
summary = {
|
summary = {
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ function renderFinance() {
|
|||||||
const months = displayMonths.map(d => d.key);
|
const months = displayMonths.map(d => d.key);
|
||||||
const monthLabels = displayMonths.map(d => d.label);
|
const monthLabels = displayMonths.map(d => d.label);
|
||||||
|
|
||||||
const signed = pfs.filter(x => x.status === "已签约");
|
const signed = pfs;
|
||||||
const pending = pfs.filter(x => x.status === "待签约");
|
const pending = pfs;
|
||||||
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
|
|
||||||
@@ -105,18 +105,15 @@ function renderFinance() {
|
|||||||
const defaultMonth2 = now2.getFullYear() + "-" + String(now2.getMonth()+1).padStart(2,"0");
|
const defaultMonth2 = now2.getFullYear() + "-" + String(now2.getMonth()+1).padStart(2,"0");
|
||||||
if (!state.finMonth) state.finMonth = defaultMonth2;
|
if (!state.finMonth) state.finMonth = defaultMonth2;
|
||||||
if (state.finQuarter === undefined) state.finQuarter = Math.floor(now2.getMonth() / 3);
|
if (state.finQuarter === undefined) state.finQuarter = Math.floor(now2.getMonth() / 3);
|
||||||
const monthSet2 = new Set([defaultMonth2]);
|
const qLabels = ['Q1','Q2','Q3','Q4'];
|
||||||
pfs.forEach(pf => { let bd = []; try { bd = JSON.parse(pf.budget_data || "[]"); } catch(e) {} bd.forEach(b => { if (b.month) monthSet2.add(b.month); }); });
|
const qMonths = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]];
|
||||||
const allMonths = [...monthSet2].sort().reverse();
|
const nowD = new Date();
|
||||||
const qLabels2 = ["Q1 (1-3月)","Q2 (4-6月)","Q3 (7-9月)","Q4 (10-12月)"];
|
const activeQ = state.finQuarter !== undefined ? state.finQuarter : Math.floor(nowD.getMonth() / 3);
|
||||||
const toolMonthSelect = allMonths.map(m => '<option value="'+m+'" '+(m===state.finMonth?'selected':'')+'>'+m+'</option>').join("");
|
const activeMonths = qMonths[activeQ];
|
||||||
const toolQuarterSelect = qLabels2.map((l,i) => '<option value="'+i+'" '+(i===state.finQuarter?'selected':'')+'>'+l+'</option>').join("");
|
const finHeaderBase = `<div class="flex items-center gap-2"><button onclick="setFinView('overview')" class="px-3 py-1 rounded text-sm font-medium ${state.finView==='overview'?'bg-blue-600 text-white':'bg-slate-100 text-slate-600 hover:bg-slate-200'}">总视图</button><span class="text-slate-300 mx-2">|</span><span class="text-sm text-slate-500">按季度:</span>${qLabels.map((q,i) => `<button onclick="setFinQuarter(${i})" class="px-3 py-1 rounded text-sm font-medium ${state.finView==='quarterly'&&activeQ===i?'bg-blue-600 text-white':'bg-slate-100 text-slate-600 hover:bg-slate-200'}">${q}</button>`).join('')}<span class="text-slate-300 mx-2">|</span><span class="text-sm text-slate-500">按月度:</span>${activeMonths.map(m => { const ms = `2026-${String(m).padStart(2,'0')}`; return `<button onclick="setFinMonth('${ms}')" class="px-3 py-1 rounded text-sm font-medium ${state.finView==='monthly'&&state.finMonth===ms?'bg-blue-600 text-white':'bg-slate-100 text-slate-600 hover:bg-slate-200'}">${m}月</button>`; }).join('')}</div>`;
|
||||||
const toolDateSelect = state.finView==='monthly'?'<span class="text-sm text-slate-500 ml-2">月份:</span><select onchange="state.finMonth=this.value;renderFinance()" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px">'+toolMonthSelect+'</select>':state.finView==='quarterly'?'<span class="text-sm text-slate-500 ml-2">季度:</span><select onchange="state.finQuarter=parseInt(this.value);localStorage.setItem(\'opc-fin-quarter\',this.value);renderFinance()" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px">'+toolQuarterSelect+'</select>':'';
|
|
||||||
|
|
||||||
const finHeaderBase = `<span class="text-sm text-slate-500">视图:</span><select onchange="setFinView(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value="overview" ${state.finView==='overview'?'selected':''}>总视图</option><option value="quarterly" ${state.finView==='quarterly'?'selected':''}>季度视图</option><option value="monthly" ${state.finView==='monthly'?'selected':''}>月度视图</option></select>${toolDateSelect}`;
|
|
||||||
const finAddBtn = `<button class="btn btn-primary btn-sm" onclick="openFinanceModal()">新增财务项目</button>`;
|
const finAddBtn = `<button class="btn btn-primary btn-sm" onclick="openFinanceModal()">新增财务项目</button>`;
|
||||||
|
|
||||||
const finFilterTabs = `<div class="finance-tabs" style="padding:0;border-bottom:1px solid #e2e8f0;margin-bottom:0"><button onclick="switchFinFilter('overview')" class="finance-tab${state.finFilter==='overview'?' active':''}" style="font-size:14px;font-weight:600">总览</button><button onclick="switchFinFilter('已签约')" class="finance-tab${state.finFilter==='已签约'?' active':''}" style="font-size:14px;font-weight:600">项目 (${pfs.filter(x=>x.status==='已签约').length})</button><button onclick="switchFinFilter('待签约')" class="finance-tab${state.finFilter==='待签约'?' active':''}" style="font-size:14px;font-weight:600">待签约 (${pfs.filter(x=>x.status==='待签约').length})</button><button onclick="switchFinFilter('expense')" class="finance-tab${state.finFilter==='expense'?' active':''}" style="font-size:14px;font-weight:600">平台费用</button></div>`;
|
const finFilterTabs = `<div class="finance-tabs" style="padding:0;border-bottom:1px solid #e2e8f0;margin-bottom:0"><button onclick="switchFinFilter('overview')" class="finance-tab${state.finFilter==='overview'?' active':''}" style="font-size:14px;font-weight:600">总览</button><button onclick="switchFinFilter('projects')" class="finance-tab${state.finFilter==='projects'?' active':''}" style="font-size:14px;font-weight:600">项目 (${pfs.length})</button><button onclick="switchFinFilter('expense')" class="finance-tab${state.finFilter==='expense'?' active':''}" style="font-size:14px;font-weight:600">平台费用</button></div>`;
|
||||||
|
|
||||||
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
||||||
${finFilterTabs}
|
${finFilterTabs}
|
||||||
@@ -142,7 +139,7 @@ function renderFinance() {
|
|||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" class="form-ctrl" placeholder="必须大于 0"></label>
|
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" class="form-ctrl" placeholder="必须大于 0"></label>
|
||||||
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
||||||
<label class="block"><span class="fin-label">项目状态</span><select name="status" class="form-ctrl bg-white"><option>已签约</option><option>待签约</option></select></label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
||||||
@@ -245,7 +242,7 @@ function renderFinance() {
|
|||||||
setTimeout(() => renderExpense(), 10);
|
setTimeout(() => renderExpense(), 10);
|
||||||
return `<div id="financeExpense"></div>`;
|
return `<div id="financeExpense"></div>`;
|
||||||
}
|
}
|
||||||
const isUnsigned = state.finFilter === '待签约';
|
const isUnsigned = false;
|
||||||
const METRIC_CARDS = [
|
const METRIC_CARDS = [
|
||||||
{ label: '签约金额', value: ctx => moneyWan(ctx.signTotal), color: 'text-slate-700' },
|
{ label: '签约金额', value: ctx => moneyWan(ctx.signTotal), color: 'text-slate-700' },
|
||||||
{ label: '已确收', hideUnsigned: true, value: ctx => moneyWan(ctx.sumRev), color: 'text-blue-700' },
|
{ label: '已确收', hideUnsigned: true, value: ctx => moneyWan(ctx.sumRev), color: 'text-blue-700' },
|
||||||
@@ -259,7 +256,7 @@ function renderFinance() {
|
|||||||
{ label: '毛利率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '毛利率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
{ label: '回款率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '回款率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
{ label: '付款率', hideUnsigned: true, value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '付款率', hideUnsigned: true, value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
].filter(c => state.finFilter !== '待签约' || !c.hideUnsigned);
|
].filter(c => true);
|
||||||
|
|
||||||
// 列排序
|
// 列排序
|
||||||
if (!state.finSort) state.finSort = { key: null, asc: true };
|
if (!state.finSort) state.finSort = { key: null, asc: true };
|
||||||
@@ -285,14 +282,14 @@ function renderFinance() {
|
|||||||
return h;
|
return h;
|
||||||
};
|
};
|
||||||
const SIGNED_COLS = [
|
const SIGNED_COLS = [
|
||||||
{ key: 'customer_name', label: '项目名称' }, { key: 'status', label: '状态' }, { key: 'sign_amount', label: '签约金额' },
|
{ key: 'customer_name', label: '项目名称' }, { key: 'sign_amount', label: '签约金额' },
|
||||||
{ key: 'rev', label: '已确收' }, { key: 'gross', label: '毛利' }, { key: 'cost', label: '成本' },
|
{ key: 'rev', label: '已确收' }, { key: 'gross', label: '毛利' }, { key: 'cost', label: '成本' },
|
||||||
{ key: 'profit', label: '项目利润' }, { key: 'payment', label: '已回款' }, { key: 'paid', label: '已付' },
|
{ key: 'profit', label: '项目利润' }, { key: 'payment', label: '已回款' }, { key: 'paid', label: '已付' },
|
||||||
{ key: 'cashflow', label: '现金流' }, { key: 'exe_rate', label: '执行率' }, { key: 'gross_rate', label: '毛利率' },
|
{ key: 'cashflow', label: '现金流' }, { key: 'exe_rate', label: '执行率' }, { key: 'gross_rate', label: '毛利率' },
|
||||||
{ key: 'pay_rate', label: '回款率' }, { key: 'paid_rate', label: '付款率' },
|
{ key: 'pay_rate', label: '回款率' }, { key: 'paid_rate', label: '付款率' },
|
||||||
];
|
];
|
||||||
const UNSIGNED_COLS = [
|
const UNSIGNED_COLS = [
|
||||||
{ key: 'customer_name', label: '项目名称' }, { key: 'status', label: '状态' }, { key: 'sign_amount', label: '签约金额' },
|
{ key: 'customer_name', label: '项目名称' }, { key: 'sign_amount', label: '签约金额' },
|
||||||
{ key: 'sign_month', label: '签约月份' }, { key: 'gross', label: '毛利' }, { key: 'cost', label: '成本' },
|
{ key: 'sign_month', label: '签约月份' }, { key: 'gross', label: '毛利' }, { key: 'cost', label: '成本' },
|
||||||
{ key: 'profit', label: '项目利润' },
|
{ key: 'profit', label: '项目利润' },
|
||||||
];
|
];
|
||||||
@@ -304,7 +301,7 @@ function renderFinance() {
|
|||||||
return typeof v === 'object' ? [c.label, v.val, v.cls] : [c.label, v, c.color];
|
return typeof v === 'object' ? [c.label, v.val, v.cls] : [c.label, v, c.color];
|
||||||
});
|
});
|
||||||
const thead = isUnsigned ? buildThead(UNSIGNED_COLS, 'uns') : buildThead(SIGNED_COLS, 'sig');
|
const thead = isUnsigned ? buildThead(UNSIGNED_COLS, 'uns') : buildThead(SIGNED_COLS, 'sig');
|
||||||
const theadCols = isUnsigned ? 7 : 14;
|
const theadCols = isUnsigned ? 6 : 13;
|
||||||
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="${theadCols}" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="${theadCols}" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
||||||
|
|
||||||
const cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
const cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
||||||
@@ -324,25 +321,23 @@ function renderFinance() {
|
|||||||
const payR = payRVal !== null ? '<span class="' + payRCls + ' font-semibold">' + payRVal + '%</span>' : '<span class="text-slate-300">—</span>';
|
const payR = payRVal !== null ? '<span class="' + payRCls + ' font-semibold">' + payRVal + '%</span>' : '<span class="text-slate-300">—</span>';
|
||||||
const paidR = cost && paid ? Math.round(paid / cost * 100) + '%' : '<span class="text-slate-300">—</span>';
|
const paidR = cost && paid ? Math.round(paid / cost * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||||
const grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
const grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||||
const st = pf.status === '已签约' ? '<span class="text-green-600">已签约</span>' : '<span class="text-amber-600">待签约</span>';
|
const cf = cashflow ? money(cashflow) : '<span class="text-slate-300">—</span>';
|
||||||
const cf = cashflow ? money(cashflow) : '<span class="text-slate-300">—</span>';
|
|
||||||
const cfCls = cashflow >= 0 ? 'text-green-600' : 'text-red-600';
|
const cfCls = cashflow >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const profit = gross;
|
const profit = gross;
|
||||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
||||||
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm">${st}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center text-blue-700 align-middle">${fmtNoUnit(rev)}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td><td class="p-2 text-center text-amber-700 align-middle">${fmtNoUnit(payment)}</td><td class="p-2 text-center text-purple-700 align-middle">${fmtNoUnit(paid)}</td><td class="p-2 text-center font-semibold align-middle ${cfCls}">${cf}</td><td class="p-2 text-center align-middle text-sm">${exe}</td><td class="p-2 text-center align-middle text-sm">${grossR}</td><td class="p-2 text-center align-middle text-sm">${payR}</td><td class="p-2 text-center align-middle text-sm">${paidR}</td></tr>`;
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center text-blue-700 align-middle">${fmtNoUnit(rev)}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td><td class="p-2 text-center text-amber-700 align-middle">${fmtNoUnit(payment)}</td><td class="p-2 text-center text-purple-700 align-middle">${fmtNoUnit(paid)}</td><td class="p-2 text-center font-semibold align-middle ${cfCls}">${cf}</td><td class="p-2 text-center align-middle text-sm">${exe}</td><td class="p-2 text-center align-middle text-sm">${grossR}</td><td class="p-2 text-center align-middle text-sm">${payR}</td><td class="p-2 text-center align-middle text-sm">${paidR}</td></tr>`;
|
||||||
};
|
};
|
||||||
// 待签约简版行
|
// 待签约简版行
|
||||||
const tdRowUnsigned = (pf, cost, gross) => {
|
const tdRowUnsigned = (pf, cost, gross) => {
|
||||||
const st = pf.status === '待签约' ? '<span class="text-amber-600">待签约</span>' : '<span class="text-green-600">已签约</span>';
|
const profit = gross;
|
||||||
const profit = gross;
|
|
||||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
||||||
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm">${st}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center align-middle text-sm">${pf.sign_month || '—'}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td></tr>`;
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center align-middle text-sm">${pf.sign_month || '—'}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td></tr>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (state.finView === 'monthly') {
|
if (state.finView === 'monthly') {
|
||||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
const allPfs = pfs;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
||||||
if (!state.finMonth) state.finMonth = defaultMonth;
|
if (!state.finMonth) state.finMonth = defaultMonth;
|
||||||
@@ -360,8 +355,7 @@ function renderFinance() {
|
|||||||
const paid = Math.round(parseFloat(e.paid || 0) || 0);
|
const paid = Math.round(parseFloat(e.paid || 0) || 0);
|
||||||
if (!rev && !payment && !cost && !paid && !gross) return;
|
if (!rev && !payment && !cost && !paid && !gross) return;
|
||||||
dataItems.push({
|
dataItems.push({
|
||||||
pf: pf, customer_name: pf.customer_name || '', status: pf.status || '',
|
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||||
sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
|
||||||
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
||||||
cashflow: payment - paid,
|
cashflow: payment - paid,
|
||||||
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
||||||
@@ -379,12 +373,12 @@ function renderFinance() {
|
|||||||
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约" && (x.sign_month || "").substring(0, 7) === selMonth).length;
|
const signCnt = allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该月份暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该月份暂无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.finView === 'quarterly') {
|
if (state.finView === 'quarterly') {
|
||||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
const allPfs = pfs;
|
||||||
const qRanges = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]];
|
const qRanges = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]];
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
if (state.finQuarter === undefined) {
|
if (state.finQuarter === undefined) {
|
||||||
@@ -412,8 +406,7 @@ function renderFinance() {
|
|||||||
const paid = sumExpense(pf, "paid");
|
const paid = sumExpense(pf, "paid");
|
||||||
if (!rev && !payment && !cost && !paid && !gross) return;
|
if (!rev && !payment && !cost && !paid && !gross) return;
|
||||||
dataItems.push({
|
dataItems.push({
|
||||||
pf: pf, customer_name: pf.customer_name || '', status: pf.status || '',
|
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||||
sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
|
||||||
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
||||||
cashflow: payment - paid,
|
cashflow: payment - paid,
|
||||||
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
||||||
@@ -431,7 +424,7 @@ function renderFinance() {
|
|||||||
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.filter(x => { const m = parseInt((x.sign_month || "0").substring(5)) || 0; return qRange.includes(m); }).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.filter(x => { const m = parseInt((x.sign_month || "0").substring(5)) || 0; return qRange.includes(m); }).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约" && qRange.includes(parseInt((x.sign_month || "0").substring(5)) || 0)).length;
|
const signCnt = allPfs.filter(x => qRange.includes(parseInt((x.sign_month || "0").substring(5)) || 0)).length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该季度暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该季度暂无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,12 +438,11 @@ function renderFinance() {
|
|||||||
expense.forEach(e => { cost += parseFloat(e.cost || 0) || 0; paid += parseFloat(e.paid || 0) || 0; });
|
expense.forEach(e => { cost += parseFloat(e.cost || 0) || 0; paid += parseFloat(e.paid || 0) || 0; });
|
||||||
return { rev: Math.round(rev), payment: Math.round(payment), cost: Math.round(cost), paid: Math.round(paid), gross: Math.round(gross) };
|
return { rev: Math.round(rev), payment: Math.round(payment), cost: Math.round(cost), paid: Math.round(paid), gross: Math.round(gross) };
|
||||||
};
|
};
|
||||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
const allPfs = pfs;
|
||||||
var dataItems = allPfs.map(pf => {
|
var dataItems = allPfs.map(pf => {
|
||||||
var t = calcTotals(pf);
|
var t = calcTotals(pf);
|
||||||
return {
|
return {
|
||||||
pf: pf, customer_name: pf.customer_name || '', status: pf.status || '',
|
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||||
sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
|
||||||
rev: t.rev, gross: t.gross, cost: t.cost, profit: t.gross,
|
rev: t.rev, gross: t.gross, cost: t.cost, profit: t.gross,
|
||||||
payment: t.payment, paid: t.paid, cashflow: t.payment - t.paid,
|
payment: t.payment, paid: t.paid, cashflow: t.payment - t.paid,
|
||||||
exe_rate: t.rev && pf.sign_amount ? Math.round(t.rev / pf.sign_amount * 100) : 0,
|
exe_rate: t.rev && pf.sign_amount ? Math.round(t.rev / pf.sign_amount * 100) : 0,
|
||||||
@@ -468,7 +460,7 @@ function renderFinance() {
|
|||||||
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约").length;
|
const signCnt = allPfs.length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '暂无数据');
|
||||||
})()}
|
})()}
|
||||||
</div>`;
|
</div>`;
|
||||||
@@ -789,7 +781,6 @@ window.openPfEditModal = (pfId) => {
|
|||||||
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
||||||
signMonthEl.value = signMonthValue;
|
signMonthEl.value = signMonthValue;
|
||||||
}
|
}
|
||||||
form.querySelector('[name="status"]').value = pf.status || "待签约";
|
|
||||||
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
||||||
form.querySelector('[name="owner"]').value = pf.owner || "";
|
form.querySelector('[name="owner"]').value = pf.owner || "";
|
||||||
setVal("start_date", pf.start_date);
|
setVal("start_date", pf.start_date);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ window.renderPerformance = () => {
|
|||||||
const qRange = qRanges[q];
|
const qRange = qRanges[q];
|
||||||
const storageKey = 'opc-performance-Q' + (q + 1);
|
const storageKey = 'opc-performance-Q' + (q + 1);
|
||||||
|
|
||||||
const pfs = (data.projectFinances || []).filter(p => p.status === '已签约');
|
const pfs = (data.projectFinances || []);
|
||||||
|
|
||||||
const sumQ = (field) => {
|
const sumQ = (field) => {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ function renderPlan() {
|
|||||||
const months = displayMonths.map(d => d.key);
|
const months = displayMonths.map(d => d.key);
|
||||||
const monthLabels = displayMonths.map(d => d.label);
|
const monthLabels = displayMonths.map(d => d.label);
|
||||||
|
|
||||||
const signed = pfs.filter(x => x.status === "已签约");
|
const signed = pfs;
|
||||||
const pending = pfs.filter(x => x.status === "待签约");
|
const pending = pfs;
|
||||||
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
|
|
||||||
@@ -95,31 +95,32 @@ function renderPlan() {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
const sm = pf.sign_month || "";
|
const sm = pf.sign_month || "";
|
||||||
const signMonthCell = `<td class="p-2 text-center align-middle text-sm"><span class="pf-sm-text cursor-pointer hover:text-blue-600" id="pf-sm-${pf.id}" onclick="event.stopPropagation(); editPfSignMonth(event, ${pf.id})">${sm || '—'}</span></td>`;
|
const signMonthCell = `<td class="p-2 text-center align-middle text-sm"><span class="pf-sm-text cursor-pointer hover:text-blue-600" id="pf-sm-${pf.id}" onclick="event.stopPropagation(); planEditSignMonth(event, ${pf.id})">${sm || '—'}</span></td>`;
|
||||||
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle">${esc(pf.customer_name)}</td>${signMonthCell}<td class="p-2 text-center align-middle text-sm">${money(pf.sign_amount)}</td>${mCols}${totalCol}</tr>`;
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="planOpenPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle">${esc(pf.customer_name)}</td>${signMonthCell}<td class="p-2 text-center align-middle text-sm">${money(pf.sign_amount)}</td>${mCols}${totalCol}</tr>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const now2 = new Date();
|
const now2 = new Date();
|
||||||
const defaultMonth2 = now2.getFullYear() + "-" + String(now2.getMonth()+1).padStart(2,"0");
|
const defaultMonth2 = now2.getFullYear() + "-" + String(now2.getMonth()+1).padStart(2,"0");
|
||||||
if (!state.planMonth) state.planMonth = defaultMonth2;
|
if (!state.planMonth) state.planMonth = defaultMonth2;
|
||||||
if (state.planQuarter === undefined) state.planQuarter = Math.floor(now2.getMonth() / 3);
|
if (state.planQuarter === undefined) state.planQuarter = Math.floor(now2.getMonth() / 3);
|
||||||
const monthSet2 = new Set([defaultMonth2]);
|
const qLabels = ['Q1','Q2','Q3','Q4'];
|
||||||
pfs.forEach(pf => { let bd = []; try { bd = JSON.parse(pf.budget_data || "[]"); } catch(e) {} bd.forEach(b => { if (b.month) monthSet2.add(b.month); }); });
|
const qMonths = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]];
|
||||||
const allMonths = [...monthSet2].sort().reverse();
|
const nowD = new Date();
|
||||||
const qLabels2 = ["Q1 (1-3月)","Q2 (4-6月)","Q3 (7-9月)","Q4 (10-12月)"];
|
const activeQ = state.planQuarter !== undefined ? state.planQuarter : Math.floor(nowD.getMonth() / 3);
|
||||||
const toolMonthSelect = allMonths.map(m => '<option value="'+m+'" '+(m===state.planMonth?'selected':'')+'>'+m+'</option>').join("");
|
const activeMonths = qMonths[activeQ];
|
||||||
const toolQuarterSelect = qLabels2.map((l,i) => '<option value="'+i+'" '+(i===state.planQuarter?'selected':'')+'>'+l+'</option>').join("");
|
const finHeaderBase = `<div class="flex items-center gap-2"><button onclick="setPlanView('overview')" class="px-3 py-1 rounded text-sm font-medium ${state.planView==='overview'?'bg-blue-600 text-white':'bg-slate-100 text-slate-600 hover:bg-slate-200'}">总视图</button><span class="text-slate-300 mx-2">|</span><span class="text-sm text-slate-500">按季度:</span>${qLabels.map((q,i) => `<button onclick="setPlanQuarter(${i})" class="px-3 py-1 rounded text-sm font-medium ${state.planView==='quarterly'&&activeQ===i?'bg-blue-600 text-white':'bg-slate-100 text-slate-600 hover:bg-slate-200'}">${q}</button>`).join('')}<span class="text-slate-300 mx-2">|</span><span class="text-sm text-slate-500">按月度:</span>${activeMonths.map(m => { const ms = `2026-${String(m).padStart(2,'0')}`; return `<button onclick="setPlanMonth('${ms}')" class="px-3 py-1 rounded text-sm font-medium ${state.planView==='monthly'&&state.planMonth===ms?'bg-blue-600 text-white':'bg-slate-100 text-slate-600 hover:bg-slate-200'}">${m}月</button>`; }).join('')}</div>`;
|
||||||
const toolDateSelect = state.planView==='monthly'?'<span class="text-sm text-slate-500 ml-2">月份:</span><select onchange="state.planMonth=this.value;renderPlan()" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px">'+toolMonthSelect+'</select>':state.planView==='quarterly'?'<span class="text-sm text-slate-500 ml-2">季度:</span><select onchange="state.planQuarter=parseInt(this.value);localStorage.setItem(\'opc-fin-quarter\',this.value);renderPlan()" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px">'+toolQuarterSelect+'</select>':'';
|
|
||||||
|
|
||||||
const finHeaderBase = `<span class="text-sm text-slate-500">视图:</span><select onchange="setPlanView(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value="overview" ${state.planView==='overview'?'selected':''}>总视图</option><option value="quarterly" ${state.planView==='quarterly'?'selected':''}>季度视图</option><option value="monthly" ${state.planView==='monthly'?'selected':''}>月度视图</option></select>${toolDateSelect}`;
|
|
||||||
const finAddBtn = `<button class="btn btn-primary btn-sm" onclick="openPlanModal()">新增财务项目</button>`;
|
const finAddBtn = `<button class="btn btn-primary btn-sm" onclick="openPlanModal()">新增财务项目</button>`;
|
||||||
|
|
||||||
const planFilterTabs = `<div class="finance-tabs" style="padding:0 0 0 0;border-bottom:1px solid #e2e8f0;margin-bottom:0;display:flex;gap:4px"><button onclick="switchPlanFilter('overview')" class="finance-tab${state.planFilter==='overview'?' active':''}" style="font-size:14px;font-weight:600;padding:8px 16px;margin-right:0">总览</button><button onclick="switchPlanFilter('已签约')" class="finance-tab${state.planFilter==='已签约'?' active':''}" style="font-size:14px;font-weight:600">项目 (${pfs.filter(x=>x.status==='已签约').length})</button><button onclick="switchPlanFilter('待签约')" class="finance-tab${state.planFilter==='待签约'?' active':''}" style="font-size:14px;font-weight:600">待签约 (${pfs.filter(x=>x.status==='待签约').length})</button><button onclick="switchPlanFilter('expense')" class="finance-tab${state.planFilter==='expense'?' active':''}" style="font-size:14px;font-weight:600">平台费用</button></div>`;
|
const planFilterTabs = `<div class="finance-tabs" style="padding:0 0 0 0;border-bottom:1px solid #e2e8f0;margin-bottom:0;display:flex;gap:4px"><button onclick="switchPlanFilter('overview')" class="finance-tab${state.planFilter==='overview'?' active':''}" style="font-size:14px;font-weight:600;padding:8px 16px;margin-right:0">总览</button><button onclick="switchPlanFilter('projects')" class="finance-tab${state.planFilter==='projects'?' active':''}" style="font-size:14px;font-weight:600">项目计划 (${pfs.length})</button><button onclick="switchPlanFilter('expense')" class="finance-tab${state.planFilter==='expense'?' active':''}" style="font-size:14px;font-weight:600">平台费用计划</button></div>`;
|
||||||
|
|
||||||
document.querySelector("#plan").innerHTML = `<div class="grid gap-4">
|
document.querySelector("#plan").innerHTML = `<div class="grid gap-4">
|
||||||
${planFilterTabs}
|
${planFilterTabs}
|
||||||
|
<div class="flex items-center gap-3 px-4 py-3 rounded-lg border" style="background:linear-gradient(135deg,#dbeafe,#bfdbfe);border-color:#3b82f6">
|
||||||
|
<i data-lucide="lightbulb" class="text-blue-600 flex-shrink-0" style="width:18px;height:18px"></i>
|
||||||
|
<span class="text-sm text-blue-900"><strong>计划提醒:</strong>计划也是预算,只有真正能够列出计划的预算,才有靠谱的落地可能性</span>
|
||||||
|
</div>
|
||||||
${state.planFilter !== 'expense' && state.planFilter !== 'overview' ? card(`<div class="flex justify-between items-center"><div class="flex items-center gap-2">${finHeaderBase}</div>${finAddBtn}</div>`, "p-4") : ''}
|
${state.planFilter !== 'expense' && state.planFilter !== 'overview' ? card(`<div class="flex justify-between items-center"><div class="flex items-center gap-2">${finHeaderBase}</div>${finAddBtn}</div>`, "p-4") : ''}
|
||||||
<div id="financeModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closePlanModal()"><div class="bg-white rounded-2xl shadow-2xl w-full max-w-6xl mx-4 max-h-[92vh] overflow-y-auto" onclick="event.stopPropagation()"><div class="sticky top-0 z-10 bg-white/95 backdrop-blur border-b border-slate-100 px-8 py-5 flex items-center justify-between"><div><h3 class="text-xl font-bold text-slate-800" id="financeModalTitle">新增项目财务</h3><p class="text-xs text-slate-400 mt-0.5">填写项目财务信息与月度预算</p></div><div class="flex items-center gap-2"><button class="btn btn-ghost btn-sm text-red-600 hidden" id="financeDeleteBtn" onclick="deletePlanItem()"><i data-lucide="trash-2"></i>删除</button><button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closePlanModal()"><i data-lucide="x"></i></button></div></div>
|
<div id="planModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closePlanModal()"><div class="bg-white rounded-2xl shadow-2xl w-full max-w-6xl mx-4 max-h-[92vh] overflow-y-auto" onclick="event.stopPropagation()"><div class="sticky top-0 z-10 bg-white/95 backdrop-blur border-b border-slate-100 px-8 py-5 flex items-center justify-between"><div><h3 class="text-xl font-bold text-slate-800" id="planModalTitle">新增项目财务</h3><p class="text-xs text-slate-400 mt-0.5">填写项目财务信息与月度预算</p></div><div class="flex items-center gap-2"><button class="btn btn-ghost btn-sm text-red-600 hidden" id="planDeleteBtn" onclick="deletePlanItem()"><i data-lucide="trash-2"></i>删除</button><button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closePlanModal()"><i data-lucide="x"></i></button></div></div>
|
||||||
<div class="finance-tabs">
|
<div class="finance-tabs">
|
||||||
<button class="finance-tab active" data-tab="info" onclick="switchPlanTab('info')"><i data-lucide="info" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>基本信息</button>
|
<button class="finance-tab active" data-tab="info" onclick="switchPlanTab('info')"><i data-lucide="info" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>基本信息</button>
|
||||||
<button class="finance-tab" data-tab="revpay" onclick="switchPlanTab('revpay')"><i data-lucide="dollar-sign" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>确收与回款</button>
|
<button class="finance-tab" data-tab="revpay" onclick="switchPlanTab('revpay')"><i data-lucide="dollar-sign" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>确收与回款</button>
|
||||||
@@ -128,9 +129,9 @@ function renderPlan() {
|
|||||||
<button class="finance-tab" data-tab="tasks" onclick="switchPlanTab('tasks')"><i data-lucide="list-checks" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>任务管理</button>
|
<button class="finance-tab" data-tab="tasks" onclick="switchPlanTab('tasks')"><i data-lucide="list-checks" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>任务管理</button>
|
||||||
<button class="finance-tab" data-tab="activity" onclick="switchPlanTab('activity')"><i data-lucide="message-square" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>活动与跟进</button>
|
<button class="finance-tab" data-tab="activity" onclick="switchPlanTab('activity')"><i data-lucide="message-square" style="width:14px;height:14px;display:inline-block;vertical-align:-2px;margin-right:4px"></i>活动与跟进</button>
|
||||||
</div>
|
</div>
|
||||||
<form onsubmit="createPlanFinance(event)" class="plan-form" novalidate><input type="hidden" name="pf_id" id="pf-id-input" value="">
|
<form onsubmit="createPlanFinance(event)" class="finance-form" novalidate><input type="hidden" name="pf_id" id="plan_pf-id-input" value="">
|
||||||
<div class="plan-tab-body">
|
<div class="finance-tab-body">
|
||||||
<div id="financeTabInfo">
|
<div id="plan_financeTabInfo">
|
||||||
<div class="grid gap-4">
|
<div class="grid gap-4">
|
||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">部门</span><input type="hidden" name="project_id" value="${state.tenant}"><input class="form-ctrl bg-slate-50 cursor-not-allowed" value="${state.tenant}" disabled></label>
|
<label class="block"><span class="fin-label">部门</span><input type="hidden" name="project_id" value="${state.tenant}"><input class="form-ctrl bg-slate-50 cursor-not-allowed" value="${state.tenant}" disabled></label>
|
||||||
@@ -140,7 +141,7 @@ function renderPlan() {
|
|||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" class="form-ctrl" placeholder="必须大于 0"></label>
|
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" class="form-ctrl" placeholder="必须大于 0"></label>
|
||||||
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
||||||
<label class="block"><span class="fin-label">项目状态</span><select name="status" class="form-ctrl bg-white"><option>已签约</option><option>待签约</option></select></label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
||||||
@@ -151,10 +152,10 @@ function renderPlan() {
|
|||||||
<label class="block"><span class="fin-label">联系电话</span><input name="contact_phone" class="form-ctrl" placeholder="请输入联系电话"></label>
|
<label class="block"><span class="fin-label">联系电话</span><input name="contact_phone" class="form-ctrl" placeholder="请输入联系电话"></label>
|
||||||
<label class="block"><span class="fin-label">其他</span><input name="other_info" class="form-ctrl" placeholder="备注信息"></label>
|
<label class="block"><span class="fin-label">其他</span><input name="other_info" class="form-ctrl" placeholder="备注信息"></label>
|
||||||
</div>
|
</div>
|
||||||
<div class="block"><span class="fin-label">业务类型</span><div class="flex flex-wrap gap-2 mt-1" id="businessTypeChecks">${fmTypes.map(t => `<label class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-slate-200 cursor-pointer hover:border-blue-300 text-sm bt-chip" onclick="toggleBtChip(this)"><input type="checkbox" name="business_type[]" value="${t}" class="hidden"><span>${t}</span></label>`).join("")}</div></div>
|
<div class="block"><span class="fin-label">业务类型</span><div class="flex flex-wrap gap-2 mt-1" id="plan_businessTypeChecks">${fmTypes.map(t => `<label class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-slate-200 cursor-pointer hover:border-blue-300 text-sm bt-chip" onclick="planToggleBtChip(this)"><input type="checkbox" name="business_type[]" value="${t}" class="hidden"><span>${t}</span></label>`).join("")}</div></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="financeTabExec" class="hidden">
|
<div id="plan_financeTabExec" class="hidden">
|
||||||
<div class="fin-field-group">
|
<div class="fin-field-group">
|
||||||
<p class="fin-section-label">执行信息</p>
|
<p class="fin-section-label">执行信息</p>
|
||||||
<div class="grid grid-cols-3 gap-4">
|
<div class="grid grid-cols-3 gap-4">
|
||||||
@@ -165,53 +166,53 @@ function renderPlan() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="financeTabRevpay" class="hidden">
|
<div id="plan_financeTabRevpay" class="hidden">
|
||||||
<div class="grid grid-cols-3 gap-3 mb-4" id="revpaySummary">
|
<div class="grid grid-cols-3 gap-3 mb-4" id="plan_revpaySummary">
|
||||||
<div class="bg-blue-50 rounded-lg p-3 text-center border border-blue-100">
|
<div class="bg-blue-50 rounded-lg p-3 text-center border border-blue-100">
|
||||||
<p class="text-xs text-blue-600 font-medium">总确收</p>
|
<p class="text-xs text-blue-600 font-medium">总确收</p>
|
||||||
<p class="text-lg font-bold text-blue-700" id="revpayTotalRev">¥0</p>
|
<p class="text-lg font-bold text-blue-700" id="plan_revpayTotalRev">¥0</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-green-50 rounded-lg p-3 text-center border border-green-100">
|
<div class="bg-green-50 rounded-lg p-3 text-center border border-green-100">
|
||||||
<p class="text-xs text-green-600 font-medium">总毛利</p>
|
<p class="text-xs text-green-600 font-medium">总毛利</p>
|
||||||
<p class="text-lg font-bold text-green-700" id="revpayTotalGross">¥0</p>
|
<p class="text-lg font-bold text-green-700" id="plan_revpayTotalGross">¥0</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-amber-50 rounded-lg p-3 text-center border border-amber-100">
|
<div class="bg-amber-50 rounded-lg p-3 text-center border border-amber-100">
|
||||||
<p class="text-xs text-amber-600 font-medium">总回款</p>
|
<p class="text-xs text-amber-600 font-medium">总回款</p>
|
||||||
<p class="text-lg font-bold text-amber-700" id="revpayTotalPayment">¥0</p>
|
<p class="text-lg font-bold text-amber-700" id="plan_revpayTotalPayment">¥0</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="revpayTable">
|
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="plan_revpayTable">
|
||||||
<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-left 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-left font-medium text-slate-500">备注</th><th class="p-2.5 w-8"></th></tr></thead>
|
||||||
<tbody id="revpayTbody"></tbody>
|
<tbody id="plan_revpayTbody"></tbody>
|
||||||
</table>
|
</table>
|
||||||
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="addRevpayRow()"><i data-lucide="plus"></i>添加月份</button>
|
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="planAddRevpayRow()"><i data-lucide="plus"></i>添加月份</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="financeTabCost" class="hidden">
|
<div id="plan_financeTabCost" class="hidden">
|
||||||
<div class="grid grid-cols-2 gap-3 mb-4" id="costSummary">
|
<div class="grid grid-cols-2 gap-3 mb-4" id="plan_costSummary">
|
||||||
<div class="bg-rose-50 rounded-lg p-3 text-center border border-rose-100">
|
<div class="bg-rose-50 rounded-lg p-3 text-center border border-rose-100">
|
||||||
<p class="text-xs text-rose-600 font-medium">总成本</p>
|
<p class="text-xs text-rose-600 font-medium">总成本</p>
|
||||||
<p class="text-lg font-bold text-rose-700" id="costTotalCost">¥0</p>
|
<p class="text-lg font-bold text-rose-700" id="plan_costTotalCost">¥0</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-purple-50 rounded-lg p-3 text-center border border-purple-100">
|
<div class="bg-purple-50 rounded-lg p-3 text-center border border-purple-100">
|
||||||
<p class="text-xs text-purple-600 font-medium">总已付</p>
|
<p class="text-xs text-purple-600 font-medium">总已付</p>
|
||||||
<p class="text-lg font-bold text-purple-700" id="costTotalPaid">¥0</p>
|
<p class="text-lg font-bold text-purple-700" id="plan_costTotalPaid">¥0</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="costTable">
|
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="plan_costTable">
|
||||||
<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-left font-medium text-slate-500" style="min-width:120px">费用类型</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-left 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-left font-medium text-slate-500" style="min-width:120px">费用类型</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-left font-medium text-slate-500">备注</th><th class="p-2.5 w-8"></th></tr></thead>
|
||||||
<tbody id="costTbody"></tbody>
|
<tbody id="plan_costTbody"></tbody>
|
||||||
</table>
|
</table>
|
||||||
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="addCostRow()"><i data-lucide="plus"></i>添加月份</button>
|
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="planAddCostRow()"><i data-lucide="plus"></i>添加月份</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="financeTabTasks" class="hidden">
|
<div id="plan_financeTabTasks" class="hidden">
|
||||||
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="taskTable">
|
<table class="w-full text-sm border border-slate-200 rounded-lg overflow-hidden" id="plan_taskTable">
|
||||||
<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:120px">月份</th><th class="p-2.5 text-left font-medium text-slate-500" style="min-width:120px">任务类型</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:120px">月份</th><th class="p-2.5 text-left font-medium text-slate-500" style="min-width:120px">任务类型</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="taskTbody"></tbody>
|
<tbody id="plan_taskTbody"></tbody>
|
||||||
</table>
|
</table>
|
||||||
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="addTaskRow()"><i data-lucide="plus"></i>添加任务</button>
|
<button type="button" class="btn btn-ghost btn-sm mt-3" onclick="planAddTaskRow()"><i data-lucide="plus"></i>添加任务</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="financeTabActivity" class="hidden">
|
<div id="plan_financeTabActivity" class="hidden">
|
||||||
<div class="grid gap-2" id="finActivityList"></div>
|
<div class="grid gap-2" id="plan_finActivityList"></div>
|
||||||
<div class="comment-box mt-3">
|
<div class="comment-box mt-3">
|
||||||
<div class="squire-toolbar">
|
<div class="squire-toolbar">
|
||||||
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('bold')" title="加粗"><i data-lucide="bold"></i></button>
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('bold')" title="加粗"><i data-lucide="bold"></i></button>
|
||||||
@@ -226,24 +227,24 @@ function renderPlan() {
|
|||||||
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('undo')" title="撤销"><i data-lucide="undo"></i></button>
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('undo')" title="撤销"><i data-lucide="undo"></i></button>
|
||||||
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('redo')" title="重做"><i data-lucide="redo"></i></button>
|
<button type="button" class="squire-btn" onmousedown="event.preventDefault();squireCmd('redo')" title="重做"><i data-lucide="redo"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="squire-editor" id="squire_finance" placeholder="添加评论"></div>
|
<div class="squire-editor" id="plan_squire_finance" placeholder="添加评论"></div>
|
||||||
<div class="comment-toolbar">
|
<div class="comment-toolbar">
|
||||||
<span class="comment-hint">支持富文本编辑</span>
|
<span class="comment-hint">支持富文本编辑</span>
|
||||||
<button class="btn btn-primary btn-sm comment-submit" type="button" onclick="submitFinComment()">评论</button>
|
<button class="btn btn-primary btn-sm comment-submit" type="button" onclick="planSubmitComment()">评论</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div><div class="flex justify-end gap-3 pt-2 plan-form-actions"><button type="button" class="btn btn-ghost btn-sm px-6" onclick="closePlanModal()">取消</button><button type="submit" class="btn btn-primary btn-sm px-8">保存</button></div></form></div></div>
|
</div><div class="flex justify-end gap-3 pt-2 finance-form-actions"><button type="button" class="btn btn-ghost btn-sm px-6" onclick="closePlanModal()">取消</button><button type="submit" class="btn btn-primary btn-sm px-8">保存</button></div></form></div></div>
|
||||||
${(() => {
|
${(() => {
|
||||||
if (state.planFilter === 'overview') {
|
if (state.planFilter === 'overview') {
|
||||||
setTimeout(() => renderPlanOverview(), 10);
|
setTimeout(() => renderPlanOverview(), 10);
|
||||||
return `<div id="financeOverview"></div>`;
|
return `<div id="planOverview"></div>`;
|
||||||
}
|
}
|
||||||
if (state.planFilter === 'expense') {
|
if (state.planFilter === 'expense') {
|
||||||
setTimeout(() => renderPlanExpense(), 10);
|
setTimeout(() => renderPlanExpense(), 10);
|
||||||
return `<div id="planExpenseModule"></div>`;
|
return `<div id="planExpenseModule"></div>`;
|
||||||
}
|
}
|
||||||
const isUnsigned = state.planFilter === '待签约';
|
const isUnsigned = false;
|
||||||
const METRIC_CARDS = [
|
const METRIC_CARDS = [
|
||||||
{ label: '签约金额', value: ctx => moneyWan(ctx.signTotal), color: 'text-slate-700' },
|
{ label: '签约金额', value: ctx => moneyWan(ctx.signTotal), color: 'text-slate-700' },
|
||||||
{ label: '已确收', hideUnsigned: true, value: ctx => moneyWan(ctx.sumRev), color: 'text-blue-700' },
|
{ label: '已确收', hideUnsigned: true, value: ctx => moneyWan(ctx.sumRev), color: 'text-blue-700' },
|
||||||
@@ -257,7 +258,7 @@ function renderPlan() {
|
|||||||
{ label: '毛利率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '毛利率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
{ label: '回款率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '回款率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
{ label: '付款率', hideUnsigned: true, value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '付款率', hideUnsigned: true, value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
].filter(c => state.planFilter !== '待签约' || !c.hideUnsigned);
|
].filter(c => true);
|
||||||
|
|
||||||
// 列排序
|
// 列排序
|
||||||
if (!state.planSort) state.planSort = { key: null, asc: true };
|
if (!state.planSort) state.planSort = { key: null, asc: true };
|
||||||
@@ -285,7 +286,7 @@ function renderPlan() {
|
|||||||
};
|
};
|
||||||
const SIGNED_COLS = [
|
const SIGNED_COLS = [
|
||||||
{ key: 'customer_name', label: '项目名称' },
|
{ key: 'customer_name', label: '项目名称' },
|
||||||
{ key: 'status', label: '状态' },
|
,
|
||||||
{ key: 'sign_amount', label: '签约金额' },
|
{ key: 'sign_amount', label: '签约金额' },
|
||||||
{ key: 'rev', label: '已确收' },
|
{ key: 'rev', label: '已确收' },
|
||||||
{ key: 'gross', label: '毛利' },
|
{ key: 'gross', label: '毛利' },
|
||||||
@@ -301,7 +302,7 @@ function renderPlan() {
|
|||||||
];
|
];
|
||||||
const UNSIGNED_COLS = [
|
const UNSIGNED_COLS = [
|
||||||
{ key: 'customer_name', label: '项目名称' },
|
{ key: 'customer_name', label: '项目名称' },
|
||||||
{ key: 'status', label: '状态' },
|
,
|
||||||
{ key: 'sign_amount', label: '签约金额' },
|
{ key: 'sign_amount', label: '签约金额' },
|
||||||
{ key: 'sign_month', label: '签约月份' },
|
{ key: 'sign_month', label: '签约月份' },
|
||||||
{ key: 'gross', label: '毛利' },
|
{ key: 'gross', label: '毛利' },
|
||||||
@@ -316,7 +317,7 @@ function renderPlan() {
|
|||||||
return typeof v === 'object' ? [c.label, v.val, v.cls] : [c.label, v, c.color];
|
return typeof v === 'object' ? [c.label, v.val, v.cls] : [c.label, v, c.color];
|
||||||
});
|
});
|
||||||
const thead = isUnsigned ? buildThead(UNSIGNED_COLS, 'uns') : buildThead(SIGNED_COLS, 'sig');
|
const thead = isUnsigned ? buildThead(UNSIGNED_COLS, 'uns') : buildThead(SIGNED_COLS, 'sig');
|
||||||
const theadCols = isUnsigned ? 7 : 14;
|
const theadCols = isUnsigned ? 6 : 13;
|
||||||
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="${theadCols}" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="${theadCols}" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
||||||
|
|
||||||
const cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
const cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
||||||
@@ -336,25 +337,23 @@ function renderPlan() {
|
|||||||
const payR = payRVal !== null ? '<span class="' + payRCls + ' font-semibold">' + payRVal + '%</span>' : '<span class="text-slate-300">—</span>';
|
const payR = payRVal !== null ? '<span class="' + payRCls + ' font-semibold">' + payRVal + '%</span>' : '<span class="text-slate-300">—</span>';
|
||||||
const paidR = cost && paid ? Math.round(paid / cost * 100) + '%' : '<span class="text-slate-300">—</span>';
|
const paidR = cost && paid ? Math.round(paid / cost * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||||
const grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
const grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||||
const st = pf.status === '已签约' ? '<span class="text-green-600">已签约</span>' : '<span class="text-amber-600">待签约</span>';
|
const cf = cashflow ? money(cashflow) : '<span class="text-slate-300">—</span>';
|
||||||
const cf = cashflow ? money(cashflow) : '<span class="text-slate-300">—</span>';
|
|
||||||
const cfCls = cashflow >= 0 ? 'text-green-600' : 'text-red-600';
|
const cfCls = cashflow >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const profit = gross;
|
const profit = gross;
|
||||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
||||||
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm">${st}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center text-blue-700 align-middle">${fmtNoUnit(rev)}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td><td class="p-2 text-center text-amber-700 align-middle">${fmtNoUnit(payment)}</td><td class="p-2 text-center text-purple-700 align-middle">${fmtNoUnit(paid)}</td><td class="p-2 text-center font-semibold align-middle ${cfCls}">${cf}</td><td class="p-2 text-center align-middle text-sm">${exe}</td><td class="p-2 text-center align-middle text-sm">${grossR}</td><td class="p-2 text-center align-middle text-sm">${payR}</td><td class="p-2 text-center align-middle text-sm">${paidR}</td></tr>`;
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="planOpenPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center text-blue-700 align-middle">${fmtNoUnit(rev)}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td><td class="p-2 text-center text-amber-700 align-middle">${fmtNoUnit(payment)}</td><td class="p-2 text-center text-purple-700 align-middle">${fmtNoUnit(paid)}</td><td class="p-2 text-center font-semibold align-middle ${cfCls}">${cf}</td><td class="p-2 text-center align-middle text-sm">${exe}</td><td class="p-2 text-center align-middle text-sm">${grossR}</td><td class="p-2 text-center align-middle text-sm">${payR}</td><td class="p-2 text-center align-middle text-sm">${paidR}</td></tr>`;
|
||||||
};
|
};
|
||||||
// 待签约简版行
|
// 待签约简版行
|
||||||
const tdRowUnsigned = (pf, cost, gross) => {
|
const tdRowUnsigned = (pf, cost, gross) => {
|
||||||
const st = pf.status === '待签约' ? '<span class="text-amber-600">待签约</span>' : '<span class="text-green-600">已签约</span>';
|
const profit = gross;
|
||||||
const profit = gross;
|
|
||||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
||||||
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm">${st}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center align-middle text-sm">${pf.sign_month || '—'}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td></tr>`;
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="planOpenPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center align-middle text-sm">${pf.sign_month || '—'}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td></tr>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (state.planView === 'monthly') {
|
if (state.planView === 'monthly') {
|
||||||
const allPfs = pfs.filter(x => x.status === state.planFilter);
|
const allPfs = pfs;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
||||||
if (!state.planMonth) state.planMonth = defaultMonth;
|
if (!state.planMonth) state.planMonth = defaultMonth;
|
||||||
@@ -374,8 +373,7 @@ function renderPlan() {
|
|||||||
dataItems.push({
|
dataItems.push({
|
||||||
pf: pf,
|
pf: pf,
|
||||||
customer_name: pf.customer_name || '',
|
customer_name: pf.customer_name || '',
|
||||||
status: pf.status || '',
|
sign_amount: pf.sign_amount || 0,
|
||||||
sign_amount: pf.sign_amount || 0,
|
|
||||||
sign_month: pf.sign_month || '',
|
sign_month: pf.sign_month || '',
|
||||||
rev: rev, gross: gross, cost: cost,
|
rev: rev, gross: gross, cost: cost,
|
||||||
profit: gross, payment: payment, paid: paid,
|
profit: gross, payment: payment, paid: paid,
|
||||||
@@ -395,12 +393,12 @@ function renderPlan() {
|
|||||||
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约" && (x.sign_month || "").substring(0, 7) === selMonth).length;
|
const signCnt = allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该月份暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该月份暂无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.planView === 'quarterly') {
|
if (state.planView === 'quarterly') {
|
||||||
const allPfs = pfs.filter(x => x.status === state.planFilter);
|
const allPfs = pfs;
|
||||||
const qRanges = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]];
|
const qRanges = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]];
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
if (state.planQuarter === undefined) {
|
if (state.planQuarter === undefined) {
|
||||||
@@ -430,8 +428,7 @@ function renderPlan() {
|
|||||||
dataItems.push({
|
dataItems.push({
|
||||||
pf: pf,
|
pf: pf,
|
||||||
customer_name: pf.customer_name || '',
|
customer_name: pf.customer_name || '',
|
||||||
status: pf.status || '',
|
sign_amount: pf.sign_amount || 0,
|
||||||
sign_amount: pf.sign_amount || 0,
|
|
||||||
sign_month: pf.sign_month || '',
|
sign_month: pf.sign_month || '',
|
||||||
rev: rev, gross: gross, cost: cost,
|
rev: rev, gross: gross, cost: cost,
|
||||||
profit: gross, payment: payment, paid: paid,
|
profit: gross, payment: payment, paid: paid,
|
||||||
@@ -451,7 +448,7 @@ function renderPlan() {
|
|||||||
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.filter(x => { const m = parseInt((x.sign_month || "0").substring(5)) || 0; return qRange.includes(m); }).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.filter(x => { const m = parseInt((x.sign_month || "0").substring(5)) || 0; return qRange.includes(m); }).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约" && qRange.includes(parseInt((x.sign_month || "0").substring(5)) || 0)).length;
|
const signCnt = allPfs.filter(x => qRange.includes(parseInt((x.sign_month || "0").substring(5)) || 0)).length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该季度暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该季度暂无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,15 +462,14 @@ function renderPlan() {
|
|||||||
expense.forEach(e => { cost += parseFloat(e.cost || 0) || 0; paid += parseFloat(e.paid || 0) || 0; });
|
expense.forEach(e => { cost += parseFloat(e.cost || 0) || 0; paid += parseFloat(e.paid || 0) || 0; });
|
||||||
return { rev: Math.round(rev), payment: Math.round(payment), cost: Math.round(cost), paid: Math.round(paid), gross: Math.round(gross) };
|
return { rev: Math.round(rev), payment: Math.round(payment), cost: Math.round(cost), paid: Math.round(paid), gross: Math.round(gross) };
|
||||||
};
|
};
|
||||||
const allPfs = pfs.filter(x => x.status === state.planFilter);
|
const allPfs = pfs;
|
||||||
var dataItems = allPfs.map(pf => {
|
var dataItems = allPfs.map(pf => {
|
||||||
var t = calcTotals(pf);
|
var t = calcTotals(pf);
|
||||||
var cashflow = t.payment - t.paid;
|
var cashflow = t.payment - t.paid;
|
||||||
return {
|
return {
|
||||||
pf: pf,
|
pf: pf,
|
||||||
customer_name: pf.customer_name || '',
|
customer_name: pf.customer_name || '',
|
||||||
status: pf.status || '',
|
sign_amount: pf.sign_amount || 0,
|
||||||
sign_amount: pf.sign_amount || 0,
|
|
||||||
rev: t.rev, gross: t.gross, cost: t.cost,
|
rev: t.rev, gross: t.gross, cost: t.cost,
|
||||||
profit: t.gross, payment: t.payment, paid: t.paid,
|
profit: t.gross, payment: t.payment, paid: t.paid,
|
||||||
cashflow: cashflow,
|
cashflow: cashflow,
|
||||||
@@ -493,7 +489,7 @@ function renderPlan() {
|
|||||||
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约").length;
|
const signCnt = allPfs.length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '暂无数据');
|
||||||
})()}
|
})()}
|
||||||
</div>`;
|
</div>`;
|
||||||
@@ -508,46 +504,46 @@ window.openPlanModal = () => {
|
|||||||
if (dept) dept.value = state.tenant;
|
if (dept) dept.value = state.tenant;
|
||||||
const pfIdInput = form.querySelector('[name="pf_id"]');
|
const pfIdInput = form.querySelector('[name="pf_id"]');
|
||||||
if (!pfIdInput || !pfIdInput.value) {
|
if (!pfIdInput || !pfIdInput.value) {
|
||||||
initRevpayTable(null);
|
planInitRevpayTable(null);
|
||||||
initCostTable(null);
|
planInitCostTable(null);
|
||||||
initTaskTable(null);
|
planInitTaskTable(null);
|
||||||
document.querySelector("#planDeleteBtn").classList.add("hidden");
|
document.querySelector("#planDeleteBtn").classList.add("hidden");
|
||||||
}
|
}
|
||||||
modal.classList.remove("hidden");
|
modal.classList.remove("hidden");
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addRevpayRow = (month = '', rev = '', gross = '', payment = '', rev_note = '') => {
|
window.planAddRevpayRow = (month = '', rev = '', gross = '', payment = '', rev_note = '') => {
|
||||||
const tbody = document.querySelector("#revpayTbody");
|
const tbody = document.querySelector("#plan_revpayTbody");
|
||||||
if (!tbody) return;
|
if (!tbody) return;
|
||||||
const row = document.createElement("tr");
|
const row = document.createElement("tr");
|
||||||
row.innerHTML = `<td><select name="budget_month[]" class="form-ctrl form-ctrl-sm w-full" style="min-width:140px" onchange="updateRevpaySummary()">${monthOptions(month)}</select></td>
|
row.innerHTML = `<td><select name="budget_month[]" class="form-ctrl form-ctrl-sm w-full" style="min-width:140px" onchange="planUpdateRevpaySummary()">${monthOptions(month)}</select></td>
|
||||||
<td><input name="budget_rev[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${rev}" oninput="updateRevpaySummary()"></td>
|
<td><input name="budget_rev[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${rev}" oninput="planUpdateRevpaySummary()"></td>
|
||||||
<td><input name="budget_gross[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${gross}" oninput="updateRevpaySummary()"></td>
|
<td><input name="budget_gross[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${gross}" oninput="planUpdateRevpaySummary()"></td>
|
||||||
<td><input name="budget_payment[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${payment}" oninput="updateRevpaySummary()"></td>
|
<td><input name="budget_payment[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${payment}" oninput="planUpdateRevpaySummary()"></td>
|
||||||
<td><input name="budget_rev_note[]" class="form-ctrl form-ctrl-sm w-full" placeholder="备注" value="${rev_note}"></td>
|
<td><input name="budget_rev_note[]" class="form-ctrl form-ctrl-sm w-full" placeholder="备注" value="${rev_note}"></td>
|
||||||
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove();updateRevpaySummary()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove();planUpdateRevpaySummary()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addCostRow = (month = '', expense_type = '', cost = '', paid = '', exp_note = '') => {
|
window.planAddCostRow = (month = '', expense_type = '', cost = '', paid = '', exp_note = '') => {
|
||||||
const tbody = document.querySelector("#costTbody");
|
const tbody = document.querySelector("#plan_costTbody");
|
||||||
if (!tbody) return;
|
if (!tbody) return;
|
||||||
const row = document.createElement("tr");
|
const row = document.createElement("tr");
|
||||||
row.innerHTML = `<td><select name="expense_month[]" class="form-ctrl form-ctrl-sm w-full" style="min-width:140px" onchange="updateCostSummary()">${monthOptions(month)}</select></td>
|
row.innerHTML = `<td><select name="expense_month[]" class="form-ctrl form-ctrl-sm w-full" style="min-width:140px" onchange="planUpdateCostSummary()">${monthOptions(month)}</select></td>
|
||||||
<td><input name="expense_type[]" class="form-ctrl form-ctrl-sm w-full" placeholder="费用类型" value="${expense_type}"></td>
|
<td><input name="expense_type[]" class="form-ctrl form-ctrl-sm w-full" placeholder="费用类型" value="${expense_type}"></td>
|
||||||
<td><input name="expense_cost[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${cost}" oninput="updateCostSummary()"></td>
|
<td><input name="expense_cost[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${cost}" oninput="planUpdateCostSummary()"></td>
|
||||||
<td><input name="expense_paid[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${paid}" oninput="updateCostSummary()"></td>
|
<td><input name="expense_paid[]" type="number" step="0.01" class="form-ctrl form-ctrl-sm w-full text-right" placeholder="0" value="${paid}" oninput="planUpdateCostSummary()"></td>
|
||||||
<td><input name="expense_note[]" class="form-ctrl form-ctrl-sm w-full" placeholder="备注" value="${exp_note}"></td>
|
<td><input name="expense_note[]" class="form-ctrl form-ctrl-sm w-full" placeholder="备注" value="${exp_note}"></td>
|
||||||
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove();updateCostSummary()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove();planUpdateCostSummary()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.updateRevpaySummary = () => {
|
window.planUpdateRevpaySummary = () => {
|
||||||
const revEl = document.querySelector("#revpayTotalRev");
|
const revEl = document.querySelector("#plan_revpayTotalRev");
|
||||||
const grossEl = document.querySelector("#revpayTotalGross");
|
const grossEl = document.querySelector("#plan_revpayTotalGross");
|
||||||
const paymentEl = document.querySelector("#revpayTotalPayment");
|
const paymentEl = document.querySelector("#plan_revpayTotalPayment");
|
||||||
if (!revEl || !paymentEl) return;
|
if (!revEl || !paymentEl) return;
|
||||||
const revInputs = document.querySelectorAll('[name="budget_rev[]"]');
|
const revInputs = document.querySelectorAll('[name="budget_rev[]"]');
|
||||||
const grossInputs = document.querySelectorAll('[name="budget_gross[]"]');
|
const grossInputs = document.querySelectorAll('[name="budget_gross[]"]');
|
||||||
@@ -561,9 +557,9 @@ window.updateRevpaySummary = () => {
|
|||||||
paymentEl.textContent = money(totalPayment);
|
paymentEl.textContent = money(totalPayment);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.updateCostSummary = () => {
|
window.planUpdateCostSummary = () => {
|
||||||
const costEl = document.querySelector("#costTotalCost");
|
const costEl = document.querySelector("#plan_costTotalCost");
|
||||||
const paidEl = document.querySelector("#costTotalPaid");
|
const paidEl = document.querySelector("#plan_costTotalPaid");
|
||||||
if (!costEl || !paidEl) return;
|
if (!costEl || !paidEl) return;
|
||||||
const costInputs = document.querySelectorAll('[name="expense_cost[]"]');
|
const costInputs = document.querySelectorAll('[name="expense_cost[]"]');
|
||||||
const paidInputs = document.querySelectorAll('[name="expense_paid[]"]');
|
const paidInputs = document.querySelectorAll('[name="expense_paid[]"]');
|
||||||
@@ -574,27 +570,27 @@ window.updateCostSummary = () => {
|
|||||||
paidEl.textContent = money(totalPaid);
|
paidEl.textContent = money(totalPaid);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.initRevpayTable = (budgetData) => {
|
window.planInitRevpayTable = (budgetData) => {
|
||||||
const tbody = document.querySelector("#revpayTbody");
|
const tbody = document.querySelector("#plan_revpayTbody");
|
||||||
if (!tbody) return;
|
if (!tbody) return;
|
||||||
tbody.innerHTML = "";
|
tbody.innerHTML = "";
|
||||||
const rows = budgetData || [];
|
const rows = budgetData || [];
|
||||||
rows.forEach(r => addRevpayRow(r.month || '', r.rev || '', r.gross || '', r.payment || '', r.rev_note || ''));
|
rows.forEach(r => planAddRevpayRow(r.month || '', r.rev || '', r.gross || '', r.payment || '', r.rev_note || ''));
|
||||||
setTimeout(() => updateRevpaySummary(), 50);
|
setTimeout(() => planUpdateRevpaySummary(), 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.initCostTable = (expenseData) => {
|
window.planInitCostTable = (expenseData) => {
|
||||||
const tbody = document.querySelector("#costTbody");
|
const tbody = document.querySelector("#plan_costTbody");
|
||||||
if (!tbody) return;
|
if (!tbody) return;
|
||||||
tbody.innerHTML = "";
|
tbody.innerHTML = "";
|
||||||
const rows = expenseData || [];
|
const rows = expenseData || [];
|
||||||
rows.forEach(r => addCostRow(r.month || '', r.expense_type || '', r.cost || '', r.paid || '', r.exp_note || ''));
|
rows.forEach(r => planAddCostRow(r.month || '', r.expense_type || '', r.cost || '', r.paid || '', r.exp_note || ''));
|
||||||
setTimeout(() => updateCostSummary(), 50);
|
setTimeout(() => planUpdateCostSummary(), 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------- 任务管理 tab ----------
|
// ---------- 任务管理 tab ----------
|
||||||
|
|
||||||
function taskMonthOptions(selected) {
|
function planTaskMonthOptions(selected) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const opts = [];
|
const opts = [];
|
||||||
for (let i = -2; i <= 12; i++) {
|
for (let i = -2; i <= 12; i++) {
|
||||||
@@ -605,36 +601,36 @@ function taskMonthOptions(selected) {
|
|||||||
return opts.join("");
|
return opts.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addTaskRow = (taskMonth = '', taskType = '', taskCount = '', executedCount = '', unitPrice = '') => {
|
window.planAddTaskRow = (taskMonth = '', taskType = '', taskCount = '', executedCount = '', unitPrice = '') => {
|
||||||
const tbody = document.querySelector("#taskTbody");
|
const tbody = document.querySelector("#plan_taskTbody");
|
||||||
if (!tbody) return;
|
if (!tbody) return;
|
||||||
const row = document.createElement("tr");
|
const row = document.createElement("tr");
|
||||||
const defaultMonth = (() => { const n = new Date(); return n.getFullYear() + "-" + String(n.getMonth()+1).padStart(2,"0"); })();
|
const defaultMonth = (() => { const n = new Date(); return n.getFullYear() + "-" + String(n.getMonth()+1).padStart(2,"0"); })();
|
||||||
const isPreset = TASK_TYPES.includes(taskType);
|
const isPreset = TASK_TYPES.includes(taskType);
|
||||||
const typeCell = isPreset || !taskType
|
const typeCell = isPreset || !taskType
|
||||||
? `<select name="task_type[]" class="form-ctrl form-ctrl-sm w-full" onchange="onTaskTypeChange(this)"><option value="">选择</option>${TASK_TYPES.map(t => `<option ${t === taskType ? 'selected' : ''}>${t}</option>`).join("")}<option value="__custom__" ${!isPreset && taskType ? 'selected' : ''}>自定义...</option></select>`
|
? `<select name="task_type[]" class="form-ctrl form-ctrl-sm w-full" onchange="planOnTaskTypeChange(this)"><option value="">选择</option>${TASK_TYPES.map(t => `<option ${t === taskType ? 'selected' : ''}>${t}</option>`).join("")}<option value="__custom__" ${!isPreset && taskType ? 'selected' : ''}>自定义...</option></select>`
|
||||||
: `<input name="task_type[]" class="form-ctrl form-ctrl-sm w-full" value="${esc(taskType)}" placeholder="输入自定义类型"><button type="button" class="btn btn-ghost btn-sm text-slate-400 p-0 w-5 h-5 ml-1" onclick="revertTaskType(this)" title="返回选择"><i data-lucide="rotate-ccw" style="width:12px;height:12px"></i></button>`;
|
: `<input name="task_type[]" class="form-ctrl form-ctrl-sm w-full" value="${esc(taskType)}" placeholder="输入自定义类型"><button type="button" class="btn btn-ghost btn-sm text-slate-400 p-0 w-5 h-5 ml-1" onclick="planRevertTaskType(this)" title="返回选择"><i data-lucide="rotate-ccw" style="width:12px;height:12px"></i></button>`;
|
||||||
row.innerHTML = `<td><select name="task_month[]" class="form-ctrl form-ctrl-sm w-full">${taskMonthOptions(taskMonth || defaultMonth)}</select></td>
|
row.innerHTML = `<td><select name="task_month[]" class="form-ctrl form-ctrl-sm w-full">${planTaskMonthOptions(taskMonth || defaultMonth)}</select></td>
|
||||||
<td class="flex items-center">${typeCell}</td>
|
<td class="flex items-center">${typeCell}</td>
|
||||||
<td><input name="task_count[]" type="number" step="1" min="0" class="form-ctrl form-ctrl-sm text-right" style="width:100px" placeholder="0" value="${taskCount}" oninput="updateTaskDiff(this)"></td>
|
<td><input name="task_count[]" type="number" step="1" min="0" class="form-ctrl form-ctrl-sm text-right" style="width:100px" placeholder="0" value="${taskCount}" oninput="planUpdateTaskDiff(this)"></td>
|
||||||
<td><input name="task_executed[]" type="number" step="1" min="0" class="form-ctrl form-ctrl-sm text-right" style="width:100px" placeholder="0" value="${executedCount}" oninput="updateTaskDiff(this)"></td>
|
<td><input name="task_executed[]" type="number" step="1" min="0" class="form-ctrl form-ctrl-sm text-right" style="width:100px" placeholder="0" value="${executedCount}" oninput="planUpdateTaskDiff(this)"></td>
|
||||||
<td><input name="task_diff[]" type="number" class="form-ctrl form-ctrl-sm text-right" style="width:80px" placeholder="—" disabled></td>
|
<td><input name="task_diff[]" type="number" class="form-ctrl form-ctrl-sm text-right" style="width:80px" placeholder="—" disabled></td>
|
||||||
<td><input name="task_unit_price[]" type="number" step="0.01" min="0" class="form-ctrl form-ctrl-sm text-right" style="width:90px" placeholder="0" value="${unitPrice}" oninput="updateTaskDiff(this)"></td>
|
<td><input name="task_unit_price[]" type="number" step="0.01" min="0" class="form-ctrl form-ctrl-sm text-right" style="width:90px" placeholder="0" value="${unitPrice}" oninput="planUpdateTaskDiff(this)"></td>
|
||||||
<td><input name="task_exec_amount[]" type="number" class="form-ctrl form-ctrl-sm text-right" style="width:140px" placeholder="—" disabled></td>
|
<td><input name="task_exec_amount[]" type="number" class="form-ctrl form-ctrl-sm text-right" style="width:140px" placeholder="—" disabled></td>
|
||||||
<td><input name="task_unexec_amount[]" type="number" class="form-ctrl form-ctrl-sm text-right" style="width:140px" placeholder="—" disabled></td>
|
<td><input name="task_unexec_amount[]" type="number" class="form-ctrl form-ctrl-sm text-right" style="width:140px" placeholder="—" disabled></td>
|
||||||
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
<td><button type="button" class="btn btn-ghost btn-sm text-red-500 p-0 w-6 h-6" onclick="this.closest('tr').remove()"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></td>`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
updateRowCalc(row);
|
planUpdateRowCalc(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.updateTaskDiff = (el) => {
|
window.planUpdateTaskDiff = (el) => {
|
||||||
const row = el.closest('tr');
|
const row = el.closest('tr');
|
||||||
if (!row) return;
|
if (!row) return;
|
||||||
updateRowCalc(row);
|
planUpdateRowCalc(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateRowCalc(row) {
|
function planUpdateRowCalc(row) {
|
||||||
const countInput = row.querySelector('[name="task_count[]"]');
|
const countInput = row.querySelector('[name="task_count[]"]');
|
||||||
const execInput = row.querySelector('[name="task_executed[]"]');
|
const execInput = row.querySelector('[name="task_executed[]"]');
|
||||||
const priceInput = row.querySelector('[name="task_unit_price[]"]');
|
const priceInput = row.querySelector('[name="task_unit_price[]"]');
|
||||||
@@ -655,7 +651,7 @@ function updateRowCalc(row) {
|
|||||||
unexecAmtInput.value = unexecAmt ? unexecAmt.toFixed(2) : '';
|
unexecAmtInput.value = unexecAmt ? unexecAmt.toFixed(2) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
window.toggleBtChip = (chip) => {
|
window.planToggleBtChip = (chip) => {
|
||||||
const cb = chip.querySelector('input');
|
const cb = chip.querySelector('input');
|
||||||
cb.checked = !cb.checked;
|
cb.checked = !cb.checked;
|
||||||
chip.classList.toggle('bg-blue-50', cb.checked);
|
chip.classList.toggle('bg-blue-50', cb.checked);
|
||||||
@@ -663,35 +659,35 @@ window.toggleBtChip = (chip) => {
|
|||||||
chip.classList.toggle('text-blue-600', cb.checked);
|
chip.classList.toggle('text-blue-600', cb.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.initTaskTable = (taskData) => {
|
window.planInitTaskTable = (taskData) => {
|
||||||
const tbody = document.querySelector("#taskTbody");
|
const tbody = document.querySelector("#plan_taskTbody");
|
||||||
if (!tbody) return;
|
if (!tbody) return;
|
||||||
tbody.innerHTML = "";
|
tbody.innerHTML = "";
|
||||||
const rows = taskData || [];
|
const rows = taskData || [];
|
||||||
rows.forEach(r => addTaskRow(r.task_month || '', r.task_type || '', r.task_count || '', r.task_executed || '', r.unit_price || ''));
|
rows.forEach(r => planAddTaskRow(r.task_month || '', r.task_type || '', r.task_count || '', r.task_executed || '', r.unit_price || ''));
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onTaskTypeChange = (sel) => {
|
window.planOnTaskTypeChange = (sel) => {
|
||||||
if (sel.value !== '__custom__') return;
|
if (sel.value !== '__custom__') return;
|
||||||
const td = sel.parentElement;
|
const td = sel.parentElement;
|
||||||
const oldVal = sel.value;
|
const oldVal = sel.value;
|
||||||
td.innerHTML = `<input name="task_type[]" class="form-ctrl form-ctrl-sm w-full" placeholder="输入自定义类型" autofocus><button type="button" class="btn btn-ghost btn-sm text-slate-400 p-0 w-5 h-5 ml-1" onclick="revertTaskType(this)" title="返回选择"><i data-lucide="rotate-ccw" style="width:12px;height:12px"></i></button>`;
|
td.innerHTML = `<input name="task_type[]" class="form-ctrl form-ctrl-sm w-full" placeholder="输入自定义类型" autofocus><button type="button" class="btn btn-ghost btn-sm text-slate-400 p-0 w-5 h-5 ml-1" onclick="planRevertTaskType(this)" title="返回选择"><i data-lucide="rotate-ccw" style="width:12px;height:12px"></i></button>`;
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
td.querySelector('input').focus();
|
td.querySelector('input').focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.revertTaskType = (btn) => {
|
window.planRevertTaskType = (btn) => {
|
||||||
const td = btn.parentElement;
|
const td = btn.parentElement;
|
||||||
td.innerHTML = `<select name="task_type[]" class="form-ctrl form-ctrl-sm w-full" onchange="onTaskTypeChange(this)"><option value="">选择</option>${TASK_TYPES.map(t => `<option>${t}</option>`).join("")}<option value="__custom__">自定义...</option></select>`;
|
td.innerHTML = `<select name="task_type[]" class="form-ctrl form-ctrl-sm w-full" onchange="planOnTaskTypeChange(this)"><option value="">选择</option>${TASK_TYPES.map(t => `<option>${t}</option>`).join("")}<option value="__custom__">自定义...</option></select>`;
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.closePlanModal = () => {
|
window.closePlanModal = () => {
|
||||||
const modal = document.querySelector("#planModal");
|
const modal = document.querySelector("#planModal");
|
||||||
modal.classList.add("hidden");
|
if (modal) modal.classList.add("hidden");
|
||||||
};
|
};
|
||||||
|
|
||||||
window.editPfSignMonth = (event, pfId) => {
|
window.planEditSignMonth = (event, pfId) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const pf = (state.data.planFinances || []).find(x => x.id === pfId);
|
const pf = (state.data.planFinances || []).find(x => x.id === pfId);
|
||||||
if (!pf) return;
|
if (!pf) return;
|
||||||
@@ -707,11 +703,11 @@ window.editPfSignMonth = (event, pfId) => {
|
|||||||
try {
|
try {
|
||||||
await api(`/api/planFinances/${pfId}`, { method: "PUT", body: JSON.stringify({ data: { sign_month: newValue } }) });
|
await api(`/api/planFinances/${pfId}`, { method: "PUT", body: JSON.stringify({ data: { sign_month: newValue } }) });
|
||||||
pf.sign_month = newValue;
|
pf.sign_month = newValue;
|
||||||
td.innerHTML = `<span class="pf-sm-text cursor-pointer hover:text-blue-600" onclick="editPfSignMonth(event, ${pfId})">${newValue || '—'}</span>`;
|
td.innerHTML = `<span class="pf-sm-text cursor-pointer hover:text-blue-600" onclick="planEditSignMonth(event, ${pfId})">${newValue || '—'}</span>`;
|
||||||
} catch (e) { toast("修改失败:" + e.message, "error"); }
|
} catch (e) { toast("修改失败:" + e.message, "error"); }
|
||||||
});
|
});
|
||||||
select.addEventListener("blur", () => {
|
select.addEventListener("blur", () => {
|
||||||
td.innerHTML = `<span class="pf-sm-text cursor-pointer hover:text-blue-600" onclick="editPfSignMonth(event, ${pfId})">${currentValue || '—'}</span>`;
|
td.innerHTML = `<span class="pf-sm-text cursor-pointer hover:text-blue-600" onclick="planEditSignMonth(event, ${pfId})">${currentValue || '—'}</span>`;
|
||||||
});
|
});
|
||||||
td.innerHTML = "";
|
td.innerHTML = "";
|
||||||
td.appendChild(select);
|
td.appendChild(select);
|
||||||
@@ -720,25 +716,25 @@ window.editPfSignMonth = (event, pfId) => {
|
|||||||
|
|
||||||
window.switchPlanTab = (tab) => {
|
window.switchPlanTab = (tab) => {
|
||||||
document.querySelectorAll(".plan-tab").forEach(b => b.classList.toggle("active", b.dataset.tab === tab));
|
document.querySelectorAll(".plan-tab").forEach(b => b.classList.toggle("active", b.dataset.tab === tab));
|
||||||
document.querySelector("#financeTabInfo").classList.toggle("hidden", tab !== "info");
|
document.querySelector("#plan_financeTabInfo").classList.toggle("hidden", tab !== "info");
|
||||||
document.querySelector("#financeTabRevpay").classList.toggle("hidden", tab !== "revpay");
|
document.querySelector("#plan_financeTabRevpay").classList.toggle("hidden", tab !== "revpay");
|
||||||
document.querySelector("#financeTabCost").classList.toggle("hidden", tab !== "cost");
|
document.querySelector("#plan_financeTabCost").classList.toggle("hidden", tab !== "cost");
|
||||||
document.querySelector("#financeTabExec").classList.toggle("hidden", tab !== "exec");
|
document.querySelector("#plan_financeTabExec").classList.toggle("hidden", tab !== "exec");
|
||||||
document.querySelector("#financeTabTasks").classList.toggle("hidden", tab !== "tasks");
|
document.querySelector("#plan_financeTabTasks").classList.toggle("hidden", tab !== "tasks");
|
||||||
document.querySelector("#financeTabActivity").classList.toggle("hidden", tab !== "activity");
|
document.querySelector("#plan_financeTabActivity").classList.toggle("hidden", tab !== "activity");
|
||||||
document.querySelector(".plan-form-actions").classList.toggle("hidden", tab === "activity");
|
document.querySelector(".plan-form-actions").classList.toggle("hidden", tab === "activity");
|
||||||
if (tab === "activity") initFinSquire();
|
if (tab === "activity") planInitSquire();
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------- 活动与跟进 ----------
|
// ---------- 活动与跟进 ----------
|
||||||
|
|
||||||
async function loadFinFollowups(pfId) {
|
async function planLoadFollowups(pfId) {
|
||||||
const list = document.querySelector("#finActivityList");
|
const list = document.querySelector("#plan_finActivityList");
|
||||||
if (!list || !pfId) return;
|
if (!list || !pfId) return;
|
||||||
try {
|
try {
|
||||||
const fups = await api(`/api/followups/project_finance/${pfId}`);
|
const fups = await api(`/api/followups/project_finance/${pfId}`);
|
||||||
list.innerHTML = fups.length
|
list.innerHTML = fups.length
|
||||||
? fups.map(f => `<div class="activity-item"><div class="activity-icon"><i data-lucide="message-square"></i></div><div class="min-w-0 flex-1"><div class="flex justify-between gap-3 text-[12px] text-slate-500"><span>${esc(f.follower)} · ${esc(f.follow_up_method)}</span><span>${esc(f.followed_at)}</span></div><div class="mt-1 leading-5 text-slate-800 rich-content" data-html="${encodeURIComponent(f.content || '')}"></div>${f.next_action ? `<p class="mt-1 leading-5 text-blue-700">下一步:${text(f.next_action)}</p>` : ""}</div><button class="activity-delete" type="button" onclick="deleteFinFollowup(event, ${f.id})" title="删除评论"><i data-lucide="trash-2"></i></button></div>`).join("")
|
? fups.map(f => `<div class="activity-item"><div class="activity-icon"><i data-lucide="message-square"></i></div><div class="min-w-0 flex-1"><div class="flex justify-between gap-3 text-[12px] text-slate-500"><span>${esc(f.follower)} · ${esc(f.follow_up_method)}</span><span>${esc(f.followed_at)}</span></div><div class="mt-1 leading-5 text-slate-800 rich-content" data-html="${encodeURIComponent(f.content || '')}"></div>${f.next_action ? `<p class="mt-1 leading-5 text-blue-700">下一步:${text(f.next_action)}</p>` : ""}</div><button class="activity-delete" type="button" onclick="planDeleteFollowup(event, ${f.id})" title="删除评论"><i data-lucide="trash-2"></i></button></div>`).join("")
|
||||||
: '<p class="text-sm text-slate-400 py-4 text-center">暂无跟进记录</p>';
|
: '<p class="text-sm text-slate-400 py-4 text-center">暂无跟进记录</p>';
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
list.querySelectorAll(".rich-content").forEach(el => {
|
list.querySelectorAll(".rich-content").forEach(el => {
|
||||||
@@ -748,8 +744,8 @@ async function loadFinFollowups(pfId) {
|
|||||||
} catch (e) { /* ignore */ }
|
} catch (e) { /* ignore */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
function initFinSquire() {
|
function planInitSquire() {
|
||||||
const ed = document.querySelector("#squire_finance");
|
const ed = document.querySelector("#plan_squire_finance");
|
||||||
if (!ed || !window.Squire) return;
|
if (!ed || !window.Squire) return;
|
||||||
if (window.squireInstances["squire_finance"]) { window.squireInstances["squire_finance"].destroy(); }
|
if (window.squireInstances["squire_finance"]) { window.squireInstances["squire_finance"].destroy(); }
|
||||||
const sq = new Squire(ed, { blockTag: "P" });
|
const sq = new Squire(ed, { blockTag: "P" });
|
||||||
@@ -758,8 +754,8 @@ function initFinSquire() {
|
|||||||
ed.addEventListener("blur", () => { if (!ed.textContent.trim()) ed.classList.remove("focused"); });
|
ed.addEventListener("blur", () => { if (!ed.textContent.trim()) ed.classList.remove("focused"); });
|
||||||
}
|
}
|
||||||
|
|
||||||
window.submitFinComment = async () => {
|
window.planSubmitComment = async () => {
|
||||||
const pfId = document.querySelector("#pf-id-input").value;
|
const pfId = document.querySelector("#plan_pf-id-input").value;
|
||||||
if (!pfId) return;
|
if (!pfId) return;
|
||||||
const sq = window.squireInstances["squire_finance"];
|
const sq = window.squireInstances["squire_finance"];
|
||||||
const content = sq ? sq.getHTML().trim() : "";
|
const content = sq ? sq.getHTML().trim() : "";
|
||||||
@@ -771,22 +767,22 @@ window.submitFinComment = async () => {
|
|||||||
sq.setHTML("");
|
sq.setHTML("");
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.textContent = "评论";
|
btn.textContent = "评论";
|
||||||
await loadFinFollowups(pfId);
|
await planLoadFollowups(pfId);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.deleteFinFollowup = async (event, followupId) => {
|
window.planDeleteFollowup = async (event, followupId) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (!confirm("确认删除这条评论?")) return;
|
if (!confirm("确认删除这条评论?")) return;
|
||||||
await api(`/api/followups/${followupId}`, { method: "DELETE" });
|
await api(`/api/followups/${followupId}`, { method: "DELETE" });
|
||||||
const pfId = document.querySelector("#pf-id-input").value;
|
const pfId = document.querySelector("#plan_pf-id-input").value;
|
||||||
if (pfId) await loadFinFollowups(pfId);
|
if (pfId) await planLoadFollowups(pfId);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.openPfEditModal = (pfId) => {
|
window.planOpenPfEditModal = (pfId) => {
|
||||||
const pf = (state.data.planFinances || []).find(x => x.id === pfId);
|
const pf = (state.data.planFinances || []).find(x => x.id === pfId);
|
||||||
if (!pf) return;
|
if (!pf) return;
|
||||||
document.querySelector("#pf-id-input").value = pf.id;
|
document.querySelector("#plan_pf-id-input").value = pf.id;
|
||||||
document.querySelector("#financeModalTitle").textContent = "编辑项目财务";
|
document.querySelector("#planModalTitle").textContent = "编辑项目财务";
|
||||||
document.querySelector("#planDeleteBtn").classList.remove("hidden");
|
document.querySelector("#planDeleteBtn").classList.remove("hidden");
|
||||||
const form = document.querySelector("#financeModal form");
|
const form = document.querySelector("#financeModal form");
|
||||||
form.querySelector('[name="project_id"]').value = pf.project_id || "";
|
form.querySelector('[name="project_id"]').value = pf.project_id || "";
|
||||||
@@ -813,7 +809,6 @@ window.openPfEditModal = (pfId) => {
|
|||||||
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
||||||
signMonthEl.value = signMonthValue;
|
signMonthEl.value = signMonthValue;
|
||||||
}
|
}
|
||||||
form.querySelector('[name="status"]').value = pf.status || "待签约";
|
|
||||||
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
||||||
form.querySelector('[name="owner"]').value = pf.owner || "";
|
form.querySelector('[name="owner"]').value = pf.owner || "";
|
||||||
setVal("start_date", pf.start_date);
|
setVal("start_date", pf.start_date);
|
||||||
@@ -827,15 +822,15 @@ window.openPfEditModal = (pfId) => {
|
|||||||
setVal("other_info", pf.other_info);
|
setVal("other_info", pf.other_info);
|
||||||
let budgetData = [];
|
let budgetData = [];
|
||||||
try { budgetData = JSON.parse(pf.budget_data || "[]"); } catch (e) { budgetData = []; }
|
try { budgetData = JSON.parse(pf.budget_data || "[]"); } catch (e) { budgetData = []; }
|
||||||
initRevpayTable(budgetData.length ? budgetData : null);
|
planInitRevpayTable(budgetData.length ? budgetData : null);
|
||||||
let expenseData = [];
|
let expenseData = [];
|
||||||
try { expenseData = JSON.parse(pf.expense_data || "[]"); } catch (e) { expenseData = []; }
|
try { expenseData = JSON.parse(pf.expense_data || "[]"); } catch (e) { expenseData = []; }
|
||||||
initCostTable(expenseData.length ? expenseData : null);
|
planInitCostTable(expenseData.length ? expenseData : null);
|
||||||
let taskData = [];
|
let taskData = [];
|
||||||
try { taskData = JSON.parse(pf.task_data || "[]"); } catch (e) { taskData = []; }
|
try { taskData = JSON.parse(pf.task_data || "[]"); } catch (e) { taskData = []; }
|
||||||
initTaskTable(taskData.length ? taskData : null);
|
planInitTaskTable(taskData.length ? taskData : null);
|
||||||
setTimeout(() => updateBudgetSummary(), 100);
|
setTimeout(() => updateBudgetSummary(), 100);
|
||||||
loadFinFollowups(pf.id);
|
planLoadFollowups(pf.id);
|
||||||
openPlanModal();
|
openPlanModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -936,8 +931,8 @@ window.createPlanFinance = async (event) => {
|
|||||||
if (result.id && data.customer_name) logActivity("finance", result.id, "创建了「" + data.customer_name + "」的财务项目");
|
if (result.id && data.customer_name) logActivity("finance", result.id, "创建了「" + data.customer_name + "」的财务项目");
|
||||||
}
|
}
|
||||||
form.reset();
|
form.reset();
|
||||||
document.querySelector("#pf-id-input").value = "";
|
document.querySelector("#plan_pf-id-input").value = "";
|
||||||
document.querySelector("#financeModalTitle").textContent = "新增项目财务";
|
document.querySelector("#planModalTitle").textContent = "新增项目财务";
|
||||||
closePlanModal();
|
closePlanModal();
|
||||||
await load();
|
await load();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -946,7 +941,7 @@ window.createPlanFinance = async (event) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.deletePlanItem = async () => {
|
window.deletePlanItem = async () => {
|
||||||
const pfId = document.querySelector("#pf-id-input").value;
|
const pfId = document.querySelector("#plan_pf-id-input").value;
|
||||||
if (!pfId) return;
|
if (!pfId) return;
|
||||||
const pf = (state.data.planFinances || []).find(x => x.id === parseInt(pfId));
|
const pf = (state.data.planFinances || []).find(x => x.id === parseInt(pfId));
|
||||||
const name = pf ? (pf.customer_name || "此项目") : "此项目";
|
const name = pf ? (pf.customer_name || "此项目") : "此项目";
|
||||||
@@ -1020,7 +1015,7 @@ function renderPlanOverview() {
|
|||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
// 渲染图表(复用 home.js 的 moneyTick / chartOptions / monthLabels)
|
// 渲染图表(复用 home.js 的 moneyTick / chartOptions / monthLabels)
|
||||||
if (financeMonthly && window.Chart) {
|
if (financeMonthly && window.Chart) {
|
||||||
renderOverviewCharts(financeMonthly);
|
renderPlanCharts(financeMonthly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1030,22 +1025,22 @@ function renderPlanCharts(data) {
|
|||||||
const baseOpts = typeof chartOptions === 'function' ? chartOptions(moneyTick) : { responsive: true, maintainAspectRatio: false };
|
const baseOpts = typeof chartOptions === 'function' ? chartOptions(moneyTick) : { responsive: true, maintainAspectRatio: false };
|
||||||
var iconf = { type: "line", options: baseOpts, data: { labels: labels } };
|
var iconf = { type: "line", options: baseOpts, data: { labels: labels } };
|
||||||
|
|
||||||
var c1 = document.querySelector("#finChartSign");
|
var c1 = document.querySelector("#planChartSign");
|
||||||
if (c1 && window.Chart) {
|
if (c1 && window.Chart) {
|
||||||
if (state.planChart1) state.planChart1.destroy();
|
if (state.planChart1) state.planChart1.destroy();
|
||||||
state.planChart1 = new Chart(c1, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "签约金额", data: data.map(function(x) { return x.sign || 0; }), borderColor: "#6366f1", backgroundColor: "rgba(99,102,241,0.06)", fill: true, tension: 0.3 }] } }));
|
state.planChart1 = new Chart(c1, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "签约金额", data: data.map(function(x) { return x.sign || 0; }), borderColor: "#6366f1", backgroundColor: "rgba(99,102,241,0.06)", fill: true, tension: 0.3 }] } }));
|
||||||
}
|
}
|
||||||
var c2 = document.querySelector("#finChartRev");
|
var c2 = document.querySelector("#planChartRev");
|
||||||
if (c2 && window.Chart) {
|
if (c2 && window.Chart) {
|
||||||
if (state.planChart2) state.planChart2.destroy();
|
if (state.planChart2) state.planChart2.destroy();
|
||||||
state.planChart2 = new Chart(c2, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "确收", data: data.map(function(x) { return x.revenue || 0; }), borderColor: "#2563eb", backgroundColor: "rgba(37,99,235,0.06)", fill: true, tension: 0.3 }, { label: "毛利", data: data.map(function(x) { return x.gross || 0; }), borderColor: "#059669", backgroundColor: "rgba(5,150,105,0.06)", fill: true, tension: 0.3 }] } }));
|
state.planChart2 = new Chart(c2, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "确收", data: data.map(function(x) { return x.revenue || 0; }), borderColor: "#2563eb", backgroundColor: "rgba(37,99,235,0.06)", fill: true, tension: 0.3 }, { label: "毛利", data: data.map(function(x) { return x.gross || 0; }), borderColor: "#059669", backgroundColor: "rgba(5,150,105,0.06)", fill: true, tension: 0.3 }] } }));
|
||||||
}
|
}
|
||||||
var c3 = document.querySelector("#finChartCash");
|
var c3 = document.querySelector("#planChartCash");
|
||||||
if (c3 && window.Chart) {
|
if (c3 && window.Chart) {
|
||||||
if (state.planChart3) state.planChart3.destroy();
|
if (state.planChart3) state.planChart3.destroy();
|
||||||
state.planChart3 = new Chart(c3, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "回款", data: data.map(function(x) { return x.payment || 0; }), borderColor: "#d97706", backgroundColor: "rgba(217,119,6,0.06)", fill: true, tension: 0.3 }, { label: "已付", data: data.map(function(x) { return x.cost || 0; }), borderColor: "#7c3aed", backgroundColor: "rgba(124,58,237,0.06)", fill: true, tension: 0.3 }] } }));
|
state.planChart3 = new Chart(c3, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "回款", data: data.map(function(x) { return x.payment || 0; }), borderColor: "#d97706", backgroundColor: "rgba(217,119,6,0.06)", fill: true, tension: 0.3 }, { label: "已付", data: data.map(function(x) { return x.cost || 0; }), borderColor: "#7c3aed", backgroundColor: "rgba(124,58,237,0.06)", fill: true, tension: 0.3 }] } }));
|
||||||
}
|
}
|
||||||
var c4 = document.querySelector("#finChartProfit");
|
var c4 = document.querySelector("#planChartProfit");
|
||||||
if (c4 && window.Chart) {
|
if (c4 && window.Chart) {
|
||||||
if (state.planChart4) state.planChart4.destroy();
|
if (state.planChart4) state.planChart4.destroy();
|
||||||
state.planChart4 = new Chart(c4, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "利润", data: data.map(function(x) { return x.gross || 0; }), borderColor: "#6366f1", backgroundColor: "rgba(99,102,241,0.06)", fill: true, tension: 0.3 }] } }));
|
state.planChart4 = new Chart(c4, Object.assign({}, iconf, { data: { labels: labels, datasets: [{ label: "利润", data: data.map(function(x) { return x.gross || 0; }), borderColor: "#6366f1", backgroundColor: "rgba(99,102,241,0.06)", fill: true, tension: 0.3 }] } }));
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ const state = {
|
|||||||
data: null,
|
data: null,
|
||||||
tenant: "科普·无界",
|
tenant: "科普·无界",
|
||||||
opFilter: "all",
|
opFilter: "all",
|
||||||
finFilter: "已签约",
|
finFilter: "projects",
|
||||||
selectedProject: null,
|
selectedProject: null,
|
||||||
taskQuery: "",
|
taskQuery: "",
|
||||||
taskView: localStorage.getItem("opc-task-view") || "detail",
|
taskView: localStorage.getItem("opc-task-view") || "detail",
|
||||||
finView: "overview",
|
finView: "overview",
|
||||||
finSort: null, // { key: 'col', asc: true }
|
finSort: null, // { key: 'col', asc: true }
|
||||||
planFilter: "已签约",
|
planFilter: "projects",
|
||||||
planView: "overview",
|
planView: "overview",
|
||||||
planSort: null,
|
planSort: null,
|
||||||
proposalTab: "standard",
|
proposalTab: "standard",
|
||||||
@@ -136,7 +136,7 @@ function switchTab(tab) {
|
|||||||
document.querySelectorAll(".panel").forEach((panel) => panel.classList.toggle("active", panel.id === tab));
|
document.querySelectorAll(".panel").forEach((panel) => panel.classList.toggle("active", panel.id === tab));
|
||||||
|
|
||||||
// 更新顶部标题
|
// 更新顶部标题
|
||||||
const titles = { home: 'OPC 工作台', finance: '业务管理', plan: '计划管理', projects: '重点工作台账', proposals: '业务方案', products: '版本与运营', performance: '季度绩效考核' };
|
const titles = { home: 'OPC 工作台', finance: '实际管理', plan: '计划管理', projects: '重点工作台账', proposals: '业务方案', products: '版本与运营', performance: '季度绩效考核' };
|
||||||
const titleEl = document.querySelector('#workspaceTitle');
|
const titleEl = document.querySelector('#workspaceTitle');
|
||||||
if (titleEl) titleEl.textContent = titles[tab] || state.tenant + ' OPC 工作台';
|
if (titleEl) titleEl.textContent = titles[tab] || state.tenant + ' OPC 工作台';
|
||||||
|
|
||||||
@@ -204,6 +204,8 @@ window.setFinView = (view) => {
|
|||||||
state.finView = view;
|
state.finView = view;
|
||||||
renderFinance();
|
renderFinance();
|
||||||
};
|
};
|
||||||
|
window.setFinQuarter = (q) => { state.finQuarter = q; state.finView = 'quarterly'; renderFinance(); };
|
||||||
|
window.setFinMonth = (month) => { state.finMonth = month; state.finView = 'monthly'; renderFinance(); };
|
||||||
window.switchFinFilter = (filter) => {
|
window.switchFinFilter = (filter) => {
|
||||||
state.finFilter = filter;
|
state.finFilter = filter;
|
||||||
state.finSort = null;
|
state.finSort = null;
|
||||||
@@ -220,6 +222,8 @@ window.setPlanView = (view) => {
|
|||||||
state.planView = view;
|
state.planView = view;
|
||||||
renderPlan();
|
renderPlan();
|
||||||
};
|
};
|
||||||
|
window.setPlanQuarter = (q) => { state.planQuarter = q; state.planView = 'quarterly'; renderPlan(); };
|
||||||
|
window.setPlanMonth = (month) => { state.planMonth = month; state.planView = 'monthly'; renderPlan(); };
|
||||||
window.switchPlanFilter = (filter) => {
|
window.switchPlanFilter = (filter) => {
|
||||||
state.planFilter = filter;
|
state.planFilter = filter;
|
||||||
state.planSort = null;
|
state.planSort = null;
|
||||||
|
|||||||
@@ -96,26 +96,26 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 详情弹窗固定高度,tab 切换不抖动 */
|
/* 详情弹窗固定高度,tab 切换不抖动 */
|
||||||
#financeModal > div {
|
#financeModal > div, #planModal > div {
|
||||||
height: 650px;
|
height: 650px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
#financeModal .finance-tabs { flex-shrink: 0; }
|
#financeModal .finance-tabs, #planModal .finance-tabs { flex-shrink: 0; }
|
||||||
#financeModal form {
|
#financeModal form, #planModal form {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
#financeModal .finance-tab-body {
|
#financeModal .finance-tab-body, #planModal .finance-tab-body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 32px;
|
padding: 32px;
|
||||||
}
|
}
|
||||||
#financeModal .finance-form-actions {
|
#financeModal .finance-form-actions, #planModal .finance-form-actions {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
padding: 12px 32px 8px;
|
padding: 12px 32px 8px;
|
||||||
|
|||||||
@@ -53,9 +53,9 @@
|
|||||||
<i data-lucide="calendar-range" style="width:20px;height:20px"></i>
|
<i data-lucide="calendar-range" style="width:20px;height:20px"></i>
|
||||||
<span class="text-[10px] mt-1">计划</span>
|
<span class="text-[10px] mt-1">计划</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar-tab" data-tab="finance" onclick="switchTab('finance')" title="业务">
|
<div class="sidebar-tab" data-tab="finance" onclick="switchTab('finance')" title="实际">
|
||||||
<i data-lucide="folder-open-dot" style="width:20px;height:20px"></i>
|
<i data-lucide="folder-open-dot" style="width:20px;height:20px"></i>
|
||||||
<span class="text-[10px] mt-1">业务</span>
|
<span class="text-[10px] mt-1">实际</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar-tab" data-tab="projects" onclick="switchTab('projects')" title="Focus">
|
<div class="sidebar-tab" data-tab="projects" onclick="switchTab('projects')" title="Focus">
|
||||||
<i data-lucide="file-text" style="width:20px;height:20px"></i>
|
<i data-lucide="file-text" style="width:20px;height:20px"></i>
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
<header class="topbar border-b border-slate-200 bg-white px-8 py-5">
|
<header class="topbar border-b border-slate-200 bg-white px-8 py-5">
|
||||||
<div class="flex items-center gap-3 w-full">
|
<div class="flex items-center gap-3 w-full">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<p class="eyebrow text-xs font-semibold uppercase tracking-[0.18em] text-blue-700">OPC Manager <span class="ml-2 text-xs font-normal text-slate-400 tracking-normal">v1.0.0.17</span></p>
|
<p class="eyebrow text-xs font-semibold uppercase tracking-[0.18em] text-blue-700">OPC Manager <span class="ml-2 text-xs font-normal text-slate-400 tracking-normal">v1.0.0.24</span></p>
|
||||||
<div class="flex items-center gap-4 mt-1">
|
<div class="flex items-center gap-4 mt-1">
|
||||||
<h1 class="text-2xl font-semibold" id="workspaceTitle">科普 OPC 工作台</h1>
|
<h1 class="text-2xl font-semibold" id="workspaceTitle">科普 OPC 工作台</h1>
|
||||||
<div class="hidden sm:flex items-center gap-1.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-100 rounded-full px-4 py-1.5">
|
<div class="hidden sm:flex items-center gap-1.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-100 rounded-full px-4 py-1.5">
|
||||||
|
|||||||
Reference in New Issue
Block a user