Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e21d41b218 |
@@ -65,7 +65,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
||||
_year = date.today().year
|
||||
months = [f"{_year}-{m:02d}" for m in range(1, 13)]
|
||||
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])
|
||||
|
||||
parsed_budgets = []
|
||||
@@ -104,7 +104,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
||||
key = month.replace("-", "_")
|
||||
revenue = gross = payment = cost = paid = sign = 0
|
||||
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)
|
||||
b = budget_map.get(key)
|
||||
if b:
|
||||
|
||||
@@ -17,7 +17,7 @@ def run_migrations():
|
||||
"""
|
||||
from migrations.tables import migrate_create_tables
|
||||
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.seed import migrate_seed_users, migrate_seed_demo_data
|
||||
|
||||
@@ -28,7 +28,6 @@ def run_migrations():
|
||||
migrate_drop_product_fields()
|
||||
migrate_fix_service_fee_standard()
|
||||
migrate_fix_expense_status()
|
||||
migrate_move_pending_to_plan()
|
||||
migrate_data_split()
|
||||
migrate_seed_users()
|
||||
migrate_seed_demo_data()
|
||||
|
||||
@@ -122,6 +122,12 @@ def migrate_add_columns():
|
||||
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:
|
||||
conn.close()
|
||||
|
||||
@@ -114,34 +114,3 @@ def migrate_fix_expense_status():
|
||||
conn.close()
|
||||
|
||||
|
||||
def migrate_move_pending_to_plan():
|
||||
"""迁移业务待签约项目到计划模块(幂等)"""
|
||||
from db import db
|
||||
|
||||
conn = db()
|
||||
try:
|
||||
cur = conn.cursor()
|
||||
# 获取 plan_finances 的列名(排除 status,因计划模块已删除该列)
|
||||
cur.execute("SHOW COLUMNS FROM plan_finances")
|
||||
plan_cols = [row[0] for row in cur.fetchall()]
|
||||
col_list = ", ".join(plan_cols)
|
||||
|
||||
# 仅迁移 id 不存在于计划表的待签约项目
|
||||
cur.execute(
|
||||
f"INSERT INTO plan_finances ({col_list}) "
|
||||
f"SELECT {col_list} FROM project_finances WHERE status='待签约' "
|
||||
f"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个月的预算数据"""
|
||||
months = []
|
||||
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)
|
||||
payment_rate = random.uniform(0.7, 0.95)
|
||||
|
||||
@@ -135,17 +135,17 @@ def seed_db():
|
||||
cust_idx += i % 3
|
||||
|
||||
# 70% 已签约, 30% 待签约
|
||||
status = "已签约" if random.random() < 0.7 else "待签约"
|
||||
sign_month = f"2026-{random.randint(1, 6):02d}" if status == "已签约" else ""
|
||||
status = "已签约"
|
||||
sign_month = f"2026-{random.randint(1, 6):02d}"
|
||||
project_code = f"{tenant[:2]}-2026-{i+1:03d}"
|
||||
business_type = random.choice(["学术推广", "医生教育", "患者管理", "科研合作", "科普内容"])
|
||||
|
||||
# 如果签约,总额 = 签约额;否则为0
|
||||
total_rev = int(sign_amount * random.uniform(0.8, 1.0)) if status == "已签约" else 0
|
||||
total_gross = int(total_rev * random.uniform(0.25, 0.5)) if status == "已签约" else 0
|
||||
total_payment = int(total_rev * random.uniform(0.7, 0.9)) if status == "已签约" else 0
|
||||
total_cost = int(total_rev * random.uniform(0.3, 0.5)) if status == "已签约" else 0
|
||||
total_paid = int(total_cost * random.uniform(0.7, 0.95)) 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))
|
||||
total_payment = int(total_rev * random.uniform(0.7, 0.9))
|
||||
total_cost = int(total_rev * random.uniform(0.3, 0.5))
|
||||
total_paid = int(total_cost * random.uniform(0.7, 0.95))
|
||||
|
||||
budget_data = make_budget_data(sign_amount, sign_month, status)
|
||||
expense_data = make_expense_data() if status == "已签约" else "[]"
|
||||
@@ -157,16 +157,16 @@ def seed_db():
|
||||
|
||||
cur = _exec(conn, """
|
||||
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,
|
||||
budget_data, expense_data, task_data,
|
||||
project_code, start_date, end_date, task_type, task_count,
|
||||
service_fee_standard, project_manager, contact_name, contact_phone, other_info,
|
||||
created_at, updated_at)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
""", (
|
||||
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,
|
||||
total_payment, total_cost, total_paid,
|
||||
budget_data, expense_data, task_data,
|
||||
@@ -178,7 +178,7 @@ def seed_db():
|
||||
today, today,
|
||||
))
|
||||
# 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 个
|
||||
op_count = random.randint(3, 5)
|
||||
|
||||
@@ -23,7 +23,7 @@ TABLES = {
|
||||
"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"]),
|
||||
"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"]),
|
||||
"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"]),
|
||||
@@ -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_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_signed_pfs = [x for x in t_pfs if x["status"] == "已签约"]
|
||||
t_signed_pfs = t_pfs
|
||||
def t_parse_budget(pf):
|
||||
try:
|
||||
budget = json.loads(pf.get("budget_data") or "[]")
|
||||
@@ -326,12 +326,12 @@ def bootstrap():
|
||||
"total_proposals": len(t_ops),
|
||||
"total_products": len(t_proposals),
|
||||
"upcoming_products": len(t_products),
|
||||
"signed_amount": 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 if x["status"] == "已签约"),
|
||||
"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_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_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_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_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),
|
||||
"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.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.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.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_q2": t_sum_budget("rev", _q_range),
|
||||
"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)
|
||||
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)
|
||||
signed_pfs = [x for x in pfs if x["status"] == "已签约"]
|
||||
signed_pfs = pfs
|
||||
|
||||
def parse_budget(pf):
|
||||
try:
|
||||
@@ -563,16 +563,14 @@ def bootstrap():
|
||||
profit_month = gross_month - proj_expense_month
|
||||
profit_prev_q = gross_prev_q - proj_expense_prev_q
|
||||
profit_prev_month = gross_prev_month - proj_expense_prev_month
|
||||
def pf_status_sum(status):
|
||||
return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status)
|
||||
signed_amount = pf_status_sum("已签约")
|
||||
signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约")
|
||||
signed_amount = sum(x["sign_amount"] or 0 for x in pfs)
|
||||
signed_annual = sum(x["sign_amount"] or 0 for x in pfs)
|
||||
_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_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_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.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}")
|
||||
_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_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_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.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 ["已签约","已丢单","已归档","已完成"])
|
||||
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 = {
|
||||
|
||||
@@ -24,8 +24,8 @@ function renderFinance() {
|
||||
const months = displayMonths.map(d => d.key);
|
||||
const monthLabels = displayMonths.map(d => d.label);
|
||||
|
||||
const signed = pfs.filter(x => x.status === "已签约");
|
||||
const pending = pfs.filter(x => x.status === "待签约");
|
||||
const signed = pfs;
|
||||
const pending = pfs;
|
||||
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));
|
||||
|
||||
@@ -116,7 +116,7 @@ function renderFinance() {
|
||||
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 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('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">
|
||||
${finFilterTabs}
|
||||
@@ -142,7 +142,7 @@ function renderFinance() {
|
||||
<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><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></select></label>
|
||||
|
||||
</div>
|
||||
<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>
|
||||
@@ -259,7 +259,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.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' },
|
||||
].filter(c => state.finFilter !== '待签约' || !c.hideUnsigned);
|
||||
].filter(c => true);
|
||||
|
||||
// 列排序
|
||||
if (!state.finSort) state.finSort = { key: null, asc: true };
|
||||
@@ -285,14 +285,14 @@ function renderFinance() {
|
||||
return h;
|
||||
};
|
||||
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: 'profit', label: '项目利润' }, { key: 'payment', label: '已回款' }, { key: 'paid', label: '已付' },
|
||||
{ key: 'cashflow', label: '现金流' }, { key: 'exe_rate', label: '执行率' }, { key: 'gross_rate', label: '毛利率' },
|
||||
{ key: 'pay_rate', label: '回款率' }, { key: 'paid_rate', label: '付款率' },
|
||||
];
|
||||
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: 'profit', label: '项目利润' },
|
||||
];
|
||||
@@ -304,7 +304,7 @@ function renderFinance() {
|
||||
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 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 cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
||||
@@ -324,25 +324,23 @@ function renderFinance() {
|
||||
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 grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||
const st = '<span class="text-green-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 profit = gross;
|
||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||
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 st = '<span class="text-green-600">已签约</span>';
|
||||
const profit = gross;
|
||||
const profit = gross;
|
||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||
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') {
|
||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
||||
const allPfs = pfs;
|
||||
const now = new Date();
|
||||
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
||||
if (!state.finMonth) state.finMonth = defaultMonth;
|
||||
@@ -360,8 +358,7 @@ function renderFinance() {
|
||||
const paid = Math.round(parseFloat(e.paid || 0) || 0);
|
||||
if (!rev && !payment && !cost && !paid && !gross) return;
|
||||
dataItems.push({
|
||||
pf: pf, customer_name: pf.customer_name || '', status: pf.status || '',
|
||||
sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
||||
cashflow: payment - paid,
|
||||
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
||||
@@ -379,12 +376,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));
|
||||
});
|
||||
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, '该月份暂无数据');
|
||||
}
|
||||
|
||||
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 now = new Date();
|
||||
if (state.finQuarter === undefined) {
|
||||
@@ -412,8 +409,7 @@ function renderFinance() {
|
||||
const paid = sumExpense(pf, "paid");
|
||||
if (!rev && !payment && !cost && !paid && !gross) return;
|
||||
dataItems.push({
|
||||
pf: pf, customer_name: pf.customer_name || '', status: pf.status || '',
|
||||
sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
||||
cashflow: payment - paid,
|
||||
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
||||
@@ -431,7 +427,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));
|
||||
});
|
||||
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, '该季度暂无数据');
|
||||
}
|
||||
|
||||
@@ -445,12 +441,11 @@ function renderFinance() {
|
||||
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) };
|
||||
};
|
||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
||||
const allPfs = pfs;
|
||||
var dataItems = allPfs.map(pf => {
|
||||
var t = calcTotals(pf);
|
||||
return {
|
||||
pf: pf, customer_name: pf.customer_name || '', status: pf.status || '',
|
||||
sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||
rev: t.rev, gross: t.gross, cost: t.cost, profit: t.gross,
|
||||
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,
|
||||
@@ -468,7 +463,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));
|
||||
});
|
||||
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, '暂无数据');
|
||||
})()}
|
||||
</div>`;
|
||||
@@ -789,7 +784,6 @@ window.openPfEditModal = (pfId) => {
|
||||
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
||||
signMonthEl.value = signMonthValue;
|
||||
}
|
||||
form.querySelector('[name="status"]').value = pf.status || "已签约";
|
||||
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
||||
form.querySelector('[name="owner"]').value = pf.owner || "";
|
||||
setVal("start_date", pf.start_date);
|
||||
|
||||
@@ -10,7 +10,7 @@ window.renderPerformance = () => {
|
||||
const qRange = qRanges[q];
|
||||
const storageKey = 'opc-performance-Q' + (q + 1);
|
||||
|
||||
const pfs = (data.projectFinances || []).filter(p => p.status === '已签约');
|
||||
const pfs = (data.projectFinances || []);
|
||||
|
||||
const sumQ = (field) => {
|
||||
let total = 0;
|
||||
|
||||
@@ -5,7 +5,7 @@ const state = {
|
||||
data: null,
|
||||
tenant: "科普·无界",
|
||||
opFilter: "all",
|
||||
finFilter: "已签约",
|
||||
finFilter: "projects",
|
||||
selectedProject: null,
|
||||
taskQuery: "",
|
||||
taskView: localStorage.getItem("opc-task-view") || "detail",
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
<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-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.22</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.23</span></p>
|
||||
<div class="flex items-center gap-4 mt-1">
|
||||
<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">
|
||||
|
||||
Reference in New Issue
Block a user