@chenchaolong/plugin-trade-compliance-workbench 1.0.238 → 1.0.240
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 +2 -0
- package/dist/lib/invoice-formatting.d.ts.map +1 -1
- package/dist/lib/invoice-formatting.js +52 -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 +31 -26
- package/dist/lib/sales-file.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sales-file.service.d.ts","sourceRoot":"","sources":["../../src/lib/sales-file.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sales-file.service.d.ts","sourceRoot":"","sources":["../../src/lib/sales-file.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAc,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAepE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAA4F,kBAAkB,EAAuH,MAAM,qBAA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QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,qBAAqB,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,EAAE,OAAO;IAsB7J,OAAO,CAAC,sBAAsB;YAKhB,sBAAsB;YA0EtB,YAAY;YAIZ,eAAe;YAKf,QAAQ;IAMtB,wFAAwF;YAC1E,eAAe;IAoB7B,wDAAwD;YAC1C,sBAAsB;IAYpC,gCAAgC;IAChC,OAAO,CAAC,oBAAoB;CAQ7B;AAgDD,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,KAAK,CAAC;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC;IAAE,mBAAmB,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,yBAAyB,EAAE,CAE7L;AA+ID,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuExG;AAoVD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,UAM1J"}
|
|
@@ -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';
|
|
@@ -19,7 +20,7 @@ import { aggregatePackingBatches } from './packing/packing-render.js';
|
|
|
19
20
|
import { PACKING_IMPORT_ACTIVE_STATUSES } from './packing/packing-import-task.contract.js';
|
|
20
21
|
import { completePackingRows } from './packing/packing-complete-rows.js';
|
|
21
22
|
import { shipmentDerived, markReview } from './packing/shipment-documents.js';
|
|
22
|
-
import { formatInvoiceSheet } from './invoice-formatting.js';
|
|
23
|
+
import { formatInvoiceSheet, removeInvoiceExchangeRateColumn } from './invoice-formatting.js';
|
|
23
24
|
import { formatCustomsSheet } from './customs-formatting.js';
|
|
24
25
|
import { stylePackingSheet, expandPackingTextRows } from './packing/packing-layout.js';
|
|
25
26
|
import * as yauzl from 'yauzl';
|
|
@@ -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.compact-without-review-colors';
|
|
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 } },
|
|
@@ -951,9 +952,12 @@ export async function renderSalesWorkbook(type, data, logo) {
|
|
|
951
952
|
target.location = `${name}!${match[1]}${rows.get(Number(match[2]))}`;
|
|
952
953
|
}
|
|
953
954
|
}
|
|
955
|
+
if (type === 'PI' || type === 'CI')
|
|
956
|
+
removeInvoiceExchangeRateColumn(sheet);
|
|
954
957
|
for (const other of [...workbook.worksheets])
|
|
955
958
|
if (other.id !== sheet.id)
|
|
956
959
|
workbook.removeWorksheet(other.id);
|
|
960
|
+
clearExportReviewColors(sheet, type);
|
|
957
961
|
return removeExportComments(Buffer.from(await workbook.xlsx.writeBuffer()));
|
|
958
962
|
}
|
|
959
963
|
/** Remove comment parts and their relationships without changing drawings or business cells. */
|
|
@@ -1138,10 +1142,15 @@ function fillPackingPhysicalRows(sheet, rows, data) {
|
|
|
1138
1142
|
if (conflict || !completeScope || !repeated && (value == null || typeof value === 'number' && (!Number.isFinite(value) || value <= 0)))
|
|
1139
1143
|
markReview(cell, conflict ? 'FFFFC7CE' : !completeScope ? 'FFFFE0B2' : undefined);
|
|
1140
1144
|
});
|
|
1141
|
-
//
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
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.######';
|
|
1152
|
+
if (!repeated)
|
|
1153
|
+
markReview(cell, cell.value == null ? 'FFFFF2CC' : conflict ? 'FFFFC7CE' : 'FFFFE0B2');
|
|
1145
1154
|
}
|
|
1146
1155
|
if (conflict || !completeScope) {
|
|
1147
1156
|
markReview(sheet.getCell(excelRow, 3));
|
|
@@ -1191,8 +1200,8 @@ function fillPackingSheet(sheet, data) {
|
|
|
1191
1200
|
const incomplete = packing?.totalsComplete === false;
|
|
1192
1201
|
const labels = ['Total Gross weight (KG)', 'Total Net weight (KG)', 'Volume (CBM)', 'Total Carton (CTN)'];
|
|
1193
1202
|
const grossKg = packing?.totals.grossKg;
|
|
1194
|
-
const
|
|
1195
|
-
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];
|
|
1196
1205
|
labels.forEach((label, offset) => {
|
|
1197
1206
|
set(sheet, `A${totalsRow + offset}`, label);
|
|
1198
1207
|
const total = totals[offset];
|
|
@@ -1230,10 +1239,7 @@ function fillPackingSheet(sheet, data) {
|
|
|
1230
1239
|
if (incomplete)
|
|
1231
1240
|
for (const offset of [0, 1, 2, 3])
|
|
1232
1241
|
markReview(sheet.getCell(totalsRow + offset, 6));
|
|
1233
|
-
|
|
1234
|
-
markReview(sheet.getCell(totalsRow + 1, 6));
|
|
1235
|
-
else
|
|
1236
|
-
sheet.getCell(totalsRow + 1, 6).note = 'Net weight from confirmed source documents; no proportional estimation.';
|
|
1242
|
+
markReview(sheet.getCell(totalsRow + 1, 6), totals[1] == null ? 'FFFFF2CC' : 'FFFFE0B2');
|
|
1237
1243
|
sheet.getCell(totalsRow + 1, 6).numFmt = '0.######';
|
|
1238
1244
|
}
|
|
1239
1245
|
/**
|
|
@@ -1415,7 +1421,10 @@ function fillCustomsSheet(sheet, data) {
|
|
|
1415
1421
|
// Price belongs to the commercial quantity row, never the statutory kg row
|
|
1416
1422
|
// merely because it is first in the declaration template.
|
|
1417
1423
|
const tradeRow = quantities.findIndex(entry => customsUnitsCompatible(product.unit, entry.unit));
|
|
1418
|
-
|
|
1424
|
+
// Missing statutory units stay blank; keep commercial prices off a kg row
|
|
1425
|
+
// when the sale itself is counted in pieces, even without a secondary unit.
|
|
1426
|
+
const kgUnit = (unit) => /^(?:千克|公斤|kg|kgs|kilograms?)$/i.test(String(unit ?? '').trim());
|
|
1427
|
+
const priceRow = row + (tradeRow >= 0 ? tradeRow : kgUnit(quantities[0].unit) && product.unit && !kgUnit(product.unit) ? 1 : 0);
|
|
1419
1428
|
if (tradeRow < 0) {
|
|
1420
1429
|
// Retain source text and financial values; communicate unit conflicts by color only.
|
|
1421
1430
|
markReview(sheet.getCell(`C${row}`), 'FFFFE0B2');
|
|
@@ -1431,9 +1440,6 @@ function fillCustomsSheet(sheet, data) {
|
|
|
1431
1440
|
markReview(sheet.getCell(`D${row + offset}`));
|
|
1432
1441
|
if (weights.byLine[product.id]?.estimated && /^(?:千克|公斤|kg|kgs|kilograms?)$/i.test(entry.unit) && entry.quantity != null)
|
|
1433
1442
|
markReview(sheet.getCell(`D${row + offset}`), 'FFFFE0B2');
|
|
1434
|
-
if (entry.inferred)
|
|
1435
|
-
for (const column of ['D', 'E'])
|
|
1436
|
-
markReview(sheet.getCell(`${column}${row + offset}`), 'FFFFE0B2');
|
|
1437
1443
|
}
|
|
1438
1444
|
for (const warning of data.generationWarnings ?? [])
|
|
1439
1445
|
if (String(warning.field ?? '').startsWith(`customs.${purchaseLines[index].id}.`))
|
|
@@ -1458,14 +1464,13 @@ function customsUnitsCompatible(source, target) {
|
|
|
1458
1464
|
function customsQuantityRows(product, commercial) {
|
|
1459
1465
|
const explicitPrimary = String(product.statutoryUnitPrimary || '').trim();
|
|
1460
1466
|
const isKg = (unit) => /^(?:千克|公斤|kg|kgs|kilograms?)$/i.test(unit);
|
|
1461
|
-
|
|
1462
|
-
//
|
|
1463
|
-
|
|
1464
|
-
const primary = explicitPrimary || tradeUnit;
|
|
1467
|
+
// Only source-confirmed statutory units authorize a declaration quantity.
|
|
1468
|
+
// A purchase/trade unit must never fill an absent primary or secondary unit.
|
|
1469
|
+
const primary = explicitPrimary;
|
|
1465
1470
|
const explicitSecondary = String(product.statutoryUnitSecondary || '').trim();
|
|
1466
|
-
const secondary = explicitSecondary
|
|
1471
|
+
const secondary = explicitSecondary;
|
|
1472
|
+
const sourceCountRow = [primary, secondary].findIndex(unit => Boolean(unit) && !isKg(unit));
|
|
1467
1473
|
return [primary, secondary].map((unit, index) => {
|
|
1468
|
-
const inferred = Boolean(unit && (index === 0 ? !explicitPrimary : !explicitSecondary));
|
|
1469
1474
|
if (!unit)
|
|
1470
1475
|
return { unit, quantity: null, review: false };
|
|
1471
1476
|
if (isKg(unit)) {
|
|
@@ -1473,12 +1478,12 @@ function customsQuantityRows(product, commercial) {
|
|
|
1473
1478
|
const valid = typeof weight === 'number' && Number.isFinite(weight) && weight > 0;
|
|
1474
1479
|
// A commercial kg quantity cannot substitute for missing PL net weight.
|
|
1475
1480
|
const quantity = valid ? weight : null;
|
|
1476
|
-
return { unit, quantity, review: quantity == null
|
|
1481
|
+
return { unit, quantity, review: quantity == null };
|
|
1477
1482
|
}
|
|
1478
1483
|
const compatible = customsUnitsCompatible(product.unit, unit);
|
|
1479
|
-
const sourceQuantity = (index ===
|
|
1484
|
+
const sourceQuantity = (index === sourceCountRow) && product.customsSourceQuantity != null && Number.isFinite(Number(product.customsSourceQuantity)) && Number(product.customsSourceQuantity) > 0 ? Number(product.customsSourceQuantity) : null;
|
|
1480
1485
|
const valid = compatible && commercial.quantity != null && Number.isFinite(Number(commercial.quantity));
|
|
1481
|
-
return { unit, quantity: valid ? Number(commercial.quantity) : sourceQuantity, review: !valid
|
|
1486
|
+
return { unit, quantity: valid ? Number(commercial.quantity) : sourceQuantity, review: !valid };
|
|
1482
1487
|
});
|
|
1483
1488
|
}
|
|
1484
1489
|
function normalizeCustomsConfirmationRow(sheet, row) {
|