dsh-data-dashboard 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/incremental/flow.mjs +121 -32
- package/backend/incremental/jobs.mjs +19 -12
- package/backend/incremental/xlsx-rows.mjs +74 -3
- package/backend/modules/distributor/index.mjs +9 -6
- package/backend/modules/movement/index.mjs +17 -64
- package/backend/modules/scan/index.mjs +62 -0
- package/backend/modules/scan/legacy.mjs +21 -0
- package/backend/modules.mjs +2 -1
- package/backend/public/admin.css +9 -2
- package/backend/public/admin.js +74 -21
- package/backend/public/board.html +1 -1
- package/backend/public/board.js +2 -2
- package/backend/public/index.html +10 -10
- package/backend/real-data/decimal-sum.mjs +22 -0
- package/backend/real-data/generate-dashboard.mjs +18 -11
- package/backend/real-data/organization-mapping.mjs +31 -11
- package/backend/real-data/source-payload.mjs +163 -86
- package/backend/real-data/terminal-components.mjs +7 -7
- package/backend/real-data/terminal-structure.mjs +5 -5
- package/backend/real-data/v10-components.mjs +2 -2
- package/backend/real-data/v10-details.mjs +7 -62
- package/backend/real-data/v10-model.mjs +74 -71
- package/backend/real-data/v10-overview-data.mjs +14 -20
- package/backend/real-data/v10-overview.mjs +16 -6
- package/backend/real-data/v10-presentation.mjs +48 -27
- package/backend/real-data/v10-template.mjs +99 -71
- package/backend/review-engine.mjs +65 -35
- package/backend/review-service.mjs +28 -13
- package/backend/server.mjs +27 -18
- package/backend/store.mjs +3 -0
- package/backend/target-template.mjs +4 -2
- package/backend/validate-workbook.mjs +5 -2
- package/backend/web-sync/exporter.mjs +55 -21
- package/build-manifest.json +41 -38
- package/index.js +1 -1
- package/lib/tool-definitions.mjs +33 -15
- package/lib/tools.mjs +318 -85
- package/package.json +1 -1
|
@@ -10,14 +10,14 @@ export function createV10Details({ T, g, model, presentation, charts }) {
|
|
|
10
10
|
const metric = (value, unit = '', label = '') => typeof value === 'object' && value !== null ? value : { value, unit, label, state: finite(value) ? 'available' : 'pending' };
|
|
11
11
|
const unit = item => item?.unit === '元' ? '万元' : item?.unit || '';
|
|
12
12
|
const numeric = item => item?.unit === '元' ? item.value / 10000 : item.value;
|
|
13
|
-
const valueText = item => available(item) ? model.format(numeric(item), item.displayPrecision ?? (item.unit === '元' || item.unit?.includes('/') || item.unit === '%' || item.unit === '月' ? 2 : 0), item.displayPrecision ?? (item.unit === '元' || item.unit?.includes('/') || item.unit === '%' || item.unit === '月' ? 2 : 6)) : item?.state === 'missing' ? '无记录' : item?.state === 'unavailable' ? '不可用' : '待确认';
|
|
13
|
+
const valueText = item => available(item) ? model.format(numeric(item), item.displayPrecision ?? (item.unit === '元' || item.unit?.includes('/') || item.unit === '%' || item.unit === '月' ? 2 : 0), item.displayPrecision ?? (item.unit === '元' || item.unit?.includes('/') || item.unit === '%' || item.unit === '月' ? 2 : item.unit === '件' ? 1 : 6)) : item?.state === 'missing' ? '无记录' : item?.state === 'unavailable' ? '不可用' : '待确认';
|
|
14
14
|
const reason = item => item?.reason || (available(item) ? '' : '当前来源未提供完整的计算依据');
|
|
15
15
|
const name = item => item?.name || item?.label || '未提供名称';
|
|
16
|
-
const english = { invoice: 'INVOICE SALES', movement: '
|
|
16
|
+
const english = { invoice: 'INVOICE SALES', movement: 'SALES MOVEMENT', opening: 'CONSUMER OPENINGS', inventory: 'INVENTORY CHECK', banquet: 'BANQUET ACTIVITY' };
|
|
17
17
|
const descriptions = {
|
|
18
18
|
invoice: '季度、当月与财年发票及达成,开票节奏、组织和产品贡献。',
|
|
19
|
-
movement: '
|
|
20
|
-
opening: '
|
|
19
|
+
movement: '动销金额与开票对比、组织和产品贡献。',
|
|
20
|
+
opening: '开瓶金额与瓶数节奏、同比环比及开瓶城市分布。',
|
|
21
21
|
inventory: '当前导出记录的盘点规模、提交节奏、差异与产品结构。',
|
|
22
22
|
banquet: '按执行月份统计的宴席场次、开瓶、场均开瓶及组织表现。',
|
|
23
23
|
};
|
|
@@ -123,7 +123,7 @@ export function createV10Details({ T, g, model, presentation, charts }) {
|
|
|
123
123
|
const canDrill = !secondary && !leaf && item.drillable !== false && model.organizations.some(organization => organization[groupField] === item.key);
|
|
124
124
|
return el(canDrill ? 'button' : 'div', { key: item.key || item.name || index, className: secondary ? 'inv-dealer' : 'group-row', ...(canDrill ? { type: 'button', onClick: () => drill(groupField, item.key), 'aria-label': `筛选${name(item)}` } : {}), 'data-state': item.state },
|
|
125
125
|
el('span', { className: 'rank' }, String(index + 1).padStart(2, '0')),
|
|
126
|
-
el('div', { className: secondary ? '' : 'group-name' }, el('strong', { title: [name(item), item.note].filter(Boolean).join(';') }, name(item), secondary && item.records > 0 && el('small', {}, `${model.format(item.records)} 条来源记录`)), el('div', { className: 'track' }, available(item) && el('i', { style: { width: `${Math.abs(item.value) / max * 100}%`, background: item.value < 0 ? '#c99464' : color } }))),
|
|
126
|
+
el('div', { className: secondary ? '' : 'group-name' }, el('strong', { title: [name(item), item.note].filter(Boolean).join(';') }, name(item), secondary && (item.subtitle ? el('small', {}, item.subtitle) : item.records > 0 && el('small', {}, `${model.format(item.records)} 条来源记录`))), el('div', { className: 'track' }, available(item) && el('i', { style: { width: `${Math.abs(item.value) / max * 100}%`, background: item.value < 0 ? '#c99464' : color } }))),
|
|
127
127
|
el('b', {}, el(MetricValue, { item }), !available(item) ? el('small', {}, reason(item)) : item.shareText ? el('small', {}, item.shareText) : finite(item.share) && el('small', {}, `${model.format(item.share * 100, 1)}%`)),
|
|
128
128
|
canDrill && el('span', { className: 'v10-drill-arrow', 'aria-hidden': true }, '›'),
|
|
129
129
|
);
|
|
@@ -159,33 +159,6 @@ export function createV10Details({ T, g, model, presentation, charts }) {
|
|
|
159
159
|
!products.length && el(Empty, {}),
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
|
-
function SourceTable({ rows, kind, inventoryMode, cutoffDate }) {
|
|
163
|
-
const [page, setPage] = g.useState(0), size = 24;
|
|
164
|
-
const entries = list(rows), pages = Math.max(1, Math.ceil(entries.length / size)), current = Math.min(page, pages - 1);
|
|
165
|
-
g.useEffect(() => setPage(0), [rows, kind]);
|
|
166
|
-
const columns = {
|
|
167
|
-
invoice: [['organization', '完整组织路径'], ['date', '业务日期'], ['dealerName', '经销商'], ['dealerCode', '经销商编码'], ['brand', '品牌'], ['category', '品类'], ['amount', '发票净额 / 万元', '元']],
|
|
168
|
-
movement: [['organization', '完整组织路径'], ['date', '扫码日期'], ['terminalName', '终端'], ['terminalCode', '售点编码'], ['brand', '品牌'], ['category', '品类'], ['amount', '扫码净额 / 万元', '元'], ['bottles', '瓶单位数量', '瓶'], ['boxes', '盒单位数量', '盒'], ['cases', '来源扫码件数', '源件数']],
|
|
169
|
-
opening: [['organization', '产品所属完整组织'], ['date', '抽奖日期'], ['city', '开瓶城市'], ['bottles', '开瓶 / 瓶', '瓶'], ['amount', '开瓶金额 / 万元', '元']],
|
|
170
|
-
inventory: inventoryMode === 'visit-history'
|
|
171
|
-
? [['organization', '源完整营销组织'], ['dealerName', '经销商'], ['dealerCode', '经销商编码'], ['productName', '完整产品名称'], ['submittedAt', '盘点提交时间'], ['system', '提交时系统 / 瓶', '瓶'], ['counted', '盘点 / 瓶', '瓶'], ['signedVariance', '盘点与系统差异 / 瓶', '瓶'], ['previousSubmittedAt', '上次盘点时间'], ['previousCounted', '上次盘点瓶数 / 瓶', '瓶'], ['changeFromPrevious', '较上次变化瓶数 / 瓶', '瓶'], ['daysSinceStocktake', '距所选截止日天数 / 天', '天'], ['comparisonStatusLabel', '比较状态'], ['absoluteVariance', '绝对差 / 瓶', '瓶'], ['sourceVariance', '源偏差 / 瓶', '瓶'], ['systemAmount', '提交时系统金额 / 万元', '元'], ['recordStatus', '核查提示'], ['supplementRequested', '是否补录'], ['supplementStatus', '补录状态']]
|
|
172
|
-
: [['organization', '完整组织路径'], ['dealerName', '经销商'], ['dealerCode', '经销商编码'], ['productCode', '产品编码'], ['productName', '产品'], ['date', '盘点提交日期'], ['system', '系统 / 瓶', '瓶'], ['counted', '盘点 / 瓶', '瓶'], ['sourceVariance', '源偏差 / 瓶', '瓶'], ['signedVariance', '盘点−系统 / 瓶', '瓶'], ['absoluteVariance', '绝对差 / 瓶', '瓶']],
|
|
173
|
-
banquet: [['organization', '完整组织路径'], ['events', '执行 / 场', '场'], ['bottles', '开瓶 / 瓶', '瓶'], ['average', '场均 / 瓶', '瓶/场']],
|
|
174
|
-
}[kind] || [];
|
|
175
|
-
const cell = (row, field, measureUnit) => {
|
|
176
|
-
if (kind === 'banquet' && field === 'reward') return '待确认';
|
|
177
|
-
const value = row[field];
|
|
178
|
-
if (value && typeof value === 'object' && 'state' in value) return valueText(value);
|
|
179
|
-
if (measureUnit) return finite(value) ? valueText(metric(value, measureUnit)) : '待确认';
|
|
180
|
-
return typeof value === 'string' && value ? value : '未提供';
|
|
181
|
-
};
|
|
182
|
-
return el('div', { className: 'table-wrap v10-source-table' },
|
|
183
|
-
el('p', { className: 'v10-chart-caption' }, `按当前筛选展示允许导出的来源记录;源空值保持未知,不补零。${kind === 'inventory' && inventoryMode === 'visit-history' ? `距所选截止日天数以 ${cutoffDate || '未提供'} 为基准;基准日取所选月末与来源最大已知提交日期的较早者,不使用电脑今天日期。较上次变化不代表销量。` : ''}`),
|
|
184
|
-
el('div', { className: 'v10-table-scroll' }, el('table', {}, el('thead', {}, el('tr', {}, ...columns.map(([field, label]) => el('th', { key: field, scope: 'col' }, label)))), el('tbody', {}, ...entries.slice(current * size, (current + 1) * size).map((row, index) => el('tr', { key: row.key || index }, ...columns.map(([field, , measureUnit]) => el('td', { key: field, title: cell(row, field, measureUnit) }, cell(row, field, measureUnit)))))))),
|
|
185
|
-
!entries.length && el(Empty, {}),
|
|
186
|
-
el('div', { className: 'v10-pagination' }, el('span', {}, `共 ${model.format(entries.length)} 条来源记录 · 第 ${current + 1} / ${pages} 页`), el('button', { type: 'button', disabled: current === 0, onClick: () => setPage(current - 1) }, '上一页'), el('button', { type: 'button', disabled: current >= pages - 1, onClick: () => setPage(current + 1) }, '下一页')),
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
162
|
function ObservationTable({ items, kind, inventoryMode }) {
|
|
190
163
|
const entries = list(items);
|
|
191
164
|
if (!entries.length) return el(Empty, {});
|
|
@@ -200,28 +173,6 @@ export function createV10Details({ T, g, model, presentation, charts }) {
|
|
|
200
173
|
)),
|
|
201
174
|
);
|
|
202
175
|
}
|
|
203
|
-
function DayChangeTable({ items }) {
|
|
204
|
-
const entries = list(items);
|
|
205
|
-
if (!entries.length) return el(Empty, {});
|
|
206
|
-
const first = entries.find(item => item.date) || {}, day = date => date ? date.slice(5) : '—';
|
|
207
|
-
const bottles = value => finite(value) ? model.format(value) : '—';
|
|
208
|
-
return el('div', { className: 'sg-series op-day v10-observation-table', 'aria-label': `${first.date || '末日'} 与 ${first.previousDate || '昨日'} 开瓶比较` },
|
|
209
|
-
el('div', { className: 'sg-row head' }, el('span', {}, '组织'), el('span', {}, `${day(first.previousDate)} / 瓶`), el('span', {}, `${day(first.date)} / 瓶`), el('span', {}, '变化 / 瓶'), el('span', {}, '较昨日')),
|
|
210
|
-
...entries.map((item, index) => el('div', { className: 'sg-row', key: item.key || index }, el('strong', { title: name(item) }, name(item)),
|
|
211
|
-
el('span', {}, bottles(item.previous)), el('span', {}, bottles(item.current)),
|
|
212
|
-
el('span', { className: finite(item.difference) && item.difference < 0 ? 'minus' : finite(item.difference) && item.difference > 0 ? 'plus' : '' }, finite(item.difference) ? `${item.difference > 0 ? '+' : ''}${model.format(item.difference)}` : '—'),
|
|
213
|
-
el('b', { className: available(item) && item.value < 0 ? 'minus' : available(item) && item.value > 0 ? 'plus' : '', title: reason(item) }, available(item) ? `${item.value > 0 ? '+' : ''}${model.format(item.value, 1, 1)}%` : '—'))),
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
function Definitions({ module, description }) {
|
|
217
|
-
const notes = [...new Set([...(description.notes || []), ...(module.pending || [])].filter(value => typeof value === 'string' && value))];
|
|
218
|
-
return el('div', { className: 'definitions' },
|
|
219
|
-
el('div', { className: 'source-label' }, module.source?.originalName || '当前板块没有有效上传来源'),
|
|
220
|
-
...notes.map((text, index) => el('div', { key: text, className: 'definition-row' }, el('strong', {}, `口径 ${index + 1}`), el('p', {}, text))),
|
|
221
|
-
...(module.crossMetrics || []).map(item => el('div', { key: item.key, className: 'definition-row' }, el('strong', {}, item.label), el('div', {}, item.reason && el('p', {}, item.reason), ...(item.notes || []).map((text, index) => el('p', { key: index }, text))))),
|
|
222
|
-
el('div', { className: 'v10-source-proof' }, el('h3', {}, '本次来源版本'), module.source ? el('dl', {}, el('dt', {}, '上传版本'), el('dd', {}, module.source.uploadId), el('dt', {}, 'SHA-256'), el('dd', {}, module.source.sha256), el('dt', {}, '来源期间'), el('dd', {}, module.period)) : el('p', {}, '请先上传并校验对应来源。'), el('p', {}, `生成时间:${model.payload.generatedAt}`)),
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
176
|
function UpLevel({ filters, drill }) {
|
|
226
177
|
const step = filters.unit !== 'all' ? ['unit', model.label(filters.office)] : filters.office !== 'all' ? ['office', model.label(filters.region)] : filters.region !== 'all' ? ['region', '全战区'] : null;
|
|
227
178
|
return step && el('button', { type: 'button', className: 'up-level v10-up-level', 'aria-label': `返回上一级:${step[1]}`, onClick: () => drill(step[0], 'all') }, '‹ 返回上一级', el('small', {}, step[1]));
|
|
@@ -246,15 +197,9 @@ export function createV10Details({ T, g, model, presentation, charts }) {
|
|
|
246
197
|
el(Ranked, { items: description.organizations, color: module.color, drill, groupField: module.groupField, leaf: filters.unit !== 'all' }),
|
|
247
198
|
['invoice', 'movement', 'inventory'].includes(kind) && el(Products, { description, filters, drill }),
|
|
248
199
|
kind === 'invoice' && (description.platformSources || []).length > 1 && section('发票来源构成', el(Ranked, { items: description.platformSources, color: module.color, secondary: true }), '藏10、吞之乎平台订单已并入发票合计'),
|
|
249
|
-
kind === 'movement' && description.
|
|
250
|
-
el(Concentration, { items: [{ key: 'd-main', name: description.distributor.main.label, ...description.distributor.main },
|
|
251
|
-
{ key: 'd-yoy', name: '同比', ...description.distributor.yoy, displayPrecision: 1 },
|
|
252
|
-
{ key: 'd-count', name: '有出库的分销商', label: '有出库的分销商', unit: '家', value: description.distributor.distributors, state: 'available' }], tone }),
|
|
253
|
-
el(Ranked, { items: (description.distributor.groups || []).map(item => ({ ...item, key: `d-${item.key}` })), color: module.color, secondary: true, limit: 8 })),
|
|
254
|
-
'分销商出库与终端扫码多为同一批交易,不计入动销合计与达成'),
|
|
255
|
-
kind === 'movement' && section('终端渠道结构', el(Ranked, { items: description.channels, color: module.color, secondary: true, limit: 8 }), '按来源渠道展示扫码金额'),
|
|
200
|
+
kind === 'movement' && (description.movementSources || []).length > 0 && section(`动销来源构成 · ${filters.period === 'range' ? '所选区间' : '当月'}`, el(Ranked, { items: description.movementSources, color: module.color, secondary: true }), '两表口径不重叠,直接相加'),
|
|
256
201
|
kind === 'opening' && section('开瓶城市 · 消费地', el(g.Fragment, {}, el(Concentration, { items: description.cities?.concentration || ranking.concentration, tone: 'op' }), el(Ranked, { items: description.cities, color: module.color, secondary: true, limit: 10 })), '与产品所属组织独立观察'),
|
|
257
|
-
['
|
|
202
|
+
['inventory', 'banquet'].includes(kind) && section(ranking.title || ({ invoice: '客户集中度 · 经销商', inventory: '库存 Top 经销商', banquet: '执行 Top 单元' })[kind], el(g.Fragment, {}, el(Concentration, { items: ranking.concentration, tone }), el(Ranked, { items: ranking.items, color: module.color, secondary: true, limit: kind === 'banquet' ? 10 : 8 })), ranking.note),
|
|
258
203
|
kind === 'inventory' && section(inventoryVisit ? '盘点与系统差异 · 逐条比较' : '盘点差异 · 逐条比较', el(ObservationTable, { items: description.deviations, kind, inventoryMode: module.inventoryMode }), '盘点减系统,按来源记录逐条比较'),
|
|
259
204
|
kind === 'banquet' && section('场均开瓶排行', el(ObservationTable, { items: description.efficiency, kind }), '同一完整组织路径 · 所选月份'),
|
|
260
205
|
el('div', { className: 'v10-method-note' }, '缺失、待确认和真实零值分别展示;“—”表示缺少来源或口径待确认,不补零。'),
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import { createDecimalSum, sumDecimal } from './decimal-sum.mjs';
|
|
1
2
|
import { buildTerminalStructure } from './terminal-structure.mjs';
|
|
2
3
|
|
|
3
4
|
// Both factories are serialized into the offline dashboard.
|
|
4
5
|
export function createV10Model(payload, terminalBuilder = buildTerminalStructure) {
|
|
5
6
|
const inventoryHistory = payload.modules.inventory.inventoryMode === 'visit-history';
|
|
6
7
|
const ids = ['invoice', 'movement', 'opening', 'terminal', 'inventory', 'banquet'];
|
|
7
|
-
const titles = { invoice: '发票销售', movement: '
|
|
8
|
+
const titles = { invoice: '发票销售', movement: '动销', opening: '消费者开瓶', terminal: '终端签约', inventory: '库存盘点', banquet: '宴席执行' };
|
|
8
9
|
const colors = { invoice: '#ab343c', movement: '#167d72', opening: '#547fa3', terminal: '#877753', inventory: '#687e88', banquet: '#9c7865' };
|
|
9
10
|
const definitions = {
|
|
10
|
-
invoice: ['当月发票净额', '元', 'amount'], movement: ['
|
|
11
|
+
invoice: ['当月发票净额', '元', 'amount'], movement: ['当月动销净额', '元', 'amount'],
|
|
11
12
|
opening: ['当月开瓶瓶数', '瓶', 'bottles'], terminal: ['截至所选月末累计签约终端', '家', 'terminalCount'],
|
|
12
13
|
inventory: ['当前导出所选记录盘点数量', '瓶', 'counted'], banquet: ['当月宴席执行场次', '场', 'events'],
|
|
13
14
|
};
|
|
14
15
|
const pending = {
|
|
15
16
|
invoice: ['达成率使用“经营目标”来源,按组织名称对应,目标不分产品;主页同比按同组织、同产品与上年同期比较,期间或基数不足时保留原因;不显示期间覆盖尚未对齐的环比。'],
|
|
16
|
-
movement: ['
|
|
17
|
-
opening: ['开瓶金额为来源“开瓶金额”字段(2026-11-27
|
|
17
|
+
movement: ['动销 = 经销商动销明细(仅计销售出库与退货)+ 分销商动销明细,两表口径不重叠、直接相加,统一按件和金额统计;两表更新不同步时按较早日期对齐。', '跨表指标按对应来源的确认状态显示;当月与年累计口径分别标明。本看板暂不显示环比。'],
|
|
18
|
+
opening: ['开瓶金额为来源“开瓶金额”字段(2026-11-27 确认为开瓶产品金额,不是现金红包),界面以万元显示。'],
|
|
18
19
|
terminal: ['签约终端按网点编号去重,按签约日期截至所选月末累计。', '有效终端按 2026-07-01 至所选月末任一已签约品系扫码净件数达到 1 件判断。'],
|
|
19
20
|
inventory: ['本页是已上传导出的盘点记录视图,不是任意历史月份的库存快照。', '可销月数只对当前导出月份作来源估算,不重建历史库存,也不外推未提供日期。'],
|
|
20
21
|
banquet: ['按执行月份统计,随月份筛选;自定义区间按覆盖到的整月计入;不随产品筛选。', '宴席开瓶与消费者开瓶的包含关系不保证,不展示二者占比。'],
|
|
@@ -41,6 +42,7 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
41
42
|
}
|
|
42
43
|
return total;
|
|
43
44
|
};
|
|
45
|
+
const sumMovement = (rows, field) => rows.some(row => !finite(row[field])) ? null : sumDecimal(rows.map(row => row[field]));
|
|
44
46
|
const orgFields = ['marketingCompany', 'businessUnit', 'theater', 'region', 'office', 'unit'];
|
|
45
47
|
const partsFor = row => row.orgPath || orgFields.map(key => row.org?.[key] || '');
|
|
46
48
|
const labels = new Map(), fullLabels = new Map();
|
|
@@ -83,13 +85,18 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
83
85
|
product: JSON.stringify([row.brand || '未映射品牌', row.category || '未映射品类']),
|
|
84
86
|
month: row.date ? row.date.slice(0, 7) : null };
|
|
85
87
|
})]));
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
const scanModule = payload.modules.scan;
|
|
89
|
+
const movementCover = payload.coverage.movement;
|
|
90
|
+
const isMovementCovered = row => !row.date || movementCover?.end && row.date <= movementCover.end
|
|
91
|
+
&& (movementCover.start ? row.date >= movementCover.start : movementCover.semantics !== 'common-movement-date');
|
|
92
|
+
const limits = payload.movementSources?.distributor?.scopeLimits;
|
|
93
|
+
const movementOrganizationIssue = limits?.organization ? '分销商明细缺少完整组织,组织范围汇总待确认' : null;
|
|
94
|
+
const movementProductIssue = limits?.product ? '分销商明细缺少品牌或品类,产品范围汇总待确认' : null;
|
|
95
|
+
const movementScopeIssue = filters => limits?.invalidTemplate
|
|
96
|
+
|| ((limits?.scopedOrganization || ['region', 'office', 'unit'].some(id => filters[id] !== 'all')) && movementOrganizationIssue)
|
|
97
|
+
|| (filters.product !== 'all' && movementProductIssue) || null;
|
|
91
98
|
const monthSet = new Set();
|
|
92
|
-
for (const id of ids) for (const row of normalized[id]) if (row.month) monthSet.add(row.month);
|
|
99
|
+
for (const id of ids) for (const row of normalized[id]) if (row.month && (id !== 'movement' || isMovementCovered(row))) monthSet.add(row.month);
|
|
93
100
|
if (!monthSet.size) for (const coverage of Object.values(payload.coverage)) if (coverage?.end) monthSet.add(coverage.end.slice(0, 7));
|
|
94
101
|
const months = [...monthSet].sort();
|
|
95
102
|
if (!months.length) months.push('fixed');
|
|
@@ -116,7 +123,7 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
116
123
|
if (!['records', 'agreementCount'].includes(field) && rows.some(row => row.inventoryConflict || row.inventoryDateUncertain)) return { label, unit, value: null, state: 'unavailable', reason: '最近盘点有同时间候选或无效提交时间,不能确定唯一库存' };
|
|
117
124
|
}
|
|
118
125
|
if (forcePending || module.metrics[field]?.status === 'pending') return { label, unit, value: null, state: 'pending', reason: '来源规则或口径待确认' };
|
|
119
|
-
const value = ['records', 'agreementCount'].includes(field) ? rows.length : field === 'terminalCount' ? rows.some(row => !row.terminalCode) ? null : new Set(rows.map(row => row.terminalCode)).size : sum(rows, field);
|
|
126
|
+
const value = ['records', 'agreementCount'].includes(field) ? rows.length : field === 'terminalCount' ? rows.some(row => !row.terminalCode) ? null : new Set(rows.map(row => row.terminalCode)).size : module === payload.modules.movement ? sumMovement(rows, field) : sum(rows, field);
|
|
120
127
|
return { label, unit, value, state: value === null ? 'pending' : 'available', reason: value === null ? '存在缺失或不可用源值' : null };
|
|
121
128
|
};
|
|
122
129
|
const monthEnd = month => new Date(Date.UTC(Number(month.slice(0, 4)), Number(month.slice(5, 7)), 0)).toISOString().slice(0, 10);
|
|
@@ -147,7 +154,8 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
147
154
|
}
|
|
148
155
|
return null;
|
|
149
156
|
};
|
|
150
|
-
const windowRows = (id, filters, start, end
|
|
157
|
+
const windowRows = (id, filters, start, end) => normalized[id].filter(row => matchesOrg(row, filters) && matchesProduct(id, row, filters)
|
|
158
|
+
&& row.date && row.date >= start && row.date <= end && (id !== 'movement' || isMovementCovered(row)));
|
|
151
159
|
const ratioMetric = (key, label, unit, numerator, denominator, range, notes, scale = 100) => {
|
|
152
160
|
if (!finite(numerator) || !finite(denominator)) return failCross(key, label, unit, '计算窗口存在缺失源值', notes);
|
|
153
161
|
if (denominator <= 0) return failCross(key, label, unit, '分母不大于零,不能计算比例或估算', notes);
|
|
@@ -155,57 +163,47 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
155
163
|
if (!finite(value)) return failCross(key, label, unit, '计算结果超出可表示范围', notes);
|
|
156
164
|
return { key, label, unit, value, state: 'available', reason: null, numerator, denominator, range, notes, precision: 2 };
|
|
157
165
|
};
|
|
166
|
+
// 动销合并了经销商与分销商,跨表确认绑定实际参与的来源版本(只有一边时只绑那一边)。
|
|
167
|
+
const movementShaIds = ['movement', 'distributor'].filter(id => payload.sources[id]?.sha256
|
|
168
|
+
&& (!payload.movementSources || Boolean(payload.movementSources[id === 'movement' ? 'dealer' : id])));
|
|
158
169
|
function crossTableMetrics(filters) {
|
|
159
170
|
const f = filters, p = periodOf(f), range = p.mode === 'range';
|
|
160
171
|
const amountRatio = cumulative => {
|
|
161
172
|
const key = cumulative ? 'invoiceMovementYtdRatio' : 'invoiceMovementMonthRatio', label = cumulative ? '年累计动销 / 开票' : range ? '区间动销 / 开票' : '当月动销 / 开票';
|
|
162
173
|
const deps = ['invoice', 'movement'];
|
|
163
|
-
if (
|
|
174
|
+
if (movementScopeIssue(f)) return failCross(key, label, '%', movementScopeIssue(f), [], 'pending');
|
|
175
|
+
if (!ruleReady('crossTableMetrics', [deps[0], ...movementShaIds])) return failCross(key, label, '%', '这两个来源版本的跨表关系尚未确认', [], 'pending');
|
|
164
176
|
const end = commonCut(deps, p.end), start = cumulative ? `${f.month.slice(0, 4)}-01-01` : p.start;
|
|
165
|
-
const notes = [`同组织、同产品;${start} 至 ${end || '未提供共同截止日'}。`, '
|
|
177
|
+
const notes = [`同组织、同产品;${start} 至 ${end || '未提供共同截止日'}。`, '动销净额与发票净额分别来自各自来源;比例超过 100% 不解释为渗透率。'];
|
|
166
178
|
const issue = sourceWindowIssue(deps, start, end);
|
|
167
179
|
if (issue) return failCross(key, label, '%', issue, notes);
|
|
168
180
|
const invoices = windowRows('invoice', f, start, end), movements = windowRows('movement', f, start, end);
|
|
169
181
|
if (!invoices.length || !movements.length) return failCross(key, label, '%', '当前组织或产品范围缺少一侧来源记录', notes);
|
|
170
182
|
if (deps.some(id => payload.modules[id].metrics.amount?.status === 'pending')) return failCross(key, label, '%', '来源金额规则尚未确认', notes, 'pending');
|
|
171
|
-
return ratioMetric(key, label, '%',
|
|
172
|
-
};
|
|
173
|
-
const openingRatio = () => {
|
|
174
|
-
const key = 'openingMovementRatio', label = '年累计开瓶 / 动销(瓶)', deps = ['opening', 'movement'];
|
|
175
|
-
if (!ruleReady('crossTableMetrics', deps)) return failCross(key, label, '%', '这两个来源版本的跨表关系尚未确认', [], 'pending');
|
|
176
|
-
const end = commonCut(deps, p.end), start = `${f.month.slice(0, 4)}-01-01`;
|
|
177
|
-
const notes = [`同组织;${start} 至 ${end || '未提供共同截止日'};分子与分母都不随产品筛选。`, '仅计单品单位为瓶的扫码数量;盒单位不混入。此值是来源量关系,不解释为消费者渗透率。'];
|
|
178
|
-
const issue = sourceWindowIssue(deps, start, end);
|
|
179
|
-
if (issue) return failCross(key, label, '%', issue, notes);
|
|
180
|
-
const openings = windowRows('opening', f, start, end, true), movements = windowRows('movement', f, start, end, true);
|
|
181
|
-
if (!openings.length || !movements.length) return failCross(key, label, '%', '当前组织缺少一侧来源记录', notes);
|
|
182
|
-
if (movements.some(row => !['瓶', '盒'].includes(row.quantityUnit))) return failCross(key, label, '%', '扫码来源存在未确认单位,无法确认完整瓶数分母', notes);
|
|
183
|
-
if (deps.some(id => payload.modules[id].metrics.bottles?.status === 'pending')) return failCross(key, label, '%', '来源瓶数规则尚未确认', notes, 'pending');
|
|
184
|
-
const bottles = movements.filter(row => row.quantityUnit === '瓶');
|
|
185
|
-
if (!bottles.length) return failCross(key, label, '%', '当前组织没有瓶单位扫码记录', notes);
|
|
186
|
-
return ratioMetric(key, label, '%', sum(openings, 'bottles'), sum(bottles, 'bottles'), { start, end }, notes);
|
|
183
|
+
return ratioMetric(key, label, '%', sumMovement(movements, 'amount'), sum(invoices, 'amount'), { start, end }, notes);
|
|
187
184
|
};
|
|
188
185
|
const inventoryMonths = () => {
|
|
189
186
|
const key = 'inventorySellableMonths', label = '可销月数(来源估算)', deps = ['inventory', 'movement'];
|
|
187
|
+
if (movementScopeIssue(f)) return failCross(key, label, '月', movementScopeIssue(f), [], 'pending');
|
|
190
188
|
if (inventoryHistory) return failCross(key, label, '月', '拜访采集表缺少盘点金额和产品编码,无法计算可销月份');
|
|
191
|
-
if (!ruleReady('crossTableMetrics', deps)) return failCross(key, label, '月', '这两个来源版本的跨表关系尚未确认', [], 'pending');
|
|
189
|
+
if (!ruleReady('crossTableMetrics', [deps[0], ...movementShaIds])) return failCross(key, label, '月', '这两个来源版本的跨表关系尚未确认', [], 'pending');
|
|
192
190
|
if (range) return failCross(key, label, '月', '自定义区间不估算可销月数;请切换到按月查看');
|
|
193
191
|
if (payload.coverage.inventory?.end?.slice(0, 7) !== f.month) return failCross(key, label, '月', '只对库存当前导出截止月份估算,不能还原历史月份库存');
|
|
194
192
|
const end = commonCut(deps, p.end), start = `${offsetMonth(f.month, -2)}-01`;
|
|
195
193
|
const partial = end && end < monthEnd(f.month);
|
|
196
|
-
const notes = [`同组织、同产品;盘点金额采用截至 ${end || '未提供共同截止日'} 的当前导出记录。`, `分母为 ${start} 至 ${end || '未提供'}
|
|
194
|
+
const notes = [`同组织、同产品;盘点金额采用截至 ${end || '未提供共同截止日'} 的当前导出记录。`, `分母为 ${start} 至 ${end || '未提供'} 的动销净额合计 ÷ 3,窗口包含所选月及前两个月。`, partial ? '窗口含未完月,直接使用已提供的来源值;未折算全月,不作未来外推。' : '使用来源覆盖的三个连续月份;不补缺失月份。', '盘点估值与动销金额属于不同业务量,这只是来源估算,不是库存历史快照或实际周转天数。'];
|
|
197
195
|
const issue = sourceWindowIssue(['movement'], start, end);
|
|
198
196
|
if (issue) return failCross(key, label, '月', issue, notes);
|
|
199
197
|
const inventory = normalized.inventory.filter(row => matchesOrg(row, f) && matchesProduct('inventory', row, f) && row.date && row.date <= end);
|
|
200
198
|
const movement = windowRows('movement', f, start, end);
|
|
201
199
|
if (normalized.inventory.some(row => !row.date)) return failCross(key, label, '月', '盘点来源存在缺失日期', notes);
|
|
202
|
-
if (!inventory.length || !movement.length) return failCross(key, label, '月', '
|
|
200
|
+
if (!inventory.length || !movement.length) return failCross(key, label, '月', '当前组织或产品缺少盘点或动销来源记录', notes);
|
|
203
201
|
if (payload.modules.inventory.metrics.countAmount?.status === 'pending' || payload.modules.movement.metrics.amount?.status === 'pending') return failCross(key, label, '月', '来源金额规则尚未确认', notes, 'pending');
|
|
204
|
-
const amount = sum(inventory, 'countAmount'), sales =
|
|
202
|
+
const amount = sum(inventory, 'countAmount'), sales = sumMovement(movement, 'amount');
|
|
205
203
|
if (amount !== null && amount < 0) return failCross(key, label, '月', '盘点来源金额为负,无法作可销月数估算', notes);
|
|
206
204
|
return ratioMetric(key, label, '月', amount, sales === null ? null : sales / 3, { start, end }, notes, 1);
|
|
207
205
|
};
|
|
208
|
-
return { movement: [amountRatio(false), amountRatio(true)],
|
|
206
|
+
return { movement: [amountRatio(false), amountRatio(true)], inventory: [inventoryMonths()] };
|
|
209
207
|
}
|
|
210
208
|
const inventorySelections = new Map();
|
|
211
209
|
const latestInventory = cutoff => {
|
|
@@ -341,6 +339,7 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
341
339
|
const base = { label, unit: '元', range: { start: window.start, end: window.end } };
|
|
342
340
|
const fail = (reason, state = 'pending') => ({ ...base, value: null, state, reason });
|
|
343
341
|
if (source.state === 'unavailable') return fail(source.reviewReason || '未接入有效来源', source.reviewPending ? 'pending' : 'missing');
|
|
342
|
+
if (module.scopeIssue) return fail(module.scopeIssue);
|
|
344
343
|
if (!isDate(cover?.start) || !isDate(cover?.end)) return fail('来源覆盖期间缺失或无效');
|
|
345
344
|
if (cover.start > window.start) return fail(`来源从 ${cover.start} 开始,未覆盖 ${window.start} 起的完整累计期间`);
|
|
346
345
|
if (cover.end < window.start) return fail(`来源截至 ${cover.end},尚无本期记录`, 'missing');
|
|
@@ -392,23 +391,23 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
392
391
|
const yearToEnd = row => Boolean(row.month) && row.month.slice(0, 4) === f.month.slice(0, 4) && (p.mode === 'fixed' ? row.month <= f.month : row.date <= p.end);
|
|
393
392
|
for (const id of ids) {
|
|
394
393
|
const sourceModule = payload.modules[id], sourceRows = id === 'inventory' && inventoryHistory ? latestInventory(p.end || '9999-12-31') : normalized[id];
|
|
395
|
-
const scoped = sourceRows.filter(row => matchesOrg(row, f) && matchesProduct(id, row, f));
|
|
394
|
+
const scoped = sourceRows.filter(row => (id !== 'movement' || isMovementCovered(row)) && matchesOrg(row, f) && matchesProduct(id, row, f));
|
|
396
395
|
const rows = scoped.filter(row => id === 'banquet' ? inMonths(row) : (row.month && (['inventory', 'terminal'].includes(id) ? upToEnd(row) : inWindow(row))));
|
|
397
396
|
const [baseLabel, unit, field] = definitions[id];
|
|
398
397
|
const label = p.mode === 'range' ? baseLabel.replace('当月', '区间').replace('截至所选月末', `截至 ${p.end}`) : baseLabel;
|
|
399
398
|
const main = metric(rows, field, sourceModule, label, unit);
|
|
400
399
|
const extra = [];
|
|
401
400
|
if (id === 'invoice' || id === 'movement') {
|
|
402
|
-
|
|
401
|
+
const yearRows = scoped.filter(yearToEnd);
|
|
402
|
+
const ytd = metric(yearRows, 'amount', sourceModule, '当年截至所选月来源金额', '元');
|
|
403
|
+
if (id === 'movement' && !yearRows.length && sourceModule.state !== 'unavailable') {
|
|
404
|
+
Object.assign(ytd, { value: null, state: 'missing', reason: '当年累计期间无来源记录' });
|
|
405
|
+
}
|
|
406
|
+
extra.push(ytd);
|
|
403
407
|
extra.push(metric(rows.filter(row => finite(row.amount) && row.amount > 0), 'amount', sourceModule, '正金额合计', '元', main.state !== 'available'));
|
|
404
408
|
extra.push(metric(rows.filter(row => finite(row.amount) && row.amount < 0), 'amount', sourceModule, '负金额合计', '元', main.state !== 'available'));
|
|
405
409
|
}
|
|
406
|
-
if (id === 'movement')
|
|
407
|
-
extra.push(metric(rows.filter(row => row.quantityUnit === '瓶'), 'bottles', sourceModule, '扫码数量(瓶单位记录)', '瓶'));
|
|
408
|
-
extra.push(metric(rows.filter(row => row.quantityUnit === '盒'), 'boxes', sourceModule, '扫码数量(盒单位记录)', '盒'));
|
|
409
|
-
extra.push(metric(rows, 'cases', sourceModule, '来源扫码件数', '源件数'));
|
|
410
|
-
extra.push({ label: '单位未确认记录数', unit: '条', value: sourceModule.state === 'unavailable' ? null : rows.filter(row => !['瓶', '盒'].includes(row.quantityUnit)).length, state: sourceModule.state === 'unavailable' ? 'missing' : 'available' });
|
|
411
|
-
}
|
|
410
|
+
if (id === 'movement') extra.push(metric(rows, 'cases', sourceModule, '动销件数', '件'));
|
|
412
411
|
const ratio = (numerator, denominator, ratioLabel, ratioUnit, allowed = true) => ({ label: ratioLabel, unit: ratioUnit, value: allowed && numerator !== null && denominator !== null && denominator > 0 ? numerator / denominator : null, state: allowed && numerator !== null && denominator !== null && denominator > 0 ? 'available' : 'pending', reason: '源值缺失、规则待确认或分母不大于零' });
|
|
413
412
|
if (id === 'opening') {
|
|
414
413
|
extra.push(metric(rows, 'amount', sourceModule, '开瓶金额', '元'));
|
|
@@ -430,7 +429,7 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
430
429
|
extra.push(metric(rows, 'bottles', sourceModule, '宴席开瓶', '瓶'));
|
|
431
430
|
extra.push(ratio(sum(rows, 'bottles'), sum(rows, 'events'), '场均开瓶', '瓶/场', main.state === 'available' && sourceModule.metrics.bottles?.status !== 'pending'));
|
|
432
431
|
}
|
|
433
|
-
const hasSourcePeriod = normalized[id].some(row => id === 'banquet' ? inMonths(row) : row.month && (['inventory', 'terminal'].includes(id) ? upToEnd(row) : inWindow(row)));
|
|
432
|
+
const hasSourcePeriod = normalized[id].some(row => (id !== 'movement' || isMovementCovered(row)) && (id === 'banquet' ? inMonths(row) : row.month && (['inventory', 'terminal'].includes(id) ? upToEnd(row) : inWindow(row))));
|
|
434
433
|
if (!hasSourcePeriod && sourceModule.state !== 'unavailable') for (const item of [main, ...extra]) { item.value = null; item.state = 'missing'; item.reason = '该期间无来源记录'; }
|
|
435
434
|
// One pass groups rows by month in their original order (same sums as filtering per month).
|
|
436
435
|
const scopedByMonth = new Map();
|
|
@@ -472,8 +471,18 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
472
471
|
if (sourceModule.state === 'unavailable') for (const item of [main, ...extra]) { item.value = null; item.state = sourceModule.reviewPending ? 'pending' : 'missing'; item.reason = sourceModule.reviewReason || '未接入有效来源'; }
|
|
473
472
|
if (sourceModule.reviewPending) unknownMessage.push(sourceModule.reviewReason);
|
|
474
473
|
if (rows.length === 0 && sourceModule.state !== 'unavailable') for (const item of [main, ...extra]) { item.value = null; item.state = 'missing'; item.reason = '当前范围无来源记录;不推定为业务零值'; }
|
|
474
|
+
const scopeIssue = id === 'movement' ? movementScopeIssue(f) : null;
|
|
475
|
+
if (id === 'movement') {
|
|
476
|
+
if (scopeIssue) unknownMessage.push(scopeIssue);
|
|
477
|
+
const limit = (items, reason) => {
|
|
478
|
+
if (reason) for (const item of items) Object.assign(item, { value: null, state: 'pending', reason });
|
|
479
|
+
};
|
|
480
|
+
limit([main, ...extra, ...monthly], scopeIssue);
|
|
481
|
+
limit(groups, scopeIssue || movementOrganizationIssue);
|
|
482
|
+
limit(breakdowns.flatMap(item => item.items), scopeIssue || movementProductIssue);
|
|
483
|
+
}
|
|
475
484
|
output.modules[id] = { id, title: titles[id], color: colors[id], main, extra, rows, scopedRows: scoped, recordCount: rows.length, monthly, groups, breakdowns, groupField: grouping,
|
|
476
|
-
state: sourceModule.state, period: period(id, f), pending: [...pending[id], ...unknownMessage], source: payload.sources[id] || null };
|
|
485
|
+
...(scopeIssue ? { scopeIssue } : {}), state: sourceModule.state, period: period(id, f), pending: [...pending[id], ...unknownMessage], source: payload.sources[id] || (id === 'movement' ? payload.sources.distributor : null) || null };
|
|
477
486
|
if (id === 'inventory' && inventoryHistory) {
|
|
478
487
|
const uncertain = (sourceModule.uncertaintyGroups || []).filter(group => (group.organizations || []).some(value => {
|
|
479
488
|
const parts = value.orgPath;
|
|
@@ -539,28 +548,22 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
539
548
|
reason: ok && finite(value) ? null : module.main.reason || '存在缺失或不可用源值' };
|
|
540
549
|
});
|
|
541
550
|
}
|
|
542
|
-
// 分销商动销参考:同一期间、组织与产品筛选;同比对比去年同一段日期(来源须覆盖)。
|
|
543
551
|
{
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
const rows =
|
|
549
|
-
const
|
|
550
|
-
const
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
state: finite(value) && finite(previous) && previous > 0 ? 'available' : 'pending', reason: !covered ? '分销商来源未覆盖去年同期' : !finite(previous) ? '去年同期无记录' : previous <= 0 ? '去年同期不大于零' : null, previous },
|
|
560
|
-
records: rows.length, distributors: new Set(rows.map(row => row.distributorName).filter(Boolean)).size, coverage: cover || null,
|
|
561
|
-
groups: [...groups].map(([key, list]) => ({ key, name: label(key), value: sum(list, 'amount'), records: list.length, unit: '元', state: 'available' })).sort((a, b) => (b.value ?? -Infinity) - (a.value ?? -Infinity)),
|
|
562
|
-
};
|
|
563
|
-
}
|
|
552
|
+
const module = output.modules.movement;
|
|
553
|
+
const names = { dealer: '经销商动销明细', distributor: '分销商动销明细' };
|
|
554
|
+
module.movementSources = Object.keys(names).map(key => {
|
|
555
|
+
const source = payload.movementSources?.[key], cover = source?.coverage;
|
|
556
|
+
const rows = module.rows.filter(row => row.source === key);
|
|
557
|
+
const covered = cover?.start && cover.end && p.start && p.start <= cover.end && p.end >= cover.start;
|
|
558
|
+
const reason = !source ? '未上传有效来源' : !covered ? '来源未覆盖所选期间' : !rows.length ? '当前范围无来源记录' : null;
|
|
559
|
+
const issue = (key === 'distributor' && movementScopeIssue(f))
|
|
560
|
+
|| (module.scopedRows.some(row => row.source === key && !row.date) && '存在缺失日期,无法完整分期');
|
|
561
|
+
const measure = (field, unit) => reason || issue
|
|
562
|
+
? { label: names[key], unit, value: null, state: issue ? 'pending' : 'missing', reason: issue || reason }
|
|
563
|
+
: metric(rows, field, payload.modules.movement, names[key], unit);
|
|
564
|
+
return { key, ...measure('amount', '元'), cases: measure('cases', '件'),
|
|
565
|
+
records: rows.length, coverage: cover ?? null, originalName: source?.originalName ?? null };
|
|
566
|
+
});
|
|
564
567
|
}
|
|
565
568
|
const crossMetrics = crossTableMetrics(f);
|
|
566
569
|
for (const id of ids) output.modules[id].crossMetrics = crossMetrics[id] || [];
|
|
@@ -568,10 +571,10 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
568
571
|
const structure = terminalBuilder({ terminalRows: normalized.terminal.filter(row => matchesOrg(row, f)),
|
|
569
572
|
// The builder matches exact signed organization paths itself. Retain scans
|
|
570
573
|
// with missing identities so narrowing a filter cannot turn unknowns into 0.
|
|
571
|
-
movementRows:
|
|
574
|
+
movementRows: scanModule?.records ?? [], allTerminalRows: normalized.terminal,
|
|
572
575
|
month: f.month, endDate: p.end, groupField: output.groupField, terminalState: payload.modules.terminal.state,
|
|
573
|
-
movementState:
|
|
574
|
-
sourceEnd: payload.coverage.
|
|
576
|
+
movementState: scanModule?.state ?? 'unavailable', identityState: ruleReady('terminalIdentity', ['terminal', 'scan']) ? 'confirmed' : 'pending',
|
|
577
|
+
sourceEnd: payload.coverage.scan?.end || null });
|
|
575
578
|
const terminalModule = output.modules.terminal;
|
|
576
579
|
terminalModule.structure = structure;
|
|
577
580
|
terminalModule.pending = structure.notes;
|
|
@@ -586,7 +589,7 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
586
589
|
const module = output.modules[id];
|
|
587
590
|
if (module.state === 'unavailable' || module.main.state !== 'available') return null;
|
|
588
591
|
const selected = module.rows.filter(row => row[output.groupField] === name);
|
|
589
|
-
return selected.length ? sum(selected, 'amount') : null;
|
|
592
|
+
return selected.length ? (id === 'movement' ? sumMovement(selected, 'amount') : sum(selected, 'amount')) : null;
|
|
590
593
|
};
|
|
591
594
|
return { name, invoice: groupValue('invoice'), movement: groupValue('movement') };
|
|
592
595
|
});
|
|
@@ -609,7 +612,7 @@ export function createV10Model(payload, terminalBuilder = buildTerminalStructure
|
|
|
609
612
|
// Bounds for the custom range control: every dated flow source.
|
|
610
613
|
const flowCoverage = ['invoice', 'movement', 'opening'].map(id => payload.modules[id].state !== 'unavailable' ? payload.coverage[id] : null).filter(cover => isDate(cover?.start) && isDate(cover?.end));
|
|
611
614
|
const dateBounds = flowCoverage.length ? { min: flowCoverage.map(cover => cover.start).sort()[0], max: flowCoverage.map(cover => cover.end).sort().at(-1) } : null;
|
|
612
|
-
return { ids, titles, colors, definitions, targetSource, periodOf, dateBounds, organizations, categories, months, defaults, payload, select, format, formatMetric, period, label,
|
|
615
|
+
return { ids, titles, movementShaIds, colors, definitions, targetSource, periodOf, dateBounds, organizations, categories, months, defaults, payload, select, format, formatMetric, period, label, createDecimalSum, sumDecimal,
|
|
613
616
|
scope: filters => label(filters.unit !== 'all' ? filters.unit : filters.office !== 'all' ? filters.office : filters.region !== 'all' ? filters.region : '全战区'),
|
|
614
617
|
previewNotice: '来自本次生成锁定的本机上传版本;未提供来源和待确认指标明确标示,不使用演示值。' };
|
|
615
618
|
}
|
|
@@ -39,6 +39,7 @@ export function createV10OverviewData(model, presentation) {
|
|
|
39
39
|
const fail = (reason, state = 'missing') => ({ ...pending('同期来源合计', unit, reason, state), range: { start, end } });
|
|
40
40
|
const source = model.payload.modules[id], cover = model.payload.coverage[id];
|
|
41
41
|
if (source.state === 'unavailable') return fail('未接入有效来源');
|
|
42
|
+
if (module.scopeIssue) return fail(module.scopeIssue, 'pending');
|
|
42
43
|
if (!validDate(start) || !validDate(end) || start > end) return fail('比较期间无效');
|
|
43
44
|
if (!validDate(cover?.start) || !validDate(cover?.end) || cover.start > start || cover.end < end) return fail('来源未覆盖完整比较期间');
|
|
44
45
|
if (source.metrics?.[field]?.status === 'pending') return fail('来源数值口径待确认', 'pending');
|
|
@@ -53,10 +54,11 @@ export function createV10OverviewData(model, presentation) {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
if (rows.some(row => !finite(row[field]))) return fail('比较期间存在缺失或不可用数值', 'pending');
|
|
56
|
-
const
|
|
57
|
+
const add = id === 'movement' ? model.sumDecimal : sum;
|
|
58
|
+
const value = add(rows.map(row => row[field]));
|
|
57
59
|
if (!finite(value)) return fail('来源合计超出可表示范围', 'pending');
|
|
58
60
|
return { label: '同期来源合计', unit, value, state: 'available', reason: null, range: { start, end },
|
|
59
|
-
negative: id === 'opening' ? null :
|
|
61
|
+
negative: id === 'opening' ? null : add(rows.filter(row => row.amount < 0).map(row => row.amount)) };
|
|
60
62
|
}
|
|
61
63
|
function yearComparison(id, module, filters, cumulative = false, fixedRange = null, field = null) {
|
|
62
64
|
const p = periodOf(filters), range = p.mode === 'range';
|
|
@@ -124,24 +126,17 @@ export function createV10OverviewData(model, presentation) {
|
|
|
124
126
|
return { date, value: finite(value) ? value : null, state: finite(value) ? 'available' : 'missing', reason: finite(value) ? null : '去年当日缺少有效记录,保留断点' };
|
|
125
127
|
});
|
|
126
128
|
}
|
|
127
|
-
function openingTotal(filters, module
|
|
128
|
-
const label = '
|
|
129
|
-
if (
|
|
130
|
-
// Keep a known numerator visible when only the denominator is unusable.
|
|
131
|
-
// The window and source binding remain the confirmed cross-source contract.
|
|
132
|
-
const rule = model.payload.decisionContract?.crossTableMetrics, ids = ['opening', 'movement'];
|
|
133
|
-
if (model.payload.decisionContract?.version !== 1 || rule?.status !== 'confirmed' || ids.some(id => !rule.sources?.[id] || rule.sources[id] !== model.payload.sources[id]?.sha256))
|
|
134
|
-
return pending(label, unit, '这两个来源版本的共同期间关系尚未确认');
|
|
135
|
-
if (ids.some(id => model.payload.modules[id].state === 'unavailable')) return pending(label, unit, '缺少来源,无法确认共同截止日', 'missing');
|
|
129
|
+
function openingTotal(filters, module) {
|
|
130
|
+
const label = '当年截至所选月开瓶瓶数', unit = '瓶', source = model.payload.modules.opening;
|
|
131
|
+
if (source.state === 'unavailable') return pending(label, unit, '未接入有效开瓶来源', 'missing');
|
|
136
132
|
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(filters.month || '')) return pending(label, unit, '所选月份无效,无法定位累计期间');
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
133
|
+
const cover = model.payload.coverage?.opening;
|
|
134
|
+
if (!validDate(cover?.start) || !validDate(cover?.end) || cover.start > cover.end) return pending(label, unit, '开瓶来源期间缺失或无效');
|
|
139
135
|
const p = periodOf(filters), start = `${filters.month.slice(0, 4)}-01-01`, monthEnd = p.mode === 'range' ? p.end : new Date(Date.UTC(Number(filters.month.slice(0, 4)), Number(filters.month.slice(5, 7)), 0)).toISOString().slice(0, 10);
|
|
140
|
-
const end = [monthEnd,
|
|
136
|
+
const end = [monthEnd, cover.end].sort()[0], range = { start, end };
|
|
141
137
|
const fail = (reason, state = 'pending') => ({ ...pending(label, unit, reason, state), range });
|
|
142
138
|
if (end < start) return fail('来源截止日尚未覆盖所选年度', 'unavailable');
|
|
143
|
-
|
|
144
|
-
if (covers[0].start.slice(0, 7) > start.slice(0, 7)) return fail('开瓶来源月份未覆盖累计窗口', 'unavailable');
|
|
139
|
+
if (cover.start.slice(0, 7) > start.slice(0, 7)) return fail('开瓶来源月份未覆盖累计窗口', 'unavailable');
|
|
145
140
|
if (source.records.some(row => !validDate(row.date))) return fail('开瓶来源存在日期缺失或无效,无法完整分期');
|
|
146
141
|
if (source.metrics?.bottles?.status === 'pending') return fail('开瓶瓶数来源规则或口径待确认');
|
|
147
142
|
for (let month = 1; month <= Number(end.slice(5, 7)); month++) {
|
|
@@ -149,7 +144,7 @@ export function createV10OverviewData(model, presentation) {
|
|
|
149
144
|
if (!source.records.some(row => row.date.slice(0, 7) === key && row.date <= end)) return fail('开瓶计算窗口有月份无来源记录,不能补零', 'unavailable');
|
|
150
145
|
}
|
|
151
146
|
const rows = (module.scopedRows || []).filter(row => row.date >= start && row.date <= end);
|
|
152
|
-
if (!rows.length) return fail('
|
|
147
|
+
if (!rows.length) return fail('当前组织在累计期间没有开瓶来源记录', 'missing');
|
|
153
148
|
if (rows.some(row => !finite(row.bottles))) return fail('计算窗口存在缺失或不可用开瓶瓶数');
|
|
154
149
|
let value = 0, correction = 0;
|
|
155
150
|
for (const row of rows) { const next = row.bottles - correction, updated = value + next; correction = (updated - value) - next; value = updated; }
|
|
@@ -166,10 +161,9 @@ export function createV10OverviewData(model, presentation) {
|
|
|
166
161
|
: finite(rate) ? { label: '签约有效率', unit: '%', value: rate * 100, state: 'available', reason: null,
|
|
167
162
|
numerator: totals.effectiveCount, denominator: totals.terminalCount }
|
|
168
163
|
: pending('签约有效率', '%', totals?.terminalCount === 0 ? '当前范围无签约终端,无法计算有效率' : '来源、日期、品系、件数或身份关联不足以完整判定');
|
|
169
|
-
const openingRate = copy(modules.opening.crossMetrics?.find(item => item.key === 'openingMovementRatio') || pending('总开瓶率', '%', '当前来源未确认该跨表指标'));
|
|
170
164
|
const result = { invoice: copy(modules.invoice.main), movement: copy(modules.movement.main), opening: copy(modules.opening.main), effectiveRate,
|
|
171
165
|
signed: copy(terminal.main), effectiveCount: copy(terminal.extra?.find(item => item.label === '有效终端数') || pending('有效终端数', '家', '有效终端尚未完整判定')),
|
|
172
|
-
|
|
166
|
+
openingTotal: openingTotal(filters, modules.opening),
|
|
173
167
|
ratio: copy(modules.movement.crossMetrics?.find(item => item.key === 'invoiceMovementMonthRatio')
|
|
174
168
|
|| pending('当月动销 / 开票', '%', '当前来源未确认该跨表指标')),
|
|
175
169
|
// 季度累计、季度同比与季度目标达成率(区域一览“动销/发票”视图按季度展示)。
|
|
@@ -186,7 +180,7 @@ export function createV10OverviewData(model, presentation) {
|
|
|
186
180
|
result.movementYoY = yearComparison('movement', modules.movement, filters);
|
|
187
181
|
result.openingYoY = ready(result.openingTotal) && result.openingTotal.range
|
|
188
182
|
? yearComparison('opening', modules.opening, filters, true, result.openingTotal.range)
|
|
189
|
-
: pending('累计开瓶同比', '%', result.openingTotal.reason || '
|
|
183
|
+
: pending('累计开瓶同比', '%', result.openingTotal.reason || '累计期间未确认');
|
|
190
184
|
// Cache only small display metrics, not each selection's full source arrays.
|
|
191
185
|
regionalCache.set(key, result);
|
|
192
186
|
if (regionalCache.size > 96) regionalCache.delete(regionalCache.keys().next().value);
|
|
@@ -14,7 +14,8 @@ export function createV10Overview({ T, g, model, Pn }) {
|
|
|
14
14
|
const number = (value, digits = 0) => minus(model.format(value, digits, digits));
|
|
15
15
|
const metric = (value, unit, label = '') => ({ value, unit, label, state: finite(value) ? 'available' : 'pending', reason: finite(value) ? null : '当前来源不足以完整判定' });
|
|
16
16
|
const stateText = () => '—';
|
|
17
|
-
|
|
17
|
+
// 件数最多一位小数、整数不带 .0(与详情、左侧摘要、DSH 工具一致)。
|
|
18
|
+
const valueText = (item, digits = 0) => available(item) ? item.unit === '件' ? model.format(item.value, 0, 1) : number(item.unit === '元' ? item.value / 10000 : item.value, digits) : stateText(item);
|
|
18
19
|
const reason = item => [item?.reason, ...(item?.notes || [])].filter(Boolean).join(';');
|
|
19
20
|
const extra = (module, label) => module.extra.find(item => item.label === label);
|
|
20
21
|
const cross = (module, key) => module.crossMetrics.find(item => item.key === key);
|
|
@@ -126,7 +127,16 @@ export function createV10Overview({ T, g, model, Pn }) {
|
|
|
126
127
|
el('div', { className: 'ov-heading' }, el('i', { className: 'ov-dot', 'aria-hidden': true }), el('h2', {}, module.title), el('span', { className: 'ov-action' }, '详情 →')),
|
|
127
128
|
el('p', { className: 'ov-label', title: quarter ? `${quarter.detail};累计到所选期间末日` : undefined }, el('span', {}, primaryLabel), el('span', { className: 'ov-scope-chip' }, primaryScope),
|
|
128
129
|
kind === 'invoice' && model.payload.platforms && Object.keys(model.payload.platforms).length > 0 && el('span', { className: 'ov-scope-chip is-soft', title: '发票合计含公司发票与已上传的平台订单,构成见发票详情' },
|
|
129
|
-
`含${Object.keys(model.payload.platforms).map(id => ({ zang10: '藏10', tunzhihu: '吞之乎' })[id]).join('、')}平台`)
|
|
130
|
+
`含${Object.keys(model.payload.platforms).map(id => ({ zang10: '藏10', tunzhihu: '吞之乎' })[id]).join('、')}平台`),
|
|
131
|
+
kind === 'movement' && model.payload.movementSources && (() => {
|
|
132
|
+
const src = model.payload.movementSources, has = ['dealer', 'distributor'].filter(id => src[id]), names = { dealer: '经销商', distributor: '分销商' };
|
|
133
|
+
if (!has.length) return null;
|
|
134
|
+
const ends = has.map(id => src[id]?.coverage?.end).filter(Boolean), md = day => day ? `${Number(day.slice(5, 7))}/${Number(day.slice(8, 10))}` : '未提供';
|
|
135
|
+
const align = has.length === 2 && ends.length === 2 && ends[0] !== ends[1] ? `;当前按较早日 ${[...ends].sort()[0]} 对齐(经销商截至 ${md(src.dealer.coverage.end)},分销商截至 ${md(src.distributor.coverage.end)})` : '';
|
|
136
|
+
const title = has.length === 2 ? `动销 = 经销商 + 分销商动销明细相加(口径不重叠),构成见动销详情${align}`
|
|
137
|
+
: `当前仅含${names[has[0]]}动销明细(${names[has[0] === 'dealer' ? 'distributor' : 'dealer']}动销明细未上传),构成见动销详情`;
|
|
138
|
+
return el('span', { className: 'ov-scope-chip is-soft', title }, has.length === 2 ? '含经销商、分销商' : `仅含${names[has[0]]}`);
|
|
139
|
+
})()),
|
|
130
140
|
el('div', { className: 'ov-hero-values' }, el('div', { key: `v${scopeKey}`, className: 'ov-value ov-refresh', 'data-metric': kind }, el(Value, { item: primary, digits: 2 })), el(Comparison, { key: `c${scopeKey}`, item: primaryYoY })),
|
|
131
141
|
hasTargets && quarter && el(QuarterTarget, { t: quarter }),
|
|
132
142
|
el('div', { className: 'ov-periods' },
|
|
@@ -135,7 +145,7 @@ export function createV10Overview({ T, g, model, Pn }) {
|
|
|
135
145
|
el('div', { className: 'ov-stats' },
|
|
136
146
|
el(Stat, { label: '年累计 · 1月起', name: 'ytd', item: ytd, digits: 2, unit: '万', growth: comparison.ytdYoY }),
|
|
137
147
|
el(Stat, { label: range ? '区间负金额' : '当月负金额', name: 'negative', item: negativeAmount, digits: 2, unit: '万' }),
|
|
138
|
-
movement && el(Stat, { label: '
|
|
148
|
+
movement && el(Stat, { label: filters.period === 'range' ? '区间动销件数' : '当月动销件数', name: 'count', item: view.kpis[1], unit: '件' }),
|
|
139
149
|
movement && el(Stat, { label: '累计动销比', name: 'ratio', item: ytdRatio, digits: 1, unit: '%' })),
|
|
140
150
|
el(MonthlyChart, { points: comparison.monthly, kind, filters, drill }));
|
|
141
151
|
}
|
|
@@ -264,7 +274,7 @@ export function createV10Overview({ T, g, model, Pn }) {
|
|
|
264
274
|
'aria-selected': mode === key, 'aria-controls': 'ov-region-panel', onClick: () => setMode(key), onKeyDown: event => onTabKey(event, index),
|
|
265
275
|
}, label)))),
|
|
266
276
|
el('div', { className: 'ov-region-columns' }, el('span', {}), el('span', {}, level),
|
|
267
|
-
...(mode === 'opening' ? [el('span', { key: 'total' }, '总开瓶数 / 瓶')
|
|
277
|
+
...(mode === 'opening' ? [el('span', { key: 'total' }, '总开瓶数 / 瓶')]
|
|
268
278
|
: mode === 'terminal' ? [el('span', { key: 'legend', className: 'ov-pair-legend' }, ...pairs.map(([key, label]) => el('span', { key }, el('i', { className: `ov-${key}-bar` }), label))),
|
|
269
279
|
el('span', { key: 'first' }, '签约数 / 家'), el('span', { key: 'second' }, '有效数 / 家'), el('span', { key: 'rate' }, '签约有效率')]
|
|
270
280
|
: [el('span', { key: 'goal-invoice', className: 'ov-goal-head' }, el('i', { className: 'ov-invoice-bar' }), hasTargets ? '发票季度达成' : '季度发票'),
|
|
@@ -276,8 +286,8 @@ export function createV10Overview({ T, g, model, Pn }) {
|
|
|
276
286
|
el('span', { className: 'ov-rank' }, String(index + 1).padStart(2, '0')),
|
|
277
287
|
el('span', { className: 'ov-region-name', title: row.fullName }, el('strong', {}, row.name),
|
|
278
288
|
mode === 'movement' ? el('small', { title: reason(row.quarterShare) }, '季度发票占比 ', el(Value, { item: row.quarterShare, digits: 1, unit: '%' }))
|
|
279
|
-
: el('small', {}, mode === 'terminal' ? '签约终端 · 家' : '年累计
|
|
280
|
-
...(mode === 'opening' ? [field(row, 'openingTotal')
|
|
289
|
+
: el('small', {}, mode === 'terminal' ? '签约终端 · 家' : '年累计')),
|
|
290
|
+
...(mode === 'opening' ? [field(row, 'openingTotal')]
|
|
281
291
|
: mode === 'terminal' ? [bar(row), field(row, 'signed'), field(row, 'effectiveCount'), field(row, 'effectiveRate', 1, '%')]
|
|
282
292
|
: [goalCell(row, 'invoiceQuarterAttainment', 'quarterInvoice', 'invoice', '发票'), goalCell(row, 'movementQuarterAttainment', 'quarterMovement', 'movement', '动销'),
|
|
283
293
|
quarterField(row, 'quarterInvoice', 'quarterInvoiceYoY'), quarterField(row, 'quarterMovement', 'quarterMovementYoY')]))),
|