@chenchaolong/plugin-trade-compliance-workbench 1.0.239 → 1.0.241
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/dist/lib/customs-formatting.d.ts.map +1 -1
- package/dist/lib/customs-formatting.js +5 -4
- package/dist/lib/customs-formatting.js.map +1 -1
- package/dist/lib/export-formatting.d.ts +5 -0
- package/dist/lib/export-formatting.d.ts.map +1 -0
- package/dist/lib/export-formatting.js +18 -0
- package/dist/lib/export-formatting.js.map +1 -0
- package/dist/lib/invoice-formatting.d.ts.map +1 -1
- package/dist/lib/invoice-formatting.js +9 -7
- package/dist/lib/invoice-formatting.js.map +1 -1
- package/dist/lib/packing/packing-full-text.d.ts +2 -2
- package/dist/lib/packing/packing-full-text.d.ts.map +1 -1
- package/dist/lib/packing/packing-full-text.js +21 -73
- package/dist/lib/packing/packing-full-text.js.map +1 -1
- package/dist/lib/packing/packing-layout.js +5 -5
- package/dist/lib/packing/packing-layout.js.map +1 -1
- package/dist/lib/packing/packing-pi-model-column.js +4 -4
- package/dist/lib/packing/packing-pi-model-column.js.map +1 -1
- package/dist/lib/sales-file.service.d.ts +1 -1
- package/dist/lib/sales-file.service.d.ts.map +1 -1
- package/dist/lib/sales-file.service.js +44 -28
- package/dist/lib/sales-file.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { clearExportReviewColors } from './export-formatting.js';
|
|
2
3
|
import { customsPackingWeights } from './customs-packing-weight.js';
|
|
3
4
|
import { addPackingPiModelColumn } from './packing/packing-pi-model-column.js';
|
|
4
5
|
import { scopeCustomsDocument, isPlaceholderCustomerName } from './customs-document-scope.js';
|
|
@@ -42,8 +43,8 @@ export const MAX_EDITED_WORKBOOK_BYTES = 20 * 1024 * 1024;
|
|
|
42
43
|
export const MAX_EDITED_WORKBOOK_ZIP_ENTRIES = 2048;
|
|
43
44
|
export const MAX_EDITED_WORKBOOK_ZIP_UNCOMPRESSED_BYTES = 100 * 1024 * 1024;
|
|
44
45
|
export const OLD_SALES_FILE_CLEANUP_DELAY_MS = 30_000;
|
|
45
|
-
export const SALES_EXPORT_INTEGRITY_VERSION = '2026-11-
|
|
46
|
-
const PACKING_LAYOUT_VERSION = '
|
|
46
|
+
export const SALES_EXPORT_INTEGRITY_VERSION = '2026-11-12.retain-counts-fixed-weight-decimals';
|
|
47
|
+
const PACKING_LAYOUT_VERSION = 'v21';
|
|
47
48
|
const COMPANY_LOGO_PLACEMENTS = {
|
|
48
49
|
PI: { tl: { col: 0, row: 0.02925 }, br: { col: 2, row: 0.999996875 } },
|
|
49
50
|
CI: { tl: { col: 0, row: 0.02925 }, br: { col: 2, row: 0.999996875 } },
|
|
@@ -956,6 +957,7 @@ export async function renderSalesWorkbook(type, data, logo) {
|
|
|
956
957
|
for (const other of [...workbook.worksheets])
|
|
957
958
|
if (other.id !== sheet.id)
|
|
958
959
|
workbook.removeWorksheet(other.id);
|
|
960
|
+
clearExportReviewColors(sheet, type);
|
|
959
961
|
return removeExportComments(Buffer.from(await workbook.xlsx.writeBuffer()));
|
|
960
962
|
}
|
|
961
963
|
/** Remove comment parts and their relationships without changing drawings or business cells. */
|
|
@@ -1140,10 +1142,15 @@ function fillPackingPhysicalRows(sheet, rows, data) {
|
|
|
1140
1142
|
if (conflict || !completeScope || !repeated && (value == null || typeof value === 'number' && (!Number.isFinite(value) || value <= 0)))
|
|
1141
1143
|
markReview(cell, conflict ? 'FFFFC7CE' : !completeScope ? 'FFFFE0B2' : undefined);
|
|
1142
1144
|
});
|
|
1143
|
-
//
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
sheet.getCell(excelRow,
|
|
1145
|
+
// Estimate only from this physical group's gross; never allocate a shared
|
|
1146
|
+
// carton weight among commercial goods or count it again on repeated rows.
|
|
1147
|
+
for (const [column, grossColumn] of [[10, 6], [11, 12]]) {
|
|
1148
|
+
const gross = sheet.getCell(excelRow, grossColumn).value;
|
|
1149
|
+
const cell = sheet.getCell(excelRow, column);
|
|
1150
|
+
cell.value = typeof gross === 'number' && Number.isFinite(gross) && gross >= 0 ? new Decimal(gross).mul('0.8').toNumber() : null;
|
|
1151
|
+
cell.numFmt = '0.00';
|
|
1152
|
+
if (!repeated)
|
|
1153
|
+
markReview(cell, cell.value == null ? 'FFFFF2CC' : conflict ? 'FFFFC7CE' : 'FFFFE0B2');
|
|
1147
1154
|
}
|
|
1148
1155
|
if (conflict || !completeScope) {
|
|
1149
1156
|
markReview(sheet.getCell(excelRow, 3));
|
|
@@ -1193,8 +1200,8 @@ function fillPackingSheet(sheet, data) {
|
|
|
1193
1200
|
const incomplete = packing?.totalsComplete === false;
|
|
1194
1201
|
const labels = ['Total Gross weight (KG)', 'Total Net weight (KG)', 'Volume (CBM)', 'Total Carton (CTN)'];
|
|
1195
1202
|
const grossKg = packing?.totals.grossKg;
|
|
1196
|
-
const
|
|
1197
|
-
const totals = [grossKg,
|
|
1203
|
+
const estimatedNet = grossKg != null && Number.isFinite(Number(grossKg)) && Number(grossKg) >= 0 ? new Decimal(grossKg).mul('0.8').toNumber() : null;
|
|
1204
|
+
const totals = [grossKg, estimatedNet, packing?.totals.volumeCbm, packing?.totals.cartons];
|
|
1198
1205
|
labels.forEach((label, offset) => {
|
|
1199
1206
|
set(sheet, `A${totalsRow + offset}`, label);
|
|
1200
1207
|
const total = totals[offset];
|
|
@@ -1232,11 +1239,12 @@ function fillPackingSheet(sheet, data) {
|
|
|
1232
1239
|
if (incomplete)
|
|
1233
1240
|
for (const offset of [0, 1, 2, 3])
|
|
1234
1241
|
markReview(sheet.getCell(totalsRow + offset, 6));
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1242
|
+
markReview(sheet.getCell(totalsRow + 1, 6), totals[1] == null ? 'FFFFF2CC' : 'FFFFE0B2');
|
|
1243
|
+
for (let row = 12; row < totalsRow; row++)
|
|
1244
|
+
for (const column of [6, 10, 11, 12])
|
|
1245
|
+
sheet.getCell(row, column).numFmt = '0.00';
|
|
1246
|
+
for (const offset of [0, 1])
|
|
1247
|
+
sheet.getCell(totalsRow + offset, 6).numFmt = '0.00';
|
|
1240
1248
|
}
|
|
1241
1249
|
/**
|
|
1242
1250
|
* 银行信息区块按通道分两种布局:
|
|
@@ -1375,6 +1383,8 @@ function fillCustomsSheet(sheet, data) {
|
|
|
1375
1383
|
set(sheet, 'C9', packing?.totals.cartons > 0 ? packing.totals.cartons : '待确认');
|
|
1376
1384
|
set(sheet, 'D9', packing?.totals.grossKg > 0 ? packing.totals.grossKg : '待确认');
|
|
1377
1385
|
set(sheet, 'E9', weights.totalNetWeightKg ?? '待确认');
|
|
1386
|
+
for (const address of ['D9', 'E9'])
|
|
1387
|
+
sheet.getCell(address).numFmt = '0.00';
|
|
1378
1388
|
if (weights.totalNetWeightKg != null)
|
|
1379
1389
|
markReview(sheet.getCell('E9'), 'FFFFE0B2');
|
|
1380
1390
|
set(sheet, 'L8', pricing.currencyCode === 'USD' ? '美元' : '人民币');
|
|
@@ -1417,7 +1427,10 @@ function fillCustomsSheet(sheet, data) {
|
|
|
1417
1427
|
// Price belongs to the commercial quantity row, never the statutory kg row
|
|
1418
1428
|
// merely because it is first in the declaration template.
|
|
1419
1429
|
const tradeRow = quantities.findIndex(entry => customsUnitsCompatible(product.unit, entry.unit));
|
|
1420
|
-
|
|
1430
|
+
// Missing statutory units stay blank; keep commercial prices off a kg row
|
|
1431
|
+
// when the sale itself is counted in pieces, even without a secondary unit.
|
|
1432
|
+
const kgUnit = (unit) => /^(?:千克|公斤|kg|kgs|kilograms?)$/i.test(String(unit ?? '').trim());
|
|
1433
|
+
const priceRow = row + (tradeRow >= 0 ? tradeRow : kgUnit(quantities[0].unit) && product.unit && !kgUnit(product.unit) ? 1 : 0);
|
|
1421
1434
|
if (tradeRow < 0) {
|
|
1422
1435
|
// Retain source text and financial values; communicate unit conflicts by color only.
|
|
1423
1436
|
markReview(sheet.getCell(`C${row}`), 'FFFFE0B2');
|
|
@@ -1429,13 +1442,11 @@ function fillCustomsSheet(sheet, data) {
|
|
|
1429
1442
|
for (const [offset, entry] of quantities.entries()) {
|
|
1430
1443
|
set(sheet, `D${row + offset}`, entry.quantity);
|
|
1431
1444
|
set(sheet, `E${row + offset}`, entry.unit);
|
|
1445
|
+
sheet.getCell(`D${row + offset}`).numFmt = kgUnit(entry.unit) ? '0.00' : 'General';
|
|
1432
1446
|
if (entry.review)
|
|
1433
1447
|
markReview(sheet.getCell(`D${row + offset}`));
|
|
1434
1448
|
if (weights.byLine[product.id]?.estimated && /^(?:千克|公斤|kg|kgs|kilograms?)$/i.test(entry.unit) && entry.quantity != null)
|
|
1435
1449
|
markReview(sheet.getCell(`D${row + offset}`), 'FFFFE0B2');
|
|
1436
|
-
if (entry.inferred)
|
|
1437
|
-
for (const column of ['D', 'E'])
|
|
1438
|
-
markReview(sheet.getCell(`${column}${row + offset}`), 'FFFFE0B2');
|
|
1439
1450
|
}
|
|
1440
1451
|
for (const warning of data.generationWarnings ?? [])
|
|
1441
1452
|
if (String(warning.field ?? '').startsWith(`customs.${purchaseLines[index].id}.`))
|
|
@@ -1460,27 +1471,32 @@ function customsUnitsCompatible(source, target) {
|
|
|
1460
1471
|
function customsQuantityRows(product, commercial) {
|
|
1461
1472
|
const explicitPrimary = String(product.statutoryUnitPrimary || '').trim();
|
|
1462
1473
|
const isKg = (unit) => /^(?:千克|公斤|kg|kgs|kilograms?)$/i.test(unit);
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
// evidence, not a confirmed statutory unit: mark the fallback for review.
|
|
1466
|
-
const primary = explicitPrimary || tradeUnit;
|
|
1474
|
+
// Keep statutory units source-confirmed, independently of known commercial counts.
|
|
1475
|
+
const primary = explicitPrimary;
|
|
1467
1476
|
const explicitSecondary = String(product.statutoryUnitSecondary || '').trim();
|
|
1468
|
-
const secondary = explicitSecondary
|
|
1469
|
-
|
|
1470
|
-
|
|
1477
|
+
const secondary = explicitSecondary;
|
|
1478
|
+
const sourceCountRow = [primary, secondary].findIndex(unit => Boolean(unit) && !isKg(unit));
|
|
1479
|
+
const units = [primary, secondary];
|
|
1480
|
+
// Retain a known non-weight commercial count once in an available slot only
|
|
1481
|
+
// when neither source slot already defines a count. Never move it into kg.
|
|
1482
|
+
const missingCountRow = sourceCountRow < 0 && String(product.unit ?? '').trim() && !isKg(String(product.unit).trim())
|
|
1483
|
+
? units.findIndex(unit => !unit) : -1;
|
|
1484
|
+
const commercialQuantity = commercial.quantity;
|
|
1485
|
+
const validCount = commercialQuantity != null && String(commercialQuantity).trim() !== '' && Number.isFinite(Number(commercialQuantity)) && Number(commercialQuantity) >= 0;
|
|
1486
|
+
return units.map((unit, index) => {
|
|
1471
1487
|
if (!unit)
|
|
1472
|
-
return { unit, quantity: null, review: false };
|
|
1488
|
+
return { unit, quantity: index === missingCountRow && validCount ? Number(commercialQuantity) : null, review: false };
|
|
1473
1489
|
if (isKg(unit)) {
|
|
1474
1490
|
const weight = product.netWeightKg;
|
|
1475
1491
|
const valid = typeof weight === 'number' && Number.isFinite(weight) && weight > 0;
|
|
1476
1492
|
// A commercial kg quantity cannot substitute for missing PL net weight.
|
|
1477
1493
|
const quantity = valid ? weight : null;
|
|
1478
|
-
return { unit, quantity, review: quantity == null
|
|
1494
|
+
return { unit, quantity, review: quantity == null };
|
|
1479
1495
|
}
|
|
1480
1496
|
const compatible = customsUnitsCompatible(product.unit, unit);
|
|
1481
|
-
const sourceQuantity = (index ===
|
|
1497
|
+
const sourceQuantity = (index === sourceCountRow) && product.customsSourceQuantity != null && Number.isFinite(Number(product.customsSourceQuantity)) && Number(product.customsSourceQuantity) > 0 ? Number(product.customsSourceQuantity) : null;
|
|
1482
1498
|
const valid = compatible && commercial.quantity != null && Number.isFinite(Number(commercial.quantity));
|
|
1483
|
-
return { unit, quantity: valid ? Number(commercial.quantity) : sourceQuantity, review: !valid
|
|
1499
|
+
return { unit, quantity: valid ? Number(commercial.quantity) : sourceQuantity, review: !valid };
|
|
1484
1500
|
});
|
|
1485
1501
|
}
|
|
1486
1502
|
function normalizeCustomsConfirmationRow(sheet, row) {
|