Files
SupplierSystem/docs/audit/scripts/20260915-dashboard-verify/verify-cost-overview.mjs
T
Ubuntu 1d47267a8d
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore(sync): 提交剩余本地改动(规则文档 / 部署配置 / 小程序入库归档 / 工具与测试)
- .cursor/rules + AGENTS.md:供应商二次开发的隔离硬规则落库(库/端口/上传目录/对象前缀)
- 部署与本地配置:docker-compose*.yml、.env.*.example(仅占位值)、start-split-native / sync-prod-db-to-local 脚本
- 小程序:入库归档识别(stockInboundArchive + 识别与入库面板改动)
- tools:设计门禁脚本(check-migrations / run-all / verify-facts)与架构图脚本更新
- docs:跨系统改价改量审核、第三方订单退货跟随、免入库推进、500+ 分公司规模改造、
  拍照入库识别与档案回写等设计文档;对接清单新增 §4.5.4 我方回执(第六批端到端)
- server:存量修数脚本(legacy CS / 供应商应付 / 结算口径)、采购耳标核对脚本;
  新增测试:入库归档回写、租户优选顺序、规模并发
2026-10-09 22:28:15 +08:00

33 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 端到端核验:调用真实 getDashboardCostOverview(编译产物),数据来自本地同步库(不动生产)
import { createRequire } from 'node:module';
const require = createRequire('/home/ubuntu/harness/ai-fresh-delivery/server/index.js');
process.env.DATABASE_URL = process.env.DATABASE_URL || process.env.DATABASE_URL || 'postgresql://supplier@127.0.0.1:5432/supplier_delivery';
require('dotenv').config?.();
const { pool } = require('/home/ubuntu/harness/ai-fresh-delivery/server/dist/db.js');
const { getDashboardCostOverview } = require('/home/ubuntu/harness/ai-fresh-delivery/server/dist/services/marginQueryService.js');
const { runInBranchSchema, listActiveTenantBranches } = require('/home/ubuntu/harness/ai-fresh-delivery/server/dist/services/tenantSchemaFallback.js');
const branch = process.argv[2] || 'BR002';
const from = process.argv[3] || '2026-09-14';
const to = process.argv[4] || '2026-09-14';
const start = new Date(`${from}T00:00:00+08:00`);
const end = new Date(`${to}T23:59:59+08:00`);
const prevStart = new Date(new Date(start).getTime() - 86400000);
const prevEnd = new Date(new Date(end).getTime() - 86400000);
const out = await runInBranchSchema(branch, () =>
getDashboardCostOverview(start, end, prevStart, prevEnd, branch, 'delivery_date')
);
const buckets = out.ledger_buckets || [];
console.log(`窗口 ${from} ~ ${to}(${branch},delivery_date)`);
console.log(`账本合计 ledger_total = ${out.ledger_total}`);
console.log(`构成行数 = ${buckets.length}(固定 9)`);
for (const b of buckets) console.log(` ${String(b.cost_type).padEnd(20)} ${String(b.label).padEnd(8)} ${String(b.amount).padStart(12)} ${b.pct}%`);
const sum = buckets.reduce((s, b) => s + (Number(b.amount) || 0), 0);
console.log(`各构成之和 = ${sum.toFixed(2)} → 与 ledger_total 一致: ${Math.abs(sum - Number(out.ledger_total)) < 0.01}`);
const fixed = ['purchase','labor_sorting','labor_processing','packaging','transport','delivery','warehouse','loss','overhead'];
console.log(`固定 9 类是否齐全: ${fixed.every((f) => buckets.some((b) => b.cost_type === f))}`);
console.log(`额外(非固定、非零)类型: ${buckets.filter((b) => !fixed.includes(b.cost_type)).map((b) => `${b.cost_type}=${b.amount}`).join(', ') || '无'}`);
console.log(`采购项口径 purchase=${out.quote_cost}(quote_cost 字段)`);
await pool.end();