dsh-data-dashboard 0.1.5 → 0.1.7
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 +32 -13
- package/backend/modules/banquet/index.mjs +11 -33
- package/backend/modules/distributor/index.mjs +28 -0
- package/backend/modules/opening/index.mjs +1 -1
- package/backend/modules/tunzhihu/index.mjs +27 -0
- package/backend/modules/zang10/index.mjs +30 -0
- package/backend/modules.mjs +4 -1
- package/backend/public/admin.js +15 -9
- package/backend/public/board.js +1 -1
- package/backend/real-data/generate-dashboard.mjs +11 -2
- package/backend/real-data/source-payload.mjs +116 -19
- package/backend/real-data/v10-components.mjs +5 -4
- package/backend/real-data/v10-details.mjs +27 -13
- package/backend/real-data/v10-model.mjs +59 -12
- package/backend/real-data/v10-overview-data.mjs +49 -14
- package/backend/real-data/v10-overview.css +37 -18
- package/backend/real-data/v10-overview.mjs +88 -75
- package/backend/real-data/v10-presentation.mjs +44 -30
- package/backend/real-data/v10-template.mjs +41 -5
- package/backend/review-engine.mjs +13 -2
- package/backend/server.mjs +1 -1
- package/build-manifest.json +28 -25
- package/lib/tool-definitions.mjs +2 -2
- package/lib/tools.mjs +5 -1
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// Incremental, range and full updates. Invoice, movement, opening
|
|
2
|
-
//
|
|
1
|
+
// Incremental, range and full updates. Invoice, movement, opening, inventory,
|
|
2
|
+
// banquet and the platform / distributor sources are dated (three modes); terminal is only
|
|
3
3
|
// replaced as a whole but go through the same check card. The composed
|
|
4
4
|
// workbook is written as an ordinary source so validation, inspection,
|
|
5
5
|
// review decisions and generation keep their existing contracts.
|
|
6
6
|
import ExcelJS from 'exceljs';
|
|
7
7
|
import { normalizeHeader } from '../modules.mjs';
|
|
8
|
-
import { sourceDate } from '../review-engine.mjs';
|
|
8
|
+
import { sourceDate, monthDay } from '../review-engine.mjs';
|
|
9
9
|
import { streamSheetRows } from './xlsx-rows.mjs';
|
|
10
10
|
|
|
11
11
|
export const AGGREGATE_VERSION = 2;
|
|
@@ -15,11 +15,18 @@ export const FLOW = {
|
|
|
15
15
|
movement: { date: '扫码日期', org: ['大区名称', '办事处名称'], amount: '扫码金额', quantity: '扫码件数', bottles: '扫码数量(瓶)' },
|
|
16
16
|
opening: { date: '抽奖日期', org: ['产品所属-大区', '产品所属-办事处'], city: '开瓶城市', amount: '开瓶金额', bottles: '开瓶瓶数' },
|
|
17
17
|
// Inventory: compared and replaced by the day of 提交时间, which itself keeps its seconds.
|
|
18
|
+
// 2026-11-27:藏10、吞之乎平台计入发票,分销商动销作参考;宴席改为按执行月份累加。
|
|
19
|
+
// month: 日期列只到月份,按该月 1 日参与比较与替换(同月重复上传即按月整段替换)。
|
|
20
|
+
zang10: { date: '订单归属年月', month: true, org: ['大区', '办事处'], amount: '订单金额(元)', quantity: '购货数量\n(件)' },
|
|
21
|
+
tunzhihu: { date: '业务日期', org: ['大区', '办事处'], amount: '发票金额', quantity: '数量(件)' },
|
|
22
|
+
distributor: { date: '动销日期 (日)', org: ['大区', '办事处'], amount: '总动销金额', quantity: '总动销数量' },
|
|
23
|
+
banquet: { date: '执行时间(月)', month: true, org: ['大区', '办事处'], quantity: '执行场次', bottles: '开瓶数量',
|
|
24
|
+
// 没有执行月份的行不归入任何月份、不计入;场次与开瓶都为 0 的是组织占位,有数值的在核对卡提醒。
|
|
25
|
+
skipUndated: true },
|
|
18
26
|
inventory: { date: '提交时间', time: true, org: [['大区', '大区名称'], ['办事处', '办事处名称']], dealer: '经销商编码', key: ['经销商编码', ['产品名称', '产品编码'], '提交时间'], overlapAllowed: true },
|
|
19
27
|
};
|
|
20
28
|
export const WHOLE = {
|
|
21
29
|
terminal: { date: '签约日期', agreement: '协议编号', outlet: '网点编号' },
|
|
22
|
-
banquet: { events: '执行场次', bottles: '开瓶数量' },
|
|
23
30
|
};
|
|
24
31
|
// Export scope check (contract §11.4). Empty list: the board has no such field.
|
|
25
32
|
export const SCOPE = {
|
|
@@ -29,6 +36,9 @@ export const SCOPE = {
|
|
|
29
36
|
inventory: { zone: ['战区名称'], region: ['大区', '大区名称'], product: ['产品名称', '产品编码'], productLabel: '产品' },
|
|
30
37
|
terminal: { zone: ['战区名称'], region: ['大区'], product: ['签约品种'], productLabel: '签约品种' },
|
|
31
38
|
banquet: { zone: [], region: ['大区'], product: [], productLabel: '产品' },
|
|
39
|
+
zang10: { zone: ['战区'], region: ['大区'], product: [], productLabel: '产品' },
|
|
40
|
+
tunzhihu: { zone: ['战区'], region: ['大区'], product: [], productLabel: '产品' },
|
|
41
|
+
distributor: { zone: ['战区'], region: ['大区'], product: [], productLabel: '产品' },
|
|
32
42
|
};
|
|
33
43
|
export const PRODUCT_RULE = { windowMin: 3, fileMax: 1, minRows: 20, fallbackDays: 30 };
|
|
34
44
|
export const MODES = ['incremental', 'range', 'full'];
|
|
@@ -95,7 +105,7 @@ const keyText = value => value instanceof Date ? value.toISOString() : text(valu
|
|
|
95
105
|
export async function streamSource(file, validation, moduleId, onHeader, onRow) {
|
|
96
106
|
const spec = FLOW[moduleId];
|
|
97
107
|
const headerRow = validation.headerRow ?? 1;
|
|
98
|
-
let headers = null, dateColumn = -1;
|
|
108
|
+
let headers = null, dateColumn = -1, get = null;
|
|
99
109
|
// date1904 is filled in once workbook.xml has been read, before any row.
|
|
100
110
|
const date1904Ref = { value: false };
|
|
101
111
|
const result = await streamSheetRows(file, validation.sheet, async (rowNumber, cells) => {
|
|
@@ -104,6 +114,7 @@ export async function streamSource(file, validation, moduleId, onHeader, onRow)
|
|
|
104
114
|
headers = cells.map(value => text(plain(value)));
|
|
105
115
|
while (headers.length && !headers.at(-1)) headers.pop();
|
|
106
116
|
dateColumn = headers.findIndex(header => normalizeHeader(header) === normalizeHeader(spec.date));
|
|
117
|
+
get = accessor(headers);
|
|
107
118
|
if (dateColumn < 0) throw new Error(`缺少日期字段:${spec.date}。`);
|
|
108
119
|
await onHeader({ sheetName: validation.sheet, headers, dateColumn, format: validation.sourceFormat ?? null });
|
|
109
120
|
return;
|
|
@@ -112,10 +123,11 @@ export async function streamSource(file, validation, moduleId, onHeader, onRow)
|
|
|
112
123
|
const values = headers.map((_, index) => plain(cells[index] ?? null));
|
|
113
124
|
if (!values.some(value => text(value) !== '')) return;
|
|
114
125
|
const raw = values[dateColumn];
|
|
115
|
-
const day = sourceDate(raw, date1904Ref.value);
|
|
126
|
+
const day = spec.month ? monthDay(raw, date1904Ref.value) : sourceDate(raw, date1904Ref.value);
|
|
127
|
+
if (!day && spec.skipUndated) { await onRow({ row: rowNumber, values, date: null, skipped: true, valued: [spec.quantity, spec.bottles].filter(Boolean).some(name => number(get(values, name))) }); return; }
|
|
116
128
|
// Numeric serial dates are rewritten as dates so the 1900/1904 base of the
|
|
117
129
|
// composed workbook cannot shift them. Inventory keeps the time of day.
|
|
118
|
-
if (day && typeof raw === 'number') values[dateColumn] = spec.time ? serialDateTime(raw, date1904Ref.value) : new Date(`${day}T00:00:00Z`);
|
|
130
|
+
if (day && typeof raw === 'number' && !spec.month) values[dateColumn] = spec.time ? serialDateTime(raw, date1904Ref.value) : new Date(`${day}T00:00:00Z`);
|
|
119
131
|
await onRow({ row: rowNumber, values, date: day });
|
|
120
132
|
}, date1904Ref);
|
|
121
133
|
if (!headers) throw new Error('已验证的工作表无法读取。');
|
|
@@ -139,11 +151,12 @@ function scopeHas(get, moduleId) {
|
|
|
139
151
|
|
|
140
152
|
/** Per-day totals, organizations and scope values, small enough to keep beside a source. */
|
|
141
153
|
export function aggregator(moduleId) {
|
|
142
|
-
const spec = FLOW[moduleId], scope = SCOPE[moduleId], byDate = {}, invalidRows = [], zones = new Set(), days = new Map();
|
|
154
|
+
const spec = FLOW[moduleId], scope = SCOPE[moduleId], byDate = {}, invalidRows = [], zones = new Set(), days = new Map(), skipped = { rows: 0, valued: [], bottles: 0 };
|
|
143
155
|
let get = null, headers = [], rows = 0, format = null;
|
|
144
156
|
return {
|
|
145
157
|
header(info) { headers = info.headers; format = info.format ?? null; get = accessor(info.headers); },
|
|
146
|
-
row({ row, values, date }) {
|
|
158
|
+
row({ row, values, date, skipped: skip, valued }) {
|
|
159
|
+
if (skip) { skipped.rows++; if (valued) { skipped.valued.push(row); skipped.bottles += spec.bottles ? number(get(values, spec.bottles)) ?? 0 : 0; } return; }
|
|
147
160
|
rows++;
|
|
148
161
|
addTo(zones, get(values, scope.zone));
|
|
149
162
|
if (!date) { invalidRows.push(row); return; }
|
|
@@ -171,6 +184,7 @@ export function aggregator(moduleId) {
|
|
|
171
184
|
const dates = Object.keys(byDate).sort();
|
|
172
185
|
return { version: AGGREGATE_VERSION, moduleId, format, rows, start: dates[0] ?? null, end: dates.at(-1) ?? null,
|
|
173
186
|
invalidDateRows: invalidRows.length, invalidDateSample: invalidRows.slice(0, 20), byDate, headers,
|
|
187
|
+
skippedRows: skipped.rows, skippedValuedRows: skipped.valued.length, skippedValuedSample: skipped.valued.slice(0, 20), skippedBottles: round(skipped.bottles),
|
|
174
188
|
has: get ? scopeHas(get, moduleId) : { zone: false, region: false, product: false }, zones: sorted(zones), regions: sorted(regions), products: sorted(products) };
|
|
175
189
|
},
|
|
176
190
|
};
|
|
@@ -251,7 +265,9 @@ export function suggestMode(base, part) {
|
|
|
251
265
|
const overlap = Object.keys(part.byDate).filter(day => base.byDate[day]);
|
|
252
266
|
if (!overlap.length) return { mode: 'incremental', start: part.start, end: part.end, reason: '文件里全部是新日期,直接追加。' };
|
|
253
267
|
if (part.start <= base.start && part.end >= base.end) return { mode: 'full', start: part.start, end: part.end, reason: '文件覆盖了当前全部日期,整份替换。' };
|
|
254
|
-
|
|
268
|
+
// 月度板块(日期列只到月份)按月计数,同月重传即替换该月。
|
|
269
|
+
const unit = FLOW[part.moduleId]?.month ? '个月' : '天';
|
|
270
|
+
return { mode: 'range', start: part.start, end: part.end, reason: `与现有数据有 ${overlap.length} ${unit}重叠,按文件日期范围整段替换。` };
|
|
255
271
|
}
|
|
256
272
|
|
|
257
273
|
/** Totals over several (byDate, days) parts; dealers are counted once across parts. */
|
|
@@ -275,10 +291,13 @@ const months = days => [...new Set(days.map(day => day.slice(0, 7)))].sort();
|
|
|
275
291
|
const FIGURES = {
|
|
276
292
|
invoice: [['行数', 'rows', 'count'], ['发票净额(万元)', 'amount', 'wan']],
|
|
277
293
|
movement: [['行数', 'rows', 'count'], ['扫码金额(万元)', 'amount', 'wan'], ['扫码件数', 'quantity', 'count'], ['扫码瓶数', 'bottles', 'count']],
|
|
278
|
-
opening: [['行数', 'rows', 'count'], ['开瓶瓶数', 'bottles', 'count'], ['
|
|
294
|
+
opening: [['行数', 'rows', 'count'], ['开瓶瓶数', 'bottles', 'count'], ['开瓶金额(万元)', 'amount', 'wan']],
|
|
279
295
|
inventory: [['盘点记录', 'rows', 'count'], ['经销商', 'dealers', 'count']],
|
|
280
296
|
terminal: [['协议数', 'agreements', 'count'], ['签约终端', 'outlets', 'count']],
|
|
281
|
-
banquet: [['执行场次', '
|
|
297
|
+
banquet: [['执行场次', 'quantity', 'count'], ['开瓶瓶数', 'bottles', 'count']],
|
|
298
|
+
zang10: [['行数', 'rows', 'count'], ['订单金额(万元)', 'amount', 'wan']],
|
|
299
|
+
tunzhihu: [['行数', 'rows', 'count'], ['发票金额(万元)', 'amount', 'wan']],
|
|
300
|
+
distributor: [['行数', 'rows', 'count'], ['动销金额(万元)', 'amount', 'wan']],
|
|
282
301
|
};
|
|
283
302
|
const figures = (moduleId, before, after) => FIGURES[moduleId].map(([label, key, unit]) => ({ label, key, unit, before: before ? before[key] ?? null : null, after: after ? after[key] ?? null : null }));
|
|
284
303
|
const listText = (values, limit = 3) => `${values.slice(0, limit).join('、')}${values.length > limit ? ` 等 ${values.length} 个` : ''}`;
|
|
@@ -334,6 +353,7 @@ export function receipt({ moduleId, base, part, mode, start, end, existingByDate
|
|
|
334
353
|
const baseBy = base?.byDate ?? {}, partBy = part.byDate;
|
|
335
354
|
const partDays = Object.keys(partBy).sort(), baseAll = Object.keys(baseBy);
|
|
336
355
|
if (!part.rows) blocked.push('文件没有数据行。');
|
|
356
|
+
if (part.skippedValuedRows) warnings.push(`${part.skippedValuedRows} 行没有${spec.date}却有数值(开瓶 ${part.skippedBottles} 瓶;Excel 行号:${part.skippedValuedSample.join('、')}${part.skippedValuedRows > part.skippedValuedSample.length ? '等' : ''}),不归入任何月份、不计入。`);
|
|
337
357
|
if (part.invalidDateRows) blocked.push(`${part.invalidDateRows} 行${spec.date}无效(Excel 行号:${part.invalidDateSample.join('、')}${part.invalidDateRows > part.invalidDateSample.length ? '等' : ''}),请修正后重新导出。`);
|
|
338
358
|
if (mode !== 'full' && base && (base.format ?? null) !== (part.format ?? null)) blocked.push('文件格式与当前数据不同,只能整份替换。');
|
|
339
359
|
let window, after, before, disappearing = [], missing = { regions: [], offices: [], cities: [] };
|
|
@@ -409,7 +429,6 @@ export function wholeReceipt({ moduleId, base, part, mode = 'full' }) {
|
|
|
409
429
|
if (base.end && part.end && part.end < base.end) warnings.push(`签约日期最新只到 ${part.end},早于当前数据的 ${base.end}。`);
|
|
410
430
|
}
|
|
411
431
|
}
|
|
412
|
-
if (moduleId === 'banquet') notes.push('宴席表没有日期列;新文件的统计期间需要在导入检查中重新确认。');
|
|
413
432
|
const scope = scopeCheck(moduleId, base, part);
|
|
414
433
|
blocked.push(...scope.blocked);
|
|
415
434
|
return {
|
|
@@ -1,46 +1,24 @@
|
|
|
1
1
|
import { defineModule } from '../../recognition/module-definition.mjs';
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
// Detailed sources still require review; this contract only validates structure.
|
|
3
|
+
// 宴席执行(固定模板,2026-11-27 用户确认):每行是 执行月份 × 经销商 × 用酒品种,可直接相加。
|
|
5
4
|
export default defineModule({
|
|
6
5
|
"id": "banquet",
|
|
7
6
|
"title": "宴席执行",
|
|
8
|
-
"description": "
|
|
7
|
+
"description": "按月份的宴席执行场次与开瓶数量",
|
|
9
8
|
"sheetNames": [
|
|
10
9
|
"报表"
|
|
11
10
|
],
|
|
12
11
|
"notes": [
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"已核对简化表中的上下级同名行属于组织占位,汇总时与其他单元一起计入;保留大区、办事处、主任单元的完整路径。新来源的同名层级性质需重新核对。",
|
|
17
|
-
"非空行数不代表有效业务行数或执行场次;重复记录、组织汇总行和总计行仍需逐行核对,业务口径确认不等于业务校验已执行。",
|
|
18
|
-
"宴席开瓶与消费者开瓶分开统计,不合并两者数量;两份来源是否重叠未作核实。"
|
|
12
|
+
"按“执行时间(月)”归月,跟随月份与日期区间筛选(区间按覆盖到的整月);不随产品筛选。",
|
|
13
|
+
"执行场次、开瓶数量按原值相加;没有执行月份且场次、开瓶均为 0 的行视为组织占位,跳过。",
|
|
14
|
+
"宴席开瓶与消费者开瓶分开统计,不合并两者数量。"
|
|
19
15
|
],
|
|
20
16
|
"fields": [
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
"header": "办事处"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"key": "directorUnit",
|
|
31
|
-
"header": "主任单元"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"key": "outletReward",
|
|
35
|
-
"header": "售点推荐奖励"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"key": "eventCount",
|
|
39
|
-
"header": "执行场次"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"key": "openingQuantity",
|
|
43
|
-
"header": "开瓶数量"
|
|
44
|
-
}
|
|
17
|
+
{ "key": "executionMonth", "header": "执行时间(月)" },
|
|
18
|
+
{ "key": "region", "header": "大区" },
|
|
19
|
+
{ "key": "office", "header": "办事处" },
|
|
20
|
+
{ "key": "directorUnit", "header": "主任单元" },
|
|
21
|
+
{ "key": "eventCount", "header": "执行场次" },
|
|
22
|
+
{ "key": "openingQuantity", "header": "开瓶数量" }
|
|
45
23
|
]
|
|
46
24
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineModule } from '../../recognition/module-definition.mjs';
|
|
2
|
+
|
|
3
|
+
// 分销商动销(高端产品)。只作动销详情里的参考展示,不并入动销合计:
|
|
4
|
+
// 2026-11-27 核对发现它与终端扫码多为同一批交易,且两表没有共同单号,无法逐笔去重。
|
|
5
|
+
export default defineModule({
|
|
6
|
+
"id": "distributor",
|
|
7
|
+
"title": "分销商动销",
|
|
8
|
+
"description": "高端产品分销商出库,动销参考",
|
|
9
|
+
"sheetNames": [
|
|
10
|
+
"分销商动销明细"
|
|
11
|
+
],
|
|
12
|
+
"notes": [
|
|
13
|
+
"只在终端动销详情中单独展示,不计入动销合计、动销达成或跨表比例(用户 2026-11-27 选择方案 A)。",
|
|
14
|
+
"按“动销日期 (日)”归属日期;“总动销金额”单位元,退货与补录扣减按原负值计入。"
|
|
15
|
+
],
|
|
16
|
+
"fields": [
|
|
17
|
+
{ "key": "date", "header": "动销日期 (日)" },
|
|
18
|
+
{ "key": "distributorName", "header": "分销商名称" },
|
|
19
|
+
{ "key": "distributorCode", "header": "分销商编码" },
|
|
20
|
+
{ "key": "region", "header": "大区" },
|
|
21
|
+
{ "key": "office", "header": "办事处" },
|
|
22
|
+
{ "key": "directorUnit", "header": "客户主任单元" },
|
|
23
|
+
{ "key": "productName", "header": "产品名称" },
|
|
24
|
+
{ "key": "documentCode", "header": "单据编码" },
|
|
25
|
+
{ "key": "quantity", "header": "总动销数量" },
|
|
26
|
+
{ "key": "amount", "header": "总动销金额" }
|
|
27
|
+
]
|
|
28
|
+
});
|
|
@@ -13,7 +13,7 @@ export default defineModule({
|
|
|
13
13
|
"按抽奖日期归属开瓶统计期间,用于日期范围和月份筛选。",
|
|
14
14
|
"组织归属使用产品所属的大区、办事处、主任单元完整路径;开瓶城市不能替代组织归属。",
|
|
15
15
|
"当前按源表已有汇总数据读取;非空行数不能作为开瓶瓶数或扫码事件数。",
|
|
16
|
-
"
|
|
16
|
+
"开瓶金额为开瓶产品金额(2026-11-27 用户确认,此前误作现金红包),源数值单位为元,按原值读取,界面以万元显示。"
|
|
17
17
|
],
|
|
18
18
|
"fields": [
|
|
19
19
|
{
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineModule } from '../../recognition/module-definition.mjs';
|
|
2
|
+
|
|
3
|
+
// 吞之乎平台销售(固定模板,2026-11-27 用户确认)。只读“订单”工作表并计入发票销售;同文件的“动销”页不参与计算。
|
|
4
|
+
export default defineModule({
|
|
5
|
+
"id": "tunzhihu",
|
|
6
|
+
"title": "吞之乎平台销售",
|
|
7
|
+
"description": "吞之乎平台订单,计入发票销售",
|
|
8
|
+
"sheetNames": [
|
|
9
|
+
"订单"
|
|
10
|
+
],
|
|
11
|
+
"notes": [
|
|
12
|
+
"按“发票金额”计入发票,单位元、含税,正负按原值;单据类型 XS 与 zk3(现金折扣)都计入(用户 2026-11-27 确认)。",
|
|
13
|
+
"按“业务日期”归属日期;“动销”工作表不参与计算,动销以分销商动销与终端扫码为准。",
|
|
14
|
+
"表内只有大区、办事处、主任单元三级组织,按名称挂到其他来源的完整组织路径;挂不上的保留为“上级未提供”。"
|
|
15
|
+
],
|
|
16
|
+
"fields": [
|
|
17
|
+
{ "key": "businessDate", "header": "业务日期" },
|
|
18
|
+
{ "key": "orderCode", "header": "订单编号" },
|
|
19
|
+
{ "key": "region", "header": "大区" },
|
|
20
|
+
{ "key": "office", "header": "办事处" },
|
|
21
|
+
{ "key": "directorUnit", "header": "主任单元" },
|
|
22
|
+
{ "key": "dealerName", "header": "销管客户名称" },
|
|
23
|
+
{ "key": "productName", "header": "产品名称" },
|
|
24
|
+
{ "key": "invoiceAmount", "header": "发票金额" },
|
|
25
|
+
{ "key": "documentType", "header": "单据类型" }
|
|
26
|
+
]
|
|
27
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineModule } from '../../recognition/module-definition.mjs';
|
|
2
|
+
|
|
3
|
+
// 藏10平台销售(固定模板,2026-11-27 用户确认)。计入发票销售,与公司发票分开上传、分开留痕。
|
|
4
|
+
export default defineModule({
|
|
5
|
+
"id": "zang10",
|
|
6
|
+
"title": "藏10平台销售",
|
|
7
|
+
"description": "藏10平台订单,计入发票销售",
|
|
8
|
+
"sheetNames": [
|
|
9
|
+
"工作表1",
|
|
10
|
+
"藏10平台销售"
|
|
11
|
+
],
|
|
12
|
+
"notes": [
|
|
13
|
+
"按“订单金额(元)”计入发票,单位元、含税,正负都按原值计入;首单标记、账务类型、藏10/藏8 不作筛选,全部计入(用户 2026-11-27 确认)。",
|
|
14
|
+
"按“订单归属年月”归月:订单所在日期在归属月内时用订单所在日期,否则记为归属月 1 日。",
|
|
15
|
+
"表内只有大区、办事处、客户主任单元三级组织,按名称挂到其他来源的完整组织路径;挂不上的保留为“上级未提供”,不丢弃。"
|
|
16
|
+
],
|
|
17
|
+
"fields": [
|
|
18
|
+
{ "key": "attributionMonth", "header": "订单归属年月" },
|
|
19
|
+
{ "key": "orderYear", "header": "订单所在年" },
|
|
20
|
+
{ "key": "orderMonth", "header": "订单所在月" },
|
|
21
|
+
{ "key": "orderDay", "header": "订单所在日" },
|
|
22
|
+
{ "key": "orderCode", "header": "订单编号" },
|
|
23
|
+
{ "key": "region", "header": "大区" },
|
|
24
|
+
{ "key": "office", "header": "办事处" },
|
|
25
|
+
{ "key": "directorUnit", "header": "客户主任单元" },
|
|
26
|
+
{ "key": "dealerName", "header": "购货经销商名称" },
|
|
27
|
+
{ "key": "productName", "header": "购货产品标准名称" },
|
|
28
|
+
{ "key": "orderAmount", "header": "订单金额(元)" }
|
|
29
|
+
]
|
|
30
|
+
});
|
package/backend/modules.mjs
CHANGED
|
@@ -5,8 +5,11 @@ import terminal from './modules/terminal/index.mjs';
|
|
|
5
5
|
import inventory from './modules/inventory/index.mjs';
|
|
6
6
|
import banquet from './modules/banquet/index.mjs';
|
|
7
7
|
import target from './modules/target/index.mjs';
|
|
8
|
+
import zang10 from './modules/zang10/index.mjs';
|
|
9
|
+
import tunzhihu from './modules/tunzhihu/index.mjs';
|
|
10
|
+
import distributor from './modules/distributor/index.mjs';
|
|
8
11
|
|
|
9
12
|
// Shared registration only. Module branches edit their own directory.
|
|
10
|
-
export const moduleDefinitions = [invoice, movement, opening, terminal, inventory, banquet, target];
|
|
13
|
+
export const moduleDefinitions = [invoice, movement, opening, terminal, inventory, banquet, target, zang10, tunzhihu, distributor];
|
|
11
14
|
export const moduleById = new Map(moduleDefinitions.map(module => [module.id, module]));
|
|
12
15
|
export { normalizeHeader } from './recognition/headers.mjs';
|
package/backend/public/admin.js
CHANGED
|
@@ -4,7 +4,7 @@ if (new URLSearchParams(location.search).has('embed')) document.documentElement.
|
|
|
4
4
|
|
|
5
5
|
const $ = selector => document.querySelector(selector);
|
|
6
6
|
const rows = new Map();
|
|
7
|
-
const preferredOrder = ['invoice', 'movement', 'opening', 'terminal', 'inventory', 'banquet', 'target'];
|
|
7
|
+
const preferredOrder = ['invoice', 'zang10', 'tunzhihu', 'movement', 'distributor', 'opening', 'terminal', 'inventory', 'banquet', 'target'];
|
|
8
8
|
let state = null;
|
|
9
9
|
let working = null;
|
|
10
10
|
let connected = false;
|
|
@@ -22,6 +22,9 @@ const iconPaths = {
|
|
|
22
22
|
inventory: '<path d="m12 2 9 5v10l-9 5-9-5V7zm-9 5 9 5 9-5M12 12v10M7 4.8l10 5.5v6"/>',
|
|
23
23
|
banquet: '<path d="m3 21 4-14 10 10zm4-14 10 10M13 3l1 4m4-2 2-2m-2 7 4 1m-1 5 2 1M8 13l3 3"/>',
|
|
24
24
|
target: '<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1"/>',
|
|
25
|
+
zang10: '<path d="M4 3h16v18l-3-2-3 2-3-2-3 2-4-2zM8 8h8m-8 4h5"/><circle cx="16" cy="14" r="2"/>',
|
|
26
|
+
tunzhihu: '<path d="M4 3h16v18l-3-2-3 2-3-2-3 2-4-2zM8 8h8m-8 4h5"/><path d="M15 12l2 2 3-3"/>',
|
|
27
|
+
distributor: '<path d="M3 7h11v9H3zM14 10h4l3 3v3h-7M7 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm10 0a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/>',
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
function element(tag, className, text) {
|
|
@@ -131,11 +134,11 @@ const selectedUpload = module => module?.candidateUpload || module?.activeUpload
|
|
|
131
134
|
function rangeText(module, upload) {
|
|
132
135
|
if (!upload) return '尚未上传';
|
|
133
136
|
const count = `${Number(upload.validation?.rowCount || 0).toLocaleString('zh-CN')} 行`;
|
|
134
|
-
if (module.id === 'banquet') return `无日期列 · ${count}`;
|
|
135
137
|
if (module.id === 'target') return count;
|
|
136
138
|
if (!upload.coverage) return '正在计算数据起止日…';
|
|
137
139
|
if (!upload.coverage.start) return '—';
|
|
138
|
-
const prefix = { terminal: '签约日期 ', inventory: '提交时间 ' }[module.id] || '';
|
|
140
|
+
const prefix = { terminal: '签约日期 ', inventory: '提交时间 ', banquet: '执行月份 ', zang10: '归属月份 ' }[module.id] || '';
|
|
141
|
+
if (['banquet', 'zang10'].includes(module.id)) return `${prefix}${upload.coverage.start.slice(0, 7)} ~ ${upload.coverage.end.slice(0, 7)}`;
|
|
139
142
|
return `${prefix}${upload.coverage.start} ~ ${upload.coverage.end}`;
|
|
140
143
|
}
|
|
141
144
|
function versionText(upload) {
|
|
@@ -365,10 +368,12 @@ function applyState(next) {
|
|
|
365
368
|
lastReceipt.generating = false;
|
|
366
369
|
lastReceipt.foot = current.status === 'failed' ? `看板生成失败:${current.error || '请稍后重试'}。资料已更新,可直接重新生成。` : current.needsReview ? '已生成待确认版本,当前看板未替换。收到的原文件都保存在本机。'
|
|
367
370
|
: document.documentElement.classList.contains('embedded') ? '看板已生成并切到「看板」页。收到的原文件都保存在本机。' : '看板已生成,可在下方“生成记录”查看。收到的原文件都保存在本机。';
|
|
371
|
+
if (current.status === 'completed' && current.skippedModules?.length) lastReceipt.foot += ` ${current.skippedModules.map(item => item.title).join('、')}模板已更新,旧文件本次未计入,请按新模板重新上传。`;
|
|
368
372
|
renderReceipt();
|
|
369
373
|
}
|
|
374
|
+
const skippedNote = current?.skippedModules?.length ? ` 注意:${current.skippedModules.map(item => item.title).join('、')}模板已更新,旧文件本次未计入,请按新模板重新上传。` : '';
|
|
370
375
|
if (current?.status === 'completed') {
|
|
371
|
-
setNotice(current.needsReview ? '待确认版本已生成。相关汇总及关联指标保持待确认,请在生成记录中查看;最近正常版本入口未被替换。' : current.mode === 'real' ? '真实数据看板已生成,使用本次开始生成时锁定的来源。可在“生成记录”中查看或下载 HTML;缺失来源和待确认指标已明确标注。' : '历史演示看板已生成。请查看生成记录中的模式说明。');
|
|
376
|
+
setNotice(skippedNote ? skippedNote.trim() : current.needsReview ? '待确认版本已生成。相关汇总及关联指标保持待确认,请在生成记录中查看;最近正常版本入口未被替换。' : current.mode === 'real' ? '真实数据看板已生成,使用本次开始生成时锁定的来源。可在“生成记录”中查看或下载 HTML;缺失来源和待确认指标已明确标注。' : '历史演示看板已生成。请查看生成记录中的模式说明。');
|
|
372
377
|
trackedGeneration = null;
|
|
373
378
|
} else if (current?.status === 'failed') {
|
|
374
379
|
setNotice(`生成失败:${current.error || '请检查后台状态后重试。'}`, true);
|
|
@@ -399,7 +404,7 @@ let generateAfterBatch = false;
|
|
|
399
404
|
let lastReceipt = null;
|
|
400
405
|
const moduleOf = id => state?.modules?.find(module => module.id === id) || null;
|
|
401
406
|
const moduleTitle = id => moduleOf(id)?.title || '';
|
|
402
|
-
const SHORT = { invoice: '发票', movement: '动销', opening: '开瓶', inventory: '库存', terminal: '签约', banquet: '宴席', target: '目标' };
|
|
407
|
+
const SHORT = { invoice: '发票', movement: '动销', opening: '开瓶', inventory: '库存', terminal: '签约', banquet: '宴席', target: '目标', zang10: '藏10', tunzhihu: '吞之乎', distributor: '分销商' };
|
|
403
408
|
const shortTitle = id => SHORT[id] || moduleTitle(id);
|
|
404
409
|
const isUpdatable = id => Boolean(moduleOf(id)?.updatable);
|
|
405
410
|
const modesOf = id => moduleOf(id)?.modes || [];
|
|
@@ -514,7 +519,7 @@ function checkCard(item, counts) {
|
|
|
514
519
|
head.append(select);
|
|
515
520
|
} else head.append(element('b', 'check-board', moduleTitle(item.moduleId)));
|
|
516
521
|
const r = item.receipt;
|
|
517
|
-
const dateLabel = { terminal: '签约日期', inventory: '提交时间' }[item.moduleId] || '文件日期';
|
|
522
|
+
const dateLabel = { terminal: '签约日期', inventory: '提交时间', banquet: '执行月份', zang10: '归属月份' }[item.moduleId] || '文件日期';
|
|
518
523
|
const fileInfo = r?.file?.start ? `${item.file.name} · ${dateLabel} ${dayRange(r.file.start, r.file.end)}` : item.moduleId === 'banquet' && r ? `${item.file.name} · ${countText(r.file.rows)} 行` : item.file.name;
|
|
519
524
|
const file = element('span', 'check-file', fileInfo); file.title = item.file.name;
|
|
520
525
|
head.append(file);
|
|
@@ -564,7 +569,7 @@ function checkCard(item, counts) {
|
|
|
564
569
|
}
|
|
565
570
|
card.append(range);
|
|
566
571
|
}
|
|
567
|
-
const compact =
|
|
572
|
+
const compact = false;
|
|
568
573
|
if (compact) {
|
|
569
574
|
const [events, bottles] = r.figures;
|
|
570
575
|
card.append(element('p', 'check-note', `执行场次 ${countText(events.before)} → ${countText(events.after)} · 开瓶 ${countText(bottles.before)} → ${countText(bottles.after)} 瓶。${(r.notes || []).join('')}`));
|
|
@@ -676,8 +681,9 @@ function changeText(item) {
|
|
|
676
681
|
const arrow = key => { const value = figure(key); return value ? `${countText(value.before)} → ${countText(value.after)}` : ''; };
|
|
677
682
|
const auto = isUpdatable(item.moduleId) && modesOf(item.moduleId).length > 1 ? `(${item.modeAuto ? '系统建议' : '手动'})` : '';
|
|
678
683
|
const what = item.mode === 'range' ? `范围更新 ${dayRange(r.start, r.end)}${auto}` : item.mode === 'incremental' ? `增量追加 ${dayRange(r.file.start, r.file.end)}${auto}` : `整份替换${auto}`;
|
|
679
|
-
const core = { invoice: `净额 ${delta('amount', ' 万元')}`, movement: `扫码金额 ${delta('amount', ' 万元')}`, opening:
|
|
680
|
-
terminal: `协议 ${arrow('agreements')}${r.disappearingAgreements ? `(已确认 ${countText(r.disappearingAgreements)} 份消失)` : ''}`, banquet: `场次 ${
|
|
684
|
+
const core = { invoice: `净额 ${delta('amount', ' 万元')}`, movement: `扫码金额 ${delta('amount', ' 万元')}`, opening: `开瓶金额 ${delta('amount', ' 万元')}`, inventory: `${delta('rows', '')} 条盘点`,
|
|
685
|
+
terminal: `协议 ${arrow('agreements')}${r.disappearingAgreements ? `(已确认 ${countText(r.disappearingAgreements)} 份消失)` : ''}`, banquet: `场次 ${delta('quantity', ' 场')}`,
|
|
686
|
+
zang10: `订单金额 ${delta('amount', ' 万元')}`, tunzhihu: `发票金额 ${delta('amount', ' 万元')}`, distributor: `动销金额 ${delta('amount', ' 万元')}` }[item.moduleId] || '';
|
|
681
687
|
return [what, core].filter(Boolean).join(',');
|
|
682
688
|
}
|
|
683
689
|
function renderReceipt() {
|
package/backend/public/board.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Merged page: latest dashboard, the update page and generation history in
|
|
4
4
|
// one place. Dashboards stay independent offline HTML files.
|
|
5
5
|
const $ = selector => document.querySelector(selector);
|
|
6
|
-
const titles = { invoice: '发票', movement: '动销', opening: '开瓶', terminal: '签约', inventory: '库存', banquet: '宴席', target: '目标' };
|
|
6
|
+
const titles = { invoice: '发票', movement: '动销', opening: '开瓶', terminal: '签约', inventory: '库存', banquet: '宴席', target: '目标', zang10: '藏10', tunzhihu: '吞之乎', distributor: '分销商' };
|
|
7
7
|
let state = null, viewingId = null, known = null, followLatest = true, toastTimer = null;
|
|
8
8
|
const openMapping = new Set();
|
|
9
9
|
const updateFrame = $('#update-frame');
|
|
@@ -96,8 +96,17 @@ export async function generateDashboard({ project, dataDir, sourceVersions, outp
|
|
|
96
96
|
const { payload, report } = await build({ dataDir, decisionsFile: decisionBefore ? decisionsFile : undefined, sourceVersions, allowPending, rowCache: true });
|
|
97
97
|
if (!payload?.sources || !payload?.modules || report?.activeChangedDuringRead) throw new Error('有效上传版本读取不完整或已发生变化,请重新生成。');
|
|
98
98
|
if (report.decisionError) throw new Error(report.decisionError);
|
|
99
|
+
// 模板已更新、旧文件通不过当前表头校验的板块:本次跳过并在看板与生成记录中提示重传,其他板块照常生成。
|
|
100
|
+
const skippedModules = [];
|
|
99
101
|
for (const [id, expected] of Object.entries(sourceVersions)) {
|
|
100
102
|
const source = payload.sources[id], module = payload.modules[id];
|
|
103
|
+
if (!source && module?.state === 'unavailable' && /^工作簿结构校验失败/.test(module.reason || '')) {
|
|
104
|
+
const reason = `${module.reason.replace(/。$/, '')}。该板块模板已更新,请按新模板重新上传;本次看板不含此板块。`;
|
|
105
|
+
Object.assign(module, { reason, records: [], metrics: {} });
|
|
106
|
+
(module.warnings ||= []).push(reason);
|
|
107
|
+
skippedModules.push({ moduleId: id, title: titles[id], uploadId: expected.uploadId, reason });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
101
110
|
if (!source || source.uploadId !== expected.uploadId || source.sha256 !== expected.sha256) throw new Error(`${titles[id]}未使用锁定的有效上传版本:${module?.reason || '请重新上传并检查来源。'}`);
|
|
102
111
|
if (!['ready', 'partial'].includes(module?.state) && !(allowPending && report.modules?.[id]?.reviewPending)) throw new Error(`${titles[id]}无法计算:${module?.reason || '请核对该板块资料及已确认规则。'}`);
|
|
103
112
|
}
|
|
@@ -110,7 +119,7 @@ export async function generateDashboard({ project, dataDir, sourceVersions, outp
|
|
|
110
119
|
const rendered = await render(payload);
|
|
111
120
|
if (typeof rendered?.html !== 'string' || !rendered.html.includes('</html>')) throw new Error('未生成有效的离线 HTML。');
|
|
112
121
|
const reviewSummary = { pendingCount: pendingModules.reduce((count, id) => count + (report.modules[id].review?.pendingCount || 1), 0), modules: pendingModules,
|
|
113
|
-
sources: Object.entries(sourceVersions).map(([id]) => ({ moduleId: id, filename: payload.sources[id]
|
|
122
|
+
sources: Object.entries(sourceVersions).map(([id]) => ({ moduleId: id, filename: payload.sources[id]?.originalName ?? null, sha256: payload.sources[id]?.sha256 ?? null, groups: report.modules[id].review?.groups ?? [], reason: payload.modules[id].reason ?? null })), organizations: report.reviewOrganizations ?? null };
|
|
114
123
|
if (initialState.review) {
|
|
115
124
|
const escape = value => String(value ?? '').replace(/[&<>"']/g, character => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[character]);
|
|
116
125
|
const label = pendingModules.length ? `待确认版本 · ${pendingModules.length} 个板块尚未处理` : '本次来源与处理记录';
|
|
@@ -126,7 +135,7 @@ export async function generateDashboard({ project, dataDir, sourceVersions, outp
|
|
|
126
135
|
await verifyInputs();
|
|
127
136
|
return {
|
|
128
137
|
bytes: Buffer.byteLength(rendered.html), sha256: sha(rendered.html), templateSha256: rendered.templateSha256,
|
|
129
|
-
codeSha256, decisionsSha256, reviewSha256, needsReview: pendingModules.length > 0, reviewSummary, payloadSha256: rendered.payloadSha256,
|
|
138
|
+
codeSha256, decisionsSha256, reviewSha256, needsReview: pendingModules.length > 0, reviewSummary, skippedModules, payloadSha256: rendered.payloadSha256,
|
|
130
139
|
processingVersion: payload.processingVersion, payloadVersion: payload.schemaVersion, rendererVersion: rendered.rendererVersion,
|
|
131
140
|
sources: payload.sources, moduleStates: rendered.moduleStates,
|
|
132
141
|
processors: Object.fromEntries(ids.map(id => [id, { version: payload.processingVersion, state: payload.modules[id].state }])),
|