2026-10-17 19:50:24 +08:00
|
|
|
'use strict';
|
|
|
|
|
const { test } = require('node:test'),
|
|
|
|
|
assert = require('node:assert/strict');
|
|
|
|
|
const { receipt, uppercaseMoney, settings } = require('../printing');
|
|
|
|
|
const sample = {
|
|
|
|
|
number: 'MM-INTERNAL-UNIQUE',
|
|
|
|
|
paper_number: '20261017003',
|
|
|
|
|
date: '2026-10-17',
|
|
|
|
|
customer: '示例客户',
|
|
|
|
|
salesperson: '助理',
|
|
|
|
|
status: 'delivered',
|
|
|
|
|
total: 216750,
|
|
|
|
|
discount: 1000,
|
|
|
|
|
received: 216750,
|
|
|
|
|
refunded: 0,
|
|
|
|
|
balance: 0,
|
|
|
|
|
paymentMethods: ['支付宝'],
|
|
|
|
|
note: '客户备注',
|
|
|
|
|
lines: [
|
2026-12-04 08:58:53 -08:00
|
|
|
{
|
2026-10-17 19:50:24 +08:00
|
|
|
name: '足金999',
|
|
|
|
|
unit: 'g',
|
|
|
|
|
quantity: 2200,
|
|
|
|
|
pricingMode: 'auto',
|
|
|
|
|
goldPrice: 94000,
|
|
|
|
|
laborRate: 4500,
|
|
|
|
|
laborMode: 'gram',
|
|
|
|
|
baseSale: 216700,
|
|
|
|
|
sale: 217750,
|
|
|
|
|
charges: [{ name: '编绳', amount: 1050 }],
|
2026-12-04 08:58:53 -08:00
|
|
|
},
|
|
|
|
|
],
|
2026-10-17 19:50:24 +08:00
|
|
|
};
|
|
|
|
|
test('人民币大写按整数分覆盖零、角分、跨万亿及连续零', () => {
|
|
|
|
|
for (const [value, text] of [
|
|
|
|
|
[0, '零元整'],
|
|
|
|
|
[1, '零元壹分'],
|
|
|
|
|
[10, '零元壹角'],
|
|
|
|
|
[105, '壹元零伍分'],
|
|
|
|
|
[115, '壹元壹角伍分'],
|
|
|
|
|
[1000, '壹拾元整'],
|
|
|
|
|
[216750, '贰仟壹佰陆拾柒元伍角'],
|
|
|
|
|
[203400, '贰仟零叁拾肆元整'],
|
|
|
|
|
[1000000, '壹万元整'],
|
|
|
|
|
[1000100, '壹万零壹元整'],
|
|
|
|
|
[1001000, '壹万零壹拾元整'],
|
|
|
|
|
[100000001, '壹佰万元零壹分'],
|
|
|
|
|
[10001000101, '壹亿零壹万零壹元零壹分'],
|
|
|
|
|
[100000000000, '壹拾亿元整'],
|
|
|
|
|
[100000000000000, '壹兆元整'],
|
|
|
|
|
])
|
|
|
|
|
assert.equal(uppercaseMoney(value), text, String(value));
|
|
|
|
|
for (const invalid of [-1, 1.1, NaN, Infinity, '100', Number.MAX_SAFE_INTEGER + 1])
|
|
|
|
|
assert.throws(() => uppercaseMoney(invalid));
|
|
|
|
|
});
|
2026-10-23 09:49:36 +08:00
|
|
|
test('客户单保留纸单号、优惠抹零、最终金额大小写和经办人,不显示收退款汇总', () => {
|
2026-10-17 19:50:24 +08:00
|
|
|
const html = receipt(sample);
|
2026-10-23 09:49:36 +08:00
|
|
|
for (const hidden of ['系统单号', 'MM-INTERNAL-UNIQUE', '累计收款', '累计退款', '客户确认', '待收款', '待退款'])
|
|
|
|
|
assert.ok(!html.includes(hidden), hidden);
|
|
|
|
|
for (const visible of [
|
|
|
|
|
'纸单号:20261017003',
|
|
|
|
|
'合计金额',
|
|
|
|
|
'¥2167.50',
|
|
|
|
|
'贰仟壹佰陆拾柒元伍角',
|
|
|
|
|
'优惠/抹零:¥10.00',
|
|
|
|
|
'经办人:助理',
|
|
|
|
|
'附加:编绳',
|
|
|
|
|
'10.50',
|
|
|
|
|
'支付宝',
|
|
|
|
|
])
|
|
|
|
|
assert.ok(html.includes(visible), visible);
|
|
|
|
|
assert.match(
|
|
|
|
|
html,
|
|
|
|
|
/<div class="totals-summary"><div class="uppercase">合计人民币大写:<strong>贰仟壹佰陆拾柒元伍角<\/strong><\/div><span class="discount">优惠/抹零:¥10\.00<\/span>/,
|
|
|
|
|
);
|
2026-10-17 19:50:24 +08:00
|
|
|
assert.equal((html.match(/<section class="sheet /g) || []).length, 1);
|
|
|
|
|
});
|
2026-10-23 09:49:36 +08:00
|
|
|
test('优惠只展示已保存整数分,零值明确显示,取整差额不再次计入优惠或扣减合计', () => {
|
|
|
|
|
for (const mode of ['full', 'overlay'])
|
|
|
|
|
for (const [discount, total, adjustment] of [
|
|
|
|
|
[0, 1300, 40],
|
|
|
|
|
[20, 1200, -40],
|
|
|
|
|
[1234, 100000, 0],
|
|
|
|
|
]) {
|
|
|
|
|
const order = { ...sample, discount, total, rounding_mode: 'yuan', rounding_adjustment: adjustment },
|
|
|
|
|
before = JSON.stringify(order),
|
|
|
|
|
html = receipt(order, {}, mode);
|
|
|
|
|
assert.ok(html.includes('优惠/抹零:¥' + (discount / 100).toFixed(2)));
|
|
|
|
|
assert.equal((html.match(/优惠/抹零:/g) || []).length, 1);
|
|
|
|
|
assert.ok(html.includes('<strong>¥' + total / 100 + '</strong>'));
|
|
|
|
|
assert.ok(html.includes(uppercaseMoney(total)));
|
|
|
|
|
assert.equal(JSON.stringify(order), before, '打印不修改保存金额');
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-10-17 19:50:24 +08:00
|
|
|
test('正常客户单不标注预订或交付状态,草稿、取消和退货保留提示', () => {
|
|
|
|
|
for (const mode of ['full', 'overlay'])
|
|
|
|
|
for (const status of ['confirmed', 'delivered']) {
|
|
|
|
|
const html = receipt({ ...sample, status }, {}, mode);
|
|
|
|
|
for (const hidden of ['预订单', '待交付', '销售单 · 已交付'])
|
|
|
|
|
assert.ok(!html.includes(hidden), status + ' ' + hidden);
|
|
|
|
|
assert.ok(html.includes('<div class="meta secondary"><span>收款方式:支付宝</span></div>'));
|
|
|
|
|
}
|
|
|
|
|
for (const [status, notice] of [
|
|
|
|
|
['draft', '草稿 · 未确认'],
|
|
|
|
|
['returned', '退货单 · 已退货'],
|
|
|
|
|
['cancelled', '取消单 · 已取消'],
|
|
|
|
|
]) {
|
|
|
|
|
const html = receipt({ ...sample, status });
|
|
|
|
|
assert.ok(html.includes(notice), status);
|
|
|
|
|
assert.ok(html.includes('收款方式:支付宝'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
test('注意事项按最新要求去掉维修承诺,取消退货仍注明原单金额', () => {
|
|
|
|
|
const html = receipt(sample);
|
|
|
|
|
for (const text of [
|
|
|
|
|
'国家法定机构检测合格',
|
|
|
|
|
'如无质量问题,概不退换',
|
|
|
|
|
'票据、标签、证书',
|
|
|
|
|
'珠宝首饰保养须知',
|
|
|
|
|
'避免接触水银、铅等金属',
|
|
|
|
|
'漂白剂、涂改液',
|
|
|
|
|
'最好每天清水清洗',
|
|
|
|
|
'首饰质量监督检验中心鉴定',
|
|
|
|
|
'凭本票无条件退换货',
|
|
|
|
|
])
|
|
|
|
|
assert.ok(html.includes(text), text);
|
|
|
|
|
assert.ok(!html.includes('免费维修'));
|
|
|
|
|
assert.ok(!html.includes('仅收取配件费用'));
|
|
|
|
|
for (const status of ['returned', 'cancelled']) assert.ok(receipt({ ...sample, status }).includes('原单成交额'));
|
|
|
|
|
});
|
2026-10-22 12:59:56 +08:00
|
|
|
test('固定横版单页保留超多商品、收费和长备注,不受旧尺寸设置影响', () => {
|
2026-10-17 19:50:24 +08:00
|
|
|
const lines = Array.from({ length: 60 }, (_, i) => ({
|
|
|
|
|
...sample.lines[0],
|
|
|
|
|
name: '测试商品' + i,
|
|
|
|
|
charges: [{ name: '附加服务' + i, amount: 100 }],
|
|
|
|
|
}));
|
2026-10-22 12:59:56 +08:00
|
|
|
const html = receipt(
|
|
|
|
|
{ ...sample, lines, note: '长备注'.repeat(80) },
|
|
|
|
|
settings({ width: 300, height: 400, rows: 12, rowHeight: 16 }),
|
|
|
|
|
);
|
2026-10-17 19:50:24 +08:00
|
|
|
assert.equal((html.match(/<section class="sheet /g) || []).length, 1);
|
|
|
|
|
assert.ok(html.includes('测试商品59'));
|
|
|
|
|
assert.ok(html.includes('附加服务59'));
|
|
|
|
|
assert.ok(html.includes('长备注'.repeat(80)));
|
|
|
|
|
assert.ok(!html.includes('overflow:hidden'));
|
|
|
|
|
assert.ok(html.includes('/print.js'));
|
2026-10-22 12:59:56 +08:00
|
|
|
assert.match(html, /@page\{size:241mm 140mm;margin:0\}/);
|
2026-10-17 19:50:24 +08:00
|
|
|
for (const mode of ['full', 'overlay']) {
|
|
|
|
|
const printed = receipt({ ...sample, lines }, {}, mode);
|
|
|
|
|
const numbers = [...printed.matchAll(/<tr><td>([^<]+)<\/td>/g)].map(m => m[1]);
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
numbers,
|
|
|
|
|
Array.from({ length: 120 }, (_, i) => String(i + 1)),
|
|
|
|
|
);
|
|
|
|
|
assert.ok(!printed.includes('免费维修'));
|
|
|
|
|
assert.ok(!printed.includes('仅收取配件费用'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('旧格式纸单号打印时去掉日期间隔符,保留账内原编号', () => {
|
|
|
|
|
const old = { ...sample, paper_number: '20261017-003' };
|
|
|
|
|
const html = receipt(old);
|
|
|
|
|
assert.ok(html.includes('纸单号:20261017003'));
|
|
|
|
|
assert.ok(!html.includes('20261017-003'));
|
|
|
|
|
assert.equal(old.paper_number, '20261017-003');
|
|
|
|
|
});
|