'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: [ { name: '足金999', unit: 'g', quantity: 2200, pricingMode: 'auto', goldPrice: 94000, laborRate: 4500, laborMode: 'gram', baseSale: 216700, sale: 217750, charges: [{ name: '编绳', amount: 1050 }], }, ], }; 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)); }); test('客户单保留纸单号、优惠抹零、最终金额大小写和经办人,不显示收退款汇总', () => { const html = receipt(sample); 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, /
合计人民币大写:贰仟壹佰陆拾柒元伍角<\/strong><\/div>优惠/抹零:¥10\.00<\/span>/, ); assert.equal((html.match(/
')); } 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('原单成交额')); }); test('固定横版单页保留超多商品、收费和长备注,不受旧尺寸设置影响', () => { const lines = Array.from({ length: 60 }, (_, i) => ({ ...sample.lines[0], name: '测试商品' + i, charges: [{ name: '附加服务' + i, amount: 100 }], })); const html = receipt( { ...sample, lines, note: '长备注'.repeat(80) }, settings({ width: 300, height: 400, rows: 12, rowHeight: 16 }), ); assert.equal((html.match(/