@chenchaolong/plugin-trade-compliance-workbench 1.0.251 → 1.0.252
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/adapters/invoice-layout-analysis.provider.d.ts +9 -0
- package/dist/lib/adapters/invoice-layout-analysis.provider.d.ts.map +1 -0
- package/dist/lib/adapters/invoice-layout-analysis.provider.js +69 -0
- package/dist/lib/adapters/invoice-layout-analysis.provider.js.map +1 -0
- package/dist/lib/entities/customer.entity.d.ts +2 -2
- package/dist/lib/entities/customer.entity.d.ts.map +1 -1
- package/dist/lib/entities/customer.entity.js +4 -4
- package/dist/lib/entities/customer.entity.js.map +1 -1
- package/dist/lib/import-jobs/contracts.d.ts +3 -3
- package/dist/lib/import-jobs/contracts.d.ts.map +1 -1
- package/dist/lib/import-jobs/import-command.builder.js +1 -1
- package/dist/lib/import-jobs/import-command.builder.js.map +1 -1
- package/dist/lib/import-jobs/import-job-callback.processor.js +1 -1
- package/dist/lib/import-jobs/import-job-callback.processor.js.map +1 -1
- package/dist/lib/import-jobs/import-job.processor.js.map +1 -1
- package/dist/lib/invoice/dynamic-render.d.ts +14 -0
- package/dist/lib/invoice/dynamic-render.d.ts.map +1 -0
- package/dist/lib/invoice/dynamic-render.js +114 -0
- package/dist/lib/invoice/dynamic-render.js.map +1 -0
- package/dist/lib/invoice/formula.d.ts +5 -0
- package/dist/lib/invoice/formula.d.ts.map +1 -0
- package/dist/lib/invoice/formula.js +103 -0
- package/dist/lib/invoice/formula.js.map +1 -0
- package/dist/lib/invoice/source-layout.d.ts +23 -0
- package/dist/lib/invoice/source-layout.d.ts.map +1 -0
- package/dist/lib/invoice/source-layout.js +119 -0
- package/dist/lib/invoice/source-layout.js.map +1 -0
- package/dist/lib/invoice/types.d.ts +27 -0
- package/dist/lib/invoice/types.d.ts.map +1 -0
- package/dist/lib/invoice/types.js +2 -0
- package/dist/lib/invoice/types.js.map +1 -0
- package/dist/lib/invoice/values.d.ts +10 -0
- package/dist/lib/invoice/values.d.ts.map +1 -0
- package/dist/lib/invoice/values.js +95 -0
- package/dist/lib/invoice/values.js.map +1 -0
- package/dist/lib/invoice-payment-terms.d.ts +5 -0
- package/dist/lib/invoice-payment-terms.d.ts.map +1 -0
- package/dist/lib/invoice-payment-terms.js +28 -0
- package/dist/lib/invoice-payment-terms.js.map +1 -0
- package/dist/lib/packing/packing-complete-rows.d.ts.map +1 -1
- package/dist/lib/packing/packing-complete-rows.js +7 -10
- package/dist/lib/packing/packing-complete-rows.js.map +1 -1
- package/dist/lib/packing/packing-role.js +2 -2
- package/dist/lib/packing/packing-role.js.map +1 -1
- package/dist/lib/remote-components/trade-compliance-workbench/app.css +1 -1
- package/dist/lib/remote-components/trade-compliance-workbench/app.js +4 -4
- package/dist/lib/remote-ui/action-execution.d.ts.map +1 -1
- package/dist/lib/remote-ui/action-execution.js +2 -0
- package/dist/lib/remote-ui/action-execution.js.map +1 -1
- package/dist/lib/remote-ui/app-source.js +6 -2
- package/dist/lib/remote-ui/app-source.js.map +1 -1
- package/dist/lib/remote-ui/customer-contract-contracts.d.ts +10 -4
- package/dist/lib/remote-ui/customer-contract-contracts.d.ts.map +1 -1
- package/dist/lib/remote-ui/pages/contracts.d.ts +1 -0
- package/dist/lib/remote-ui/pages/contracts.d.ts.map +1 -1
- package/dist/lib/remote-ui/pages/contracts.js +20 -15
- package/dist/lib/remote-ui/pages/contracts.js.map +1 -1
- package/dist/lib/remote-ui/pages/procurement-contracts.css +5 -0
- package/dist/lib/remote-ui/pages/procurement.d.ts.map +1 -1
- package/dist/lib/remote-ui/pages/procurement.js +18 -5
- package/dist/lib/remote-ui/pages/procurement.js.map +1 -1
- package/dist/lib/sales-file.service.d.ts +4 -2
- package/dist/lib/sales-file.service.d.ts.map +1 -1
- package/dist/lib/sales-file.service.js +27 -12
- package/dist/lib/sales-file.service.js.map +1 -1
- package/dist/lib/schema-maintenance.d.ts.map +1 -1
- package/dist/lib/schema-maintenance.js +2 -0
- package/dist/lib/schema-maintenance.js.map +1 -1
- package/dist/lib/supplier-materials/generation-materials.d.ts +2 -0
- package/dist/lib/supplier-materials/generation-materials.d.ts.map +1 -1
- package/dist/lib/supplier-materials/generation-materials.js.map +1 -1
- package/dist/lib/workbench-action-contract.d.ts +1 -1
- package/dist/lib/workbench-action-contract.d.ts.map +1 -1
- package/dist/lib/workbench-action-contract.js +1 -0
- package/dist/lib/workbench-action-contract.js.map +1 -1
- package/dist/lib/workbench-view.provider.d.ts +1 -1
- package/dist/lib/workbench-view.provider.d.ts.map +1 -1
- package/dist/lib/workbench-view.provider.js +4 -1
- package/dist/lib/workbench-view.provider.js.map +1 -1
- package/dist/lib/workbench.middleware.d.ts +42 -42
- package/dist/lib/workbench.middleware.js +1 -1
- package/dist/lib/workbench.middleware.js.map +1 -1
- package/dist/lib/workbench.plugin.d.ts.map +1 -1
- package/dist/lib/workbench.plugin.js +2 -1
- package/dist/lib/workbench.plugin.js.map +1 -1
- package/dist/lib/workbench.service.d.ts +25 -3
- package/dist/lib/workbench.service.d.ts.map +1 -1
- package/dist/lib/workbench.service.js +66 -12
- package/dist/lib/workbench.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":"AAGA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gDAAgD,CAAA;AAe9F,OAAO,EAAE,UAAU,EAAc,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAepE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAA4F,kBAAkB,EAAuH,MAAM,qBAAqB,CAAA;AACvQ,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAC9E,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACx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AAgC;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,CA8ExG;AAiXD,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,8 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { applyDynamicInvoiceLayout } from './invoice/dynamic-render.js';
|
|
3
|
+
import { mergeInvoiceLayouts } from './invoice/source-layout.js';
|
|
4
|
+
import { InvoiceLayoutAnalysisProvider } from './adapters/invoice-layout-analysis.provider.js';
|
|
5
|
+
import { invoicePaymentTerms } from './invoice-payment-terms.js';
|
|
2
6
|
import { balanceDocumentPricing, documentUnitPriceFormat } from './document-pricing.js';
|
|
3
7
|
import { compactExportLayout } from './compact-export-layout.js';
|
|
4
8
|
import { refreshPackingTotalsPagination } from './packing/packing-full-text.js';
|
|
@@ -50,21 +54,22 @@ export const MAX_EDITED_WORKBOOK_BYTES = 20 * 1024 * 1024;
|
|
|
50
54
|
export const MAX_EDITED_WORKBOOK_ZIP_ENTRIES = 2048;
|
|
51
55
|
export const MAX_EDITED_WORKBOOK_ZIP_UNCOMPRESSED_BYTES = 100 * 1024 * 1024;
|
|
52
56
|
export const OLD_SALES_FILE_CLEANUP_DELAY_MS = 30_000;
|
|
53
|
-
export const SALES_EXPORT_INTEGRITY_VERSION = '2026-11-18.
|
|
54
|
-
const PACKING_LAYOUT_VERSION = '
|
|
57
|
+
export const SALES_EXPORT_INTEGRITY_VERSION = '2026-11-18.dynamic-invoice.payment-conditions.product-aware-weights';
|
|
58
|
+
const PACKING_LAYOUT_VERSION = 'v22-boom-marker';
|
|
55
59
|
const COMPANY_LOGO_PLACEMENTS = {
|
|
56
60
|
PI: { tl: { col: 0, row: 0.02925 }, br: { col: 2, row: 0.999996875 } },
|
|
57
61
|
CI: { tl: { col: 0, row: 0.02925 }, br: { col: 2, row: 0.999996875 } },
|
|
58
62
|
PL: { tl: { col: 0, row: 0.05 }, br: { col: 0.9999, row: 1.9999 } }
|
|
59
63
|
};
|
|
60
64
|
let SalesFileService = class SalesFileService {
|
|
61
|
-
constructor(dataSource, workbench, storage, translator, packingService, workspaceFiles, weightAnalyzer) {
|
|
65
|
+
constructor(dataSource, workbench, storage, translator, packingService, workspaceFiles, weightAnalyzer, invoiceLayoutAnalyzer) {
|
|
62
66
|
this.dataSource = dataSource;
|
|
63
67
|
this.workbench = workbench;
|
|
64
68
|
this.storage = storage;
|
|
65
69
|
this.translator = translator;
|
|
66
70
|
this.packingService = packingService;
|
|
67
71
|
this.weightAnalyzer = weightAnalyzer;
|
|
72
|
+
this.invoiceLayoutAnalyzer = invoiceLayoutAnalyzer;
|
|
68
73
|
this.fileStorage = new SalesFileStorage(storage, workspaceFiles);
|
|
69
74
|
}
|
|
70
75
|
async preflight(scope, input) {
|
|
@@ -126,6 +131,8 @@ let SalesFileService = class SalesFileService {
|
|
|
126
131
|
generationWarnings.push({ code: 'PACKING_ORDER_BASIS', message: '尚无已选定的装箱数据,本文件暂按订单商品数量生成;请按实际发货情况人工核对数量和包装信息。' });
|
|
127
132
|
const materialDocuments = await this.workbench.loadSupplierMaterials?.(scope, purchaseIds) ?? [];
|
|
128
133
|
const materialData = generationMaterials(purchaseLines, materialDocuments);
|
|
134
|
+
const sourceInvoiceLayout = mergeInvoiceLayouts(materialDocuments.filter(doc => doc.documentType === 'ENGLISH_QUOTATION' && doc.rows.some(row => row.reviewed && row.purchaseOrderLineId)).map(doc => 'invoiceLayout' in doc ? doc.invoiceLayout : undefined));
|
|
135
|
+
const invoiceLayout = requestedTypes.some(type => type === 'PI' || type === 'CI') ? this.invoiceLayoutAnalyzer ? await this.invoiceLayoutAnalyzer.analyze(sourceInvoiceLayout, scope.organizationId) : sourceInvoiceLayout : undefined;
|
|
129
136
|
const customsWeights = customsPackingWeights(packing, materialData.customsLines.filter(line => !materialData.customsScope || materialData.customsScope.purchaseOrderLineIds.includes(line.id)));
|
|
130
137
|
const customsSourceCities = requestedTypes.includes('CUSTOMS_DECLARATION') ? await recoverPurchaseSourceCities(evaluated.purchaseOrderEntities, id => this.storage.read(id)) : {};
|
|
131
138
|
if (requestedTypes.includes('CUSTOMS_DECLARATION'))
|
|
@@ -146,7 +153,7 @@ let SalesFileService = class SalesFileService {
|
|
|
146
153
|
if (packing)
|
|
147
154
|
generationWarnings.push(...this.packingWarningsForPl(derived, packing));
|
|
148
155
|
const mergedOrderRefs = orders.length > 1 ? orders.map(order => ({ customerContractId: order.customerContractId, purchaseOrderId: order.purchaseOrderId, salesOrderNo: order.salesOrderNo })) : null;
|
|
149
|
-
const commercialOrderDataFingerprint = createHash('sha256').update(JSON.stringify({ derived, customer, company, bank, clauses, documentPricing, materialsFingerprint, materialData, exportIntegrityVersion: SALES_EXPORT_INTEGRITY_VERSION })).digest('hex');
|
|
156
|
+
const commercialOrderDataFingerprint = createHash('sha256').update(JSON.stringify({ derived, customer, company, bank, clauses, documentPricing, materialsFingerprint, materialData, invoiceLayout, exportIntegrityVersion: SALES_EXPORT_INTEGRITY_VERSION })).digest('hex');
|
|
150
157
|
const orderDataFingerprint = packing?.weightEstimates && Object.keys(packing.weightEstimates).length ? createHash('sha256').update(JSON.stringify({ commercialOrderDataFingerprint, packingWeightAnalysis: packing.weightEstimates })).digest('hex') : commercialOrderDataFingerprint;
|
|
151
158
|
const shipmentReference = `SHIP-${createHash('sha256').update(`${ordersKey}:${packing?.fingerprint ?? ''}:${orderDataFingerprint}`).digest('hex').slice(0, 16)}`;
|
|
152
159
|
const batchGenerationId = input.fileType === 'ALL' ? randomUUID() : undefined;
|
|
@@ -193,7 +200,7 @@ let SalesFileService = class SalesFileService {
|
|
|
193
200
|
if (fileType === 'CUSTOMS_DECLARATION')
|
|
194
201
|
fileWarnings.push({ code: 'CUSTOMS_ELEMENTS_REVIEW', message: '商品描述采用报关资料申报要素,数量及单位按第一、第二法定单位列示;黄色空缺字段请核对补全,本文件尚未提交海关。' });
|
|
195
202
|
const request = { currencyCode: documentPricing.currencyCode, ...(batchGenerationId ? { batchGenerationId } : {}), exportIntegrityVersion: SALES_EXPORT_INTEGRITY_VERSION, shipmentDocumentsVersion: 'v2', orderDataFingerprint: fileType === 'PI' ? commercialOrderDataFingerprint : orderDataFingerprint, templateVersion, fileNumber, remarks, bankType, ...(needsPacking ? { packingMode: input.packingMode ?? 'DRAFT', packingIds: packing?.batchIds ?? [] } : {}), ...(fileType === 'PL' ? { packingLayoutVersion: PACKING_LAYOUT_VERSION } : {}), packingFingerprint: packing?.fingerprint ?? '', ordersKey };
|
|
196
|
-
const snapshot = { ...(fileType === 'CUSTOMS_DECLARATION' ? { customsWeightSource: { type: 'SUPPLIER_PACKING', packingIds: packing?.batchIds ?? [], grossWeightKg: packing?.totals.grossKg ?? null, netWeightKg: customsWeights.totalNetWeightKg, method: 'PL_GROSS_80_PERCENT', ratio: 0.8, byLine: customsWeights.byLine } } : {}), customsScope: fileType === 'CUSTOMS_DECLARATION' ? materialData.customsScope : null, customsSourceCities, customsCoverage: fileCustomsCoverage, materials: fileType === 'CUSTOMS_DECLARATION' ? materialData.sources.map(source => source.documentType === 'CUSTOMS_INFO' ? { ...source, fields: source.fields.filter(field => field !== 'netWeightKg' || customsWeights.byLine[source.purchaseOrderLineId]?.source === 'REVIEWED_SHARED_ITEM_NET') } : source) : materialData.sources, materialsFingerprint, version: 'v1', generatedAt: generatedAt.toISOString(), fileType, request, orders, documentPricing: fileDocumentPricing, customer: { ...customer }, customerContract: { ...customerContract }, purchaseOrder: { ...purchaseOrder }, purchaseLines: filePurchaseLines.map(item => ({ ...item })), derived: fileDerived, shipment: { reference: shipmentReference, orders, packingIds: packing?.batchIds ?? [], status: 'PENDING_REVIEW' }, company: company ? { ...company } : null, bank: bank ? { ...bank } : null, clauses: clauses.map(item => ({ ...item })), translated: fileTranslated, packing: packing ? { ...packing, mode: input.packingMode ?? 'DRAFT', shipmentLines: fileDerived.lines.filter((line) => (packing.byPurchaseLine[line.purchaseOrderLineId]?.shippedQty ?? 0) > 0).map((line) => ({ purchaseOrderLineId: line.purchaseOrderLineId, quantity: String(packing.byPurchaseLine[line.purchaseOrderLineId].shippedQty) })) } : null, compliance: { profitCny: compliance.profitCny.toString(), complianceProfitRate: compliance.complianceProfitRate.toString() }, exchangeRate: exchangeRate ? { ...exchangeRate } : null, exchangeCost: exchangeCost?.toString() ?? null, rule: { ...rule } };
|
|
203
|
+
const snapshot = { ...((fileType === 'PI' || fileType === 'CI') && invoiceLayout ? { invoiceLayout } : {}), ...(fileType === 'CUSTOMS_DECLARATION' ? { customsWeightSource: { type: 'SUPPLIER_PACKING', packingIds: packing?.batchIds ?? [], grossWeightKg: packing?.totals.grossKg ?? null, netWeightKg: customsWeights.totalNetWeightKg, method: 'PL_GROSS_80_PERCENT', ratio: 0.8, byLine: customsWeights.byLine } } : {}), customsScope: fileType === 'CUSTOMS_DECLARATION' ? materialData.customsScope : null, customsSourceCities, customsCoverage: fileCustomsCoverage, materials: fileType === 'CUSTOMS_DECLARATION' ? materialData.sources.map(source => source.documentType === 'CUSTOMS_INFO' ? { ...source, fields: source.fields.filter(field => field !== 'netWeightKg' || customsWeights.byLine[source.purchaseOrderLineId]?.source === 'REVIEWED_SHARED_ITEM_NET') } : source) : materialData.sources, materialsFingerprint, version: 'v1', generatedAt: generatedAt.toISOString(), fileType, request, orders, documentPricing: fileDocumentPricing, customer: { ...customer }, customerContract: { ...customerContract }, purchaseOrder: { ...purchaseOrder }, purchaseLines: filePurchaseLines.map(item => ({ ...item })), derived: fileDerived, shipment: { reference: shipmentReference, orders, packingIds: packing?.batchIds ?? [], status: 'PENDING_REVIEW' }, company: company ? { ...company } : null, bank: bank ? { ...bank } : null, clauses: clauses.map(item => ({ ...item })), translated: fileTranslated, packing: packing ? { ...packing, mode: input.packingMode ?? 'DRAFT', shipmentLines: fileDerived.lines.filter((line) => (packing.byPurchaseLine[line.purchaseOrderLineId]?.shippedQty ?? 0) > 0).map((line) => ({ purchaseOrderLineId: line.purchaseOrderLineId, quantity: String(packing.byPurchaseLine[line.purchaseOrderLineId].shippedQty) })) } : null, compliance: { profitCny: compliance.profitCny.toString(), complianceProfitRate: compliance.complianceProfitRate.toString() }, exchangeRate: exchangeRate ? { ...exchangeRate } : null, exchangeCost: exchangeCost?.toString() ?? null, rule: { ...rule } };
|
|
197
204
|
const logo = await this.readCompanyLogo(scope, fileType, company?.logoFileId);
|
|
198
205
|
const buffer = await this.fillWorkbook(fileType, { snapshot, customer, customerContract, purchaseOrder, purchaseLines: filePurchaseLines, derived: fileDerived, company, bank, clauses, translated: fileTranslated, packing, customsCoverage: fileCustomsCoverage, generationWarnings: fileWarnings }, logo);
|
|
199
206
|
await validateWorkbook(buffer);
|
|
@@ -664,13 +671,15 @@ SalesFileService = __decorate([
|
|
|
664
671
|
__param(4, Optional()),
|
|
665
672
|
__param(5, Optional()),
|
|
666
673
|
__param(6, Optional()),
|
|
674
|
+
__param(7, Optional()),
|
|
667
675
|
__metadata("design:paramtypes", [DataSource,
|
|
668
676
|
TradeComplianceWorkbenchService,
|
|
669
677
|
TradeComplianceFileStorage,
|
|
670
678
|
TranslationProvider,
|
|
671
679
|
SupplierPackingService,
|
|
672
680
|
TradeComplianceWorkspaceFiles,
|
|
673
|
-
PackingWeightAnalysisProvider
|
|
681
|
+
PackingWeightAnalysisProvider,
|
|
682
|
+
InvoiceLayoutAnalysisProvider])
|
|
674
683
|
], SalesFileService);
|
|
675
684
|
export { SalesFileService };
|
|
676
685
|
function materialSelectionFingerprint(documents) {
|
|
@@ -838,7 +847,7 @@ function fillInvoiceSheet(sheet, type, data) {
|
|
|
838
847
|
set(sheet, 'F6', dateValue(derived.orderDate ?? purchaseOrder.orderDate));
|
|
839
848
|
set(sheet, 'B7', customer.phone ?? '');
|
|
840
849
|
set(sheet, 'F7', data.snapshot?.orders?.length ? [...new Set(data.snapshot.orders.map((order) => order.contractNo).filter(Boolean))].join('; ') : customerContract.contractNo);
|
|
841
|
-
set(sheet, 'F8', translated.paymentTerms ||
|
|
850
|
+
set(sheet, 'F8', invoicePaymentTerms(translated.paymentTerms) || null);
|
|
842
851
|
set(sheet, 'E9', type === 'PI' ? 'Remark: The quotation is valid for one week.' : '');
|
|
843
852
|
// "To:" 目的国:写客户国别;为空时覆盖模板默认值(MOSCOW),留空即可
|
|
844
853
|
set(sheet, 'B9', translated.customerCountry);
|
|
@@ -885,9 +894,10 @@ export async function renderSalesWorkbook(type, data, logo) {
|
|
|
885
894
|
data = { ...data, derived: shipmentDerived(data.derived, data.packing, type) };
|
|
886
895
|
const workbook = new ExcelJS.Workbook();
|
|
887
896
|
await workbook.xlsx.load(await templateBuffer(type));
|
|
888
|
-
const
|
|
889
|
-
if (!
|
|
897
|
+
const templateSheet = workbook.getWorksheet(sheetName(type));
|
|
898
|
+
if (!templateSheet)
|
|
890
899
|
throw new DomainError(DomainErrorCodes.TEMPLATE_INVALID, '模板工作表不存在', { type });
|
|
900
|
+
let sheet = templateSheet;
|
|
891
901
|
if (sheet.getImages().length !== 0)
|
|
892
902
|
throw new DomainError(DomainErrorCodes.TEMPLATE_INVALID, '模板不应包含预置图片', { type });
|
|
893
903
|
cleanBrokenFormulas(sheet);
|
|
@@ -904,7 +914,7 @@ export async function renderSalesWorkbook(type, data, logo) {
|
|
|
904
914
|
formatInvoiceSheet(sheet, data.derived.lines.length, true);
|
|
905
915
|
if (type === 'CUSTOMS_DECLARATION')
|
|
906
916
|
formatCustomsSheet(sheet, data.derived.lines.length);
|
|
907
|
-
if (type !== 'CUSTOMS_DECLARATION' && logo)
|
|
917
|
+
if (type !== 'CUSTOMS_DECLARATION' && logo && !((type === 'PI' || type === 'CI') && data.snapshot?.invoiceLayout))
|
|
908
918
|
addCompanyLogo(type, workbook, sheet, logo);
|
|
909
919
|
const fieldLocations = {};
|
|
910
920
|
if (type === 'PI' || type === 'CI') {
|
|
@@ -986,6 +996,11 @@ export async function renderSalesWorkbook(type, data, logo) {
|
|
|
986
996
|
for (const other of [...workbook.worksheets])
|
|
987
997
|
if (other.id !== sheet.id)
|
|
988
998
|
workbook.removeWorksheet(other.id);
|
|
999
|
+
if ((type === 'PI' || type === 'CI') && data.snapshot?.invoiceLayout) {
|
|
1000
|
+
sheet = applyDynamicInvoiceLayout(sheet, data.snapshot.invoiceLayout, data, workbookDocumentPricing(data));
|
|
1001
|
+
if (logo)
|
|
1002
|
+
addCompanyLogo(type, workbook, sheet, logo);
|
|
1003
|
+
}
|
|
989
1004
|
clearExportReviewColors(sheet, type);
|
|
990
1005
|
return removeExportComments(Buffer.from(await workbook.xlsx.writeBuffer()));
|
|
991
1006
|
}
|
|
@@ -1662,8 +1677,8 @@ function clauseText(clauses, type) {
|
|
|
1662
1677
|
return undefined;
|
|
1663
1678
|
const isReview = (value) => /(?:审核意见|风险分析|(?:存在|较大|较高).{0,12}风险|risk\s+analysis|poses?.{0,30}risk\b|fails?\s+to\s+specify|failing\s+to\s+specify|(?:field|clause).{0,40}(?:empty|lacks?|missing))/i.test(value);
|
|
1664
1679
|
if (source)
|
|
1665
|
-
return source;
|
|
1666
|
-
return reviewed && !isReview(reviewed) ? reviewed : undefined;
|
|
1680
|
+
return type === 'PAYMENT_TERMS' ? invoicePaymentTerms(source) || undefined : source;
|
|
1681
|
+
return reviewed && !isReview(reviewed) ? type === 'PAYMENT_TERMS' ? invoicePaymentTerms(reviewed) || undefined : reviewed : undefined;
|
|
1667
1682
|
}
|
|
1668
1683
|
function deliveryClauseText(clauses) {
|
|
1669
1684
|
const transport = clauseText(clauses, 'TRANSPORT');
|