etiquetas.js 1.0.0-alpha.1 → 1.0.0-alpha.11
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/README.md +122 -38
- package/README.npm.md +0 -0
- package/dist/etiquetas.es.js +65 -0
- package/dist/etiquetas.es.js.map +1 -0
- package/dist/etiquetas.umd.js +358 -0
- package/dist/etiquetas.umd.js.map +1 -0
- package/dist/index-Bl0CvwuC.js +59982 -0
- package/dist/index-Bl0CvwuC.js.map +1 -0
- package/dist/index.es-eEPQXFRd.js +9229 -0
- package/dist/index.es-eEPQXFRd.js.map +1 -0
- package/dist/purify.es-DzZgBtzL.js +965 -0
- package/dist/purify.es-DzZgBtzL.js.map +1 -0
- package/package.json +38 -14
- package/README.git.md +0 -486
- package/api/api-labels.json +0 -114
- package/api/api.js +0 -316
- package/api/mock/data-volume-id_680.json +0 -64
- package/api/mock/labels-input.json +0 -96
- package/api/mock/labels-part.json +0 -216
- package/api/mock/labels-scrap.json +0 -76
- package/api/mock/labels-thickened.json +0 -96
- package/api/mock/labels-volume.json +0 -56
- package/api/token.txt +0 -1
- package/services/index.js +0 -28
- package/src/constants.js +0 -247
- package/src/createLabel.js +0 -342
- package/src/etiquetas.js +0 -654
- package/src/formatData.js +0 -96
- package/src/formatDataIntegrated.js +0 -498
- package/src/index.js +0 -86
- package/src/label/services/index.js +0 -1201
- package/src/label/services/sortFunctions.js +0 -158
- package/src/label/services/utils.js +0 -280
- package/src/labelWorker.js +0 -123
- package/src/reducer.js +0 -40
- package/src/store.js +0 -55
- package/src/templates.js +0 -139
- package/src/useLabelData.js +0 -99
- package/src/usePrinterStore.js +0 -115
- package/src/variableManager.js +0 -224
package/src/etiquetas.js
DELETED
|
@@ -1,654 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 🏷️ ETIQUETAS.JS - Sistema de Geração de Etiquetas
|
|
3
|
-
*
|
|
4
|
-
* API principal para geração de etiquetas de projetos de marcenaria
|
|
5
|
-
* Suporta 5 tipos: Peças, Tamponamentos, Insumos, Retalhos e Volumes
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { LabelWorker, createLabelWorker } from './labelWorker.js';
|
|
9
|
-
import { labelTypeNames } from './constants.js';
|
|
10
|
-
import { getTemplateById } from './templates.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Importa funções integradas de formatação de dados
|
|
14
|
-
* Compatível com sortFunctions.js e formatData.js
|
|
15
|
-
*/
|
|
16
|
-
import {
|
|
17
|
-
formatPartData,
|
|
18
|
-
formatTamponamentoData,
|
|
19
|
-
formatInsumoData,
|
|
20
|
-
formatRetalhoData,
|
|
21
|
-
formatVolumeData,
|
|
22
|
-
dataTypeList,
|
|
23
|
-
getInputsByCategory,
|
|
24
|
-
getAllCategoriesId,
|
|
25
|
-
getPartsForLabels,
|
|
26
|
-
getInputForLabels,
|
|
27
|
-
getPartsFromProjectToLabels
|
|
28
|
-
} from './formatDataIntegrated.js';
|
|
29
|
-
|
|
30
|
-
// ============================================================================
|
|
31
|
-
// CONFIGURAÇÕES GLOBAIS
|
|
32
|
-
// ============================================================================
|
|
33
|
-
|
|
34
|
-
let globalConfig = {
|
|
35
|
-
printerName: null,
|
|
36
|
-
paperSize: 'A4',
|
|
37
|
-
orientation: 'portrait',
|
|
38
|
-
defaultTemplate: 'template-padrao',
|
|
39
|
-
autoDownloadOnPrinterError: true
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// ============================================================================
|
|
43
|
-
// FUNÇÕES DE CONFIGURAÇÃO
|
|
44
|
-
// ============================================================================
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Inicializa o sistema de etiquetas
|
|
48
|
-
* @param {Object} config - Configurações iniciais
|
|
49
|
-
*/
|
|
50
|
-
export const init = (config = {}) => {
|
|
51
|
-
globalConfig = { ...globalConfig, ...config };
|
|
52
|
-
console.log('🏷️ Etiquetas.js inicializado com sucesso');
|
|
53
|
-
return globalConfig;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Configura a impressora padrão
|
|
58
|
-
* @param {Object} printerConfig - Configurações da impressora
|
|
59
|
-
*/
|
|
60
|
-
export const configurePrinter = (printerConfig) => {
|
|
61
|
-
globalConfig = { ...globalConfig, ...printerConfig };
|
|
62
|
-
console.log('🖨️ Impressora configurada:', printerConfig.printerName);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Verifica o status da impressora
|
|
67
|
-
* @returns {Promise<Object>} Status da impressora
|
|
68
|
-
*/
|
|
69
|
-
export const getPrinterStatus = async () => {
|
|
70
|
-
try {
|
|
71
|
-
// Simula verificação de impressora (implementar com API real)
|
|
72
|
-
const isConnected = globalConfig.printerName !== null;
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
connected: isConnected,
|
|
76
|
-
printerName: globalConfig.printerName,
|
|
77
|
-
status: isConnected ? 'ready' : 'disconnected',
|
|
78
|
-
paperSize: globalConfig.paperSize,
|
|
79
|
-
orientation: globalConfig.orientation
|
|
80
|
-
};
|
|
81
|
-
} catch (error) {
|
|
82
|
-
return {
|
|
83
|
-
connected: false,
|
|
84
|
-
error: error.message,
|
|
85
|
-
status: 'error'
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// ============================================================================
|
|
91
|
-
// FUNÇÕES DE GERAÇÃO DE ETIQUETAS (makeXLabel)
|
|
92
|
-
// ============================================================================
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Gera etiqueta de peça
|
|
96
|
-
* @param {Object} dadosPeca - Dados da peça
|
|
97
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
98
|
-
* @param {Object} options - Opções adicionais
|
|
99
|
-
* @returns {Promise<Buffer>} Buffer do PDF gerado
|
|
100
|
-
*/
|
|
101
|
-
export const makePartLabel = async (dadosPeca, modeloEtiquetaId, options = {}) => {
|
|
102
|
-
try {
|
|
103
|
-
const worker = createLabelWorker();
|
|
104
|
-
|
|
105
|
-
// Formatar dados da peça para o formato esperado
|
|
106
|
-
const formattedData = formatPartData(dadosPeca);
|
|
107
|
-
|
|
108
|
-
const params = {
|
|
109
|
-
dataSource: [formattedData],
|
|
110
|
-
labels: await loadLabelTemplate(modeloEtiquetaId),
|
|
111
|
-
userPrefs: globalConfig,
|
|
112
|
-
cacheKey: `part-${dadosPeca.id}-${Date.now()}`,
|
|
113
|
-
...options
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const result = await worker.generateLabels(params);
|
|
117
|
-
console.log('✅ Etiqueta de peça gerada:', dadosPeca.nome || dadosPeca.name);
|
|
118
|
-
|
|
119
|
-
// Extrair PDF do resultado
|
|
120
|
-
// O resultado pode ser [blobUri, cacheKey, pdfInstance] ou apenas o PDF
|
|
121
|
-
if (Array.isArray(result)) {
|
|
122
|
-
const [blobUri, cacheKey, pdfInstance] = result;
|
|
123
|
-
// Retornar o PDF como buffer
|
|
124
|
-
if (pdfInstance && pdfInstance.output) {
|
|
125
|
-
return pdfInstance.output('arraybuffer');
|
|
126
|
-
} else {
|
|
127
|
-
return blobUri; // Fallback para blob URI
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return result;
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.error('❌ Erro ao gerar etiqueta de peça:', error);
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Gera etiqueta de tamponamento
|
|
140
|
-
* @param {Object} dadosTamponamento - Dados do tamponamento
|
|
141
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
142
|
-
* @param {Object} options - Opções adicionais
|
|
143
|
-
* @returns {Promise<Buffer>} Buffer do PDF gerado
|
|
144
|
-
*/
|
|
145
|
-
export const makeTamponamentoLabel = async (dadosTamponamento, modeloEtiquetaId, options = {}) => {
|
|
146
|
-
try {
|
|
147
|
-
const worker = createLabelWorker();
|
|
148
|
-
|
|
149
|
-
const formattedData = formatTamponamentoData(dadosTamponamento);
|
|
150
|
-
|
|
151
|
-
const params = {
|
|
152
|
-
dataSource: [formattedData],
|
|
153
|
-
labels: await loadLabelTemplate(modeloEtiquetaId),
|
|
154
|
-
userPrefs: globalConfig,
|
|
155
|
-
cacheKey: `tamponamento-${dadosTamponamento.id}-${Date.now()}`,
|
|
156
|
-
...options
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const result = await worker.generateLabels(params);
|
|
160
|
-
console.log('✅ Etiqueta de tamponamento gerada:', dadosTamponamento.name);
|
|
161
|
-
|
|
162
|
-
// Extrair PDF do resultado
|
|
163
|
-
if (Array.isArray(result)) {
|
|
164
|
-
const [blobUri, cacheKey, pdfInstance] = result;
|
|
165
|
-
if (pdfInstance && pdfInstance.output) {
|
|
166
|
-
return pdfInstance.output('arraybuffer');
|
|
167
|
-
} else {
|
|
168
|
-
return blobUri;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return result;
|
|
173
|
-
} catch (error) {
|
|
174
|
-
console.error('❌ Erro ao gerar etiqueta de tamponamento:', error);
|
|
175
|
-
throw error;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Gera etiqueta de insumo
|
|
181
|
-
* @param {Object} dadosInsumo - Dados do insumo
|
|
182
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
183
|
-
* @param {Object} options - Opções adicionais
|
|
184
|
-
* @returns {Promise<Buffer>} Buffer do PDF gerado
|
|
185
|
-
*/
|
|
186
|
-
export const makeInsumoLabel = async (dadosInsumo, modeloEtiquetaId, options = {}) => {
|
|
187
|
-
try {
|
|
188
|
-
const worker = createLabelWorker();
|
|
189
|
-
|
|
190
|
-
const formattedData = formatInsumoData(dadosInsumo);
|
|
191
|
-
|
|
192
|
-
const params = {
|
|
193
|
-
dataSource: [formattedData],
|
|
194
|
-
labels: await loadLabelTemplate(modeloEtiquetaId),
|
|
195
|
-
userPrefs: globalConfig,
|
|
196
|
-
cacheKey: `insumo-${dadosInsumo.id}-${Date.now()}`,
|
|
197
|
-
...options
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const result = await worker.generateLabels(params);
|
|
201
|
-
console.log('✅ Etiqueta de insumo gerada:', dadosInsumo.name);
|
|
202
|
-
|
|
203
|
-
// Extrair PDF do resultado
|
|
204
|
-
if (Array.isArray(result)) {
|
|
205
|
-
const [blobUri, cacheKey, pdfInstance] = result;
|
|
206
|
-
if (pdfInstance && pdfInstance.output) {
|
|
207
|
-
return pdfInstance.output('arraybuffer');
|
|
208
|
-
} else {
|
|
209
|
-
return blobUri;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return result;
|
|
214
|
-
} catch (error) {
|
|
215
|
-
console.error('❌ Erro ao gerar etiqueta de insumo:', error);
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Gera etiqueta de retalho
|
|
222
|
-
* @param {Object} dadosRetalho - Dados do retalho
|
|
223
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
224
|
-
* @param {Object} options - Opções adicionais
|
|
225
|
-
* @returns {Promise<Buffer>} Buffer do PDF gerado
|
|
226
|
-
*/
|
|
227
|
-
export const makeRetalhoLabel = async (dadosRetalho, modeloEtiquetaId, options = {}) => {
|
|
228
|
-
try {
|
|
229
|
-
const worker = createLabelWorker();
|
|
230
|
-
|
|
231
|
-
const formattedData = formatRetalhoData(dadosRetalho);
|
|
232
|
-
|
|
233
|
-
const params = {
|
|
234
|
-
dataSource: [formattedData],
|
|
235
|
-
labels: await loadLabelTemplate(modeloEtiquetaId),
|
|
236
|
-
userPrefs: globalConfig,
|
|
237
|
-
cacheKey: `retalho-${dadosRetalho.scrapId}-${Date.now()}`,
|
|
238
|
-
...options
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const result = await worker.generateLabels(params);
|
|
242
|
-
console.log('✅ Etiqueta de retalho gerada:', dadosRetalho.name);
|
|
243
|
-
|
|
244
|
-
// Extrair PDF do resultado
|
|
245
|
-
if (Array.isArray(result)) {
|
|
246
|
-
const [blobUri, cacheKey, pdfInstance] = result;
|
|
247
|
-
if (pdfInstance && pdfInstance.output) {
|
|
248
|
-
return pdfInstance.output('arraybuffer');
|
|
249
|
-
} else {
|
|
250
|
-
return blobUri;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return result;
|
|
255
|
-
} catch (error) {
|
|
256
|
-
console.error('❌ Erro ao gerar etiqueta de retalho:', error);
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Gera etiqueta de volume
|
|
263
|
-
* @param {Object} dadosVolume - Dados do volume
|
|
264
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
265
|
-
* @param {Object} options - Opções adicionais
|
|
266
|
-
* @returns {Promise<Buffer>} Buffer do PDF gerado
|
|
267
|
-
*/
|
|
268
|
-
export const makeVolumeLabel = async (dadosVolume, modeloEtiquetaId, options = {}) => {
|
|
269
|
-
try {
|
|
270
|
-
const worker = createLabelWorker();
|
|
271
|
-
|
|
272
|
-
// Log detalhado dos dados de entrada
|
|
273
|
-
console.log(`🔍 Dados recebidos para etiqueta de volume:`, {
|
|
274
|
-
id: dadosVolume.volume_id || dadosVolume.id,
|
|
275
|
-
nome: dadosVolume.volume_nome || dadosVolume.name,
|
|
276
|
-
partes: dadosVolume.parts ? `${dadosVolume.parts.length} peças` : 'N/A',
|
|
277
|
-
projeto: dadosVolume.project_description,
|
|
278
|
-
cliente: dadosVolume.project_customer_name
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
const formattedData = formatVolumeData(dadosVolume);
|
|
282
|
-
|
|
283
|
-
// Log dos dados formatados
|
|
284
|
-
if (options.debug) {
|
|
285
|
-
console.log(`🔄 Dados formatados para template:`,
|
|
286
|
-
JSON.stringify(formattedData, null, 2).substring(0, 500) + '...'
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const params = {
|
|
291
|
-
dataSource: [formattedData],
|
|
292
|
-
labels: await loadLabelTemplate(modeloEtiquetaId),
|
|
293
|
-
userPrefs: globalConfig,
|
|
294
|
-
cacheKey: `volume-${dadosVolume.volume_id || dadosVolume.id}-${Date.now()}`,
|
|
295
|
-
...options
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
const result = await worker.generateLabels(params);
|
|
299
|
-
console.log('✅ Etiqueta de volume gerada:', dadosVolume.volume_nome || dadosVolume.name);
|
|
300
|
-
|
|
301
|
-
// Extrair PDF do resultado
|
|
302
|
-
if (Array.isArray(result)) {
|
|
303
|
-
const [blobUri, cacheKey, pdfInstance] = result;
|
|
304
|
-
if (pdfInstance && pdfInstance.output) {
|
|
305
|
-
return pdfInstance.output('arraybuffer');
|
|
306
|
-
} else {
|
|
307
|
-
return blobUri;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return result;
|
|
312
|
-
} catch (error) {
|
|
313
|
-
console.error('❌ Erro ao gerar etiqueta de volume:', error);
|
|
314
|
-
throw error;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
// ============================================================================
|
|
319
|
-
// FUNÇÕES DE SAÍDA (downloadPDF, sendToPrinter)
|
|
320
|
-
// ============================================================================
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Faz download do PDF
|
|
324
|
-
* @param {Buffer} pdfBuffer - Buffer do PDF
|
|
325
|
-
* @param {string} filename - Nome do arquivo
|
|
326
|
-
*/
|
|
327
|
-
export const downloadPDF = async (pdfBuffer, filename = 'etiqueta.pdf') => {
|
|
328
|
-
try {
|
|
329
|
-
// Implementar download do PDF
|
|
330
|
-
if (typeof window !== 'undefined') {
|
|
331
|
-
// Ambiente browser
|
|
332
|
-
const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
333
|
-
const url = URL.createObjectURL(blob);
|
|
334
|
-
const link = document.createElement('a');
|
|
335
|
-
link.href = url;
|
|
336
|
-
link.download = filename;
|
|
337
|
-
document.body.appendChild(link);
|
|
338
|
-
link.click();
|
|
339
|
-
document.body.removeChild(link);
|
|
340
|
-
URL.revokeObjectURL(url);
|
|
341
|
-
} else {
|
|
342
|
-
// Ambiente Node.js - retorna o buffer para processamento externo
|
|
343
|
-
console.log('📁 PDF gerado para download:', filename);
|
|
344
|
-
return pdfBuffer;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
console.log('📥 Download realizado:', filename);
|
|
348
|
-
} catch (error) {
|
|
349
|
-
console.error('❌ Erro no download:', error);
|
|
350
|
-
throw error;
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Envia PDF para impressora
|
|
356
|
-
* @param {Buffer} pdfBuffer - Buffer do PDF
|
|
357
|
-
* @param {Object} printOptions - Opções de impressão
|
|
358
|
-
*/
|
|
359
|
-
export const sendToPrinter = async (pdfBuffer, printOptions = {}) => {
|
|
360
|
-
try {
|
|
361
|
-
const printerStatus = await getPrinterStatus();
|
|
362
|
-
|
|
363
|
-
if (!printerStatus.connected) {
|
|
364
|
-
throw new Error(`Impressora não conectada: ${globalConfig.printerName || 'Nenhuma configurada'}`);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// Implementar envio para impressora (usar biblioteca específica)
|
|
368
|
-
// Exemplo: node-printer, electron-printer, etc.
|
|
369
|
-
|
|
370
|
-
console.log('🖨️ Enviando para impressora:', globalConfig.printerName);
|
|
371
|
-
|
|
372
|
-
// Simular envio (substituir por implementação real)
|
|
373
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
374
|
-
|
|
375
|
-
console.log('✅ Etiqueta enviada para impressão');
|
|
376
|
-
|
|
377
|
-
return {
|
|
378
|
-
success: true,
|
|
379
|
-
printerName: globalConfig.printerName,
|
|
380
|
-
timestamp: new Date().toISOString()
|
|
381
|
-
};
|
|
382
|
-
} catch (error) {
|
|
383
|
-
console.error('❌ Erro ao imprimir:', error);
|
|
384
|
-
throw error;
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// ============================================================================
|
|
389
|
-
// FUNÇÕES DE ENVIO INTELIGENTE (sendXLabel)
|
|
390
|
-
// ============================================================================
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Envia etiqueta de peça (imprime se conectado, senão baixa)
|
|
394
|
-
* @param {Object} dadosPeca - Dados da peça
|
|
395
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
396
|
-
* @param {Object} options - Opções adicionais
|
|
397
|
-
*/
|
|
398
|
-
export const sendPartLabel = async (dadosPeca, modeloEtiquetaId, options = {}) => {
|
|
399
|
-
try {
|
|
400
|
-
const pdf = await makePartLabel(dadosPeca, modeloEtiquetaId, options);
|
|
401
|
-
const printerStatus = await getPrinterStatus();
|
|
402
|
-
|
|
403
|
-
if (printerStatus.connected) {
|
|
404
|
-
await sendToPrinter(pdf);
|
|
405
|
-
} else {
|
|
406
|
-
const filename = `peca-${dadosPeca.codigo || dadosPeca.id}.pdf`;
|
|
407
|
-
await downloadPDF(pdf, filename);
|
|
408
|
-
}
|
|
409
|
-
} catch (error) {
|
|
410
|
-
console.error('❌ Erro no envio inteligente de peça:', error);
|
|
411
|
-
throw error;
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Envia etiqueta de tamponamento (imprime se conectado, senão baixa)
|
|
417
|
-
*/
|
|
418
|
-
export const sendTamponamentoLabel = async (dadosTamponamento, modeloEtiquetaId, options = {}) => {
|
|
419
|
-
try {
|
|
420
|
-
const pdf = await makeTamponamentoLabel(dadosTamponamento, modeloEtiquetaId, options);
|
|
421
|
-
const printerStatus = await getPrinterStatus();
|
|
422
|
-
|
|
423
|
-
if (printerStatus.connected) {
|
|
424
|
-
await sendToPrinter(pdf);
|
|
425
|
-
} else {
|
|
426
|
-
const filename = `tamponamento-${dadosTamponamento.id}.pdf`;
|
|
427
|
-
await downloadPDF(pdf, filename);
|
|
428
|
-
}
|
|
429
|
-
} catch (error) {
|
|
430
|
-
console.error('❌ Erro no envio inteligente de tamponamento:', error);
|
|
431
|
-
throw error;
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Envia etiqueta de insumo (imprime se conectado, senão baixa)
|
|
437
|
-
*/
|
|
438
|
-
export const sendInsumoLabel = async (dadosInsumo, modeloEtiquetaId, options = {}) => {
|
|
439
|
-
try {
|
|
440
|
-
const pdf = await makeInsumoLabel(dadosInsumo, modeloEtiquetaId, options);
|
|
441
|
-
const printerStatus = await getPrinterStatus();
|
|
442
|
-
|
|
443
|
-
if (printerStatus.connected) {
|
|
444
|
-
await sendToPrinter(pdf);
|
|
445
|
-
} else {
|
|
446
|
-
const filename = `insumo-${dadosInsumo.id}.pdf`;
|
|
447
|
-
await downloadPDF(pdf, filename);
|
|
448
|
-
}
|
|
449
|
-
} catch (error) {
|
|
450
|
-
console.error('❌ Erro no envio inteligente de insumo:', error);
|
|
451
|
-
throw error;
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Envia etiqueta de retalho (imprime se conectado, senão baixa)
|
|
457
|
-
*/
|
|
458
|
-
export const sendRetalhoLabel = async (dadosRetalho, modeloEtiquetaId, options = {}) => {
|
|
459
|
-
try {
|
|
460
|
-
const pdf = await makeRetalhoLabel(dadosRetalho, modeloEtiquetaId, options);
|
|
461
|
-
const printerStatus = await getPrinterStatus();
|
|
462
|
-
|
|
463
|
-
if (printerStatus.connected) {
|
|
464
|
-
await sendToPrinter(pdf);
|
|
465
|
-
} else {
|
|
466
|
-
const filename = `retalho-${dadosRetalho.scrapId}.pdf`;
|
|
467
|
-
await downloadPDF(pdf, filename);
|
|
468
|
-
}
|
|
469
|
-
} catch (error) {
|
|
470
|
-
console.error('❌ Erro no envio inteligente de retalho:', error);
|
|
471
|
-
throw error;
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Envia etiqueta de volume (imprime se conectado, senão baixa)
|
|
477
|
-
*/
|
|
478
|
-
export const sendVolumeLabel = async (dadosVolume, modeloEtiquetaId, options = {}) => {
|
|
479
|
-
try {
|
|
480
|
-
const pdf = await makeVolumeLabel(dadosVolume, modeloEtiquetaId, options);
|
|
481
|
-
const printerStatus = await getPrinterStatus();
|
|
482
|
-
|
|
483
|
-
if (printerStatus.connected) {
|
|
484
|
-
await sendToPrinter(pdf);
|
|
485
|
-
} else {
|
|
486
|
-
const filename = `volume-${dadosVolume.volume_id}.pdf`;
|
|
487
|
-
await downloadPDF(pdf, filename);
|
|
488
|
-
}
|
|
489
|
-
} catch (error) {
|
|
490
|
-
console.error('❌ Erro no envio inteligente de volume:', error);
|
|
491
|
-
throw error;
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
// ============================================================================
|
|
496
|
-
// FUNÇÕES DE GERAÇÃO EM LOTE
|
|
497
|
-
// ============================================================================
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Gera múltiplas etiquetas em lote
|
|
501
|
-
* @param {Array} items - Array de itens para gerar etiquetas
|
|
502
|
-
* @param {string} modeloEtiquetaId - ID do modelo de etiqueta
|
|
503
|
-
* @param {string} type - Tipo de etiqueta (parts, tamponamentos, etc.)
|
|
504
|
-
* @returns {Promise<Array>} Array de PDFs gerados
|
|
505
|
-
*/
|
|
506
|
-
export const makeBatchLabels = async (items, modeloEtiquetaId, type = 'parts') => {
|
|
507
|
-
const results = [];
|
|
508
|
-
|
|
509
|
-
for (const item of items) {
|
|
510
|
-
try {
|
|
511
|
-
let pdf;
|
|
512
|
-
|
|
513
|
-
switch (type) {
|
|
514
|
-
case 'parts':
|
|
515
|
-
pdf = await makePartLabel(item, modeloEtiquetaId);
|
|
516
|
-
break;
|
|
517
|
-
case 'tamponamentos':
|
|
518
|
-
pdf = await makeTamponamentoLabel(item, modeloEtiquetaId);
|
|
519
|
-
break;
|
|
520
|
-
case 'insumos':
|
|
521
|
-
pdf = await makeInsumoLabel(item, modeloEtiquetaId);
|
|
522
|
-
break;
|
|
523
|
-
case 'retalhos':
|
|
524
|
-
pdf = await makeRetalhoLabel(item, modeloEtiquetaId);
|
|
525
|
-
break;
|
|
526
|
-
case 'volumes':
|
|
527
|
-
pdf = await makeVolumeLabel(item, modeloEtiquetaId);
|
|
528
|
-
break;
|
|
529
|
-
default:
|
|
530
|
-
throw new Error(`Tipo de etiqueta não suportado: ${type}`);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
results.push(pdf);
|
|
534
|
-
} catch (error) {
|
|
535
|
-
console.error(`❌ Erro ao gerar etiqueta para item ${item.id}:`, error);
|
|
536
|
-
results.push(null);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
return results;
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
// ============================================================================
|
|
544
|
-
// FUNÇÕES AUXILIARES
|
|
545
|
-
// ============================================================================
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Carrega template de etiqueta
|
|
549
|
-
* @param {string} templateId - ID do template
|
|
550
|
-
* @returns {Promise<Array>} Configuração do template
|
|
551
|
-
*/
|
|
552
|
-
const loadLabelTemplate = async (templateId) => {
|
|
553
|
-
try {
|
|
554
|
-
// Importar templates
|
|
555
|
-
const { getTemplateById } = await import('./templates.js');
|
|
556
|
-
|
|
557
|
-
// Buscar template pelo ID (agora é uma função async)
|
|
558
|
-
const templateData = await getTemplateById(templateId);
|
|
559
|
-
|
|
560
|
-
if (!templateData) {
|
|
561
|
-
console.warn(`Template ${templateId} não encontrado, usando template padrão`);
|
|
562
|
-
// Retornar template básico como fallback
|
|
563
|
-
return [
|
|
564
|
-
{
|
|
565
|
-
pageWidth: 800,
|
|
566
|
-
pageHeight: 50,
|
|
567
|
-
pageHorizontalSpace: 0,
|
|
568
|
-
pageVerticalSpace: 0,
|
|
569
|
-
pageMarginLeft: 0,
|
|
570
|
-
pageMarginTop: 0,
|
|
571
|
-
pageLines: 1,
|
|
572
|
-
pageColumns: 1,
|
|
573
|
-
pageShowBorder: false,
|
|
574
|
-
left: 0,
|
|
575
|
-
top: 0,
|
|
576
|
-
width: 100,
|
|
577
|
-
height: 50
|
|
578
|
-
}
|
|
579
|
-
];
|
|
580
|
-
}
|
|
581
|
-
return templateData;
|
|
582
|
-
} catch (error) {
|
|
583
|
-
console.error('❌ Erro ao carregar template:', error);
|
|
584
|
-
// Retornar template básico em caso de erro
|
|
585
|
-
return [
|
|
586
|
-
{
|
|
587
|
-
pageWidth: 210,
|
|
588
|
-
pageHeight: 297,
|
|
589
|
-
pageHorizontalSpace: 0,
|
|
590
|
-
pageVerticalSpace: 0,
|
|
591
|
-
pageMarginLeft: 10,
|
|
592
|
-
pageMarginTop: 10,
|
|
593
|
-
pageLines: 1,
|
|
594
|
-
pageColumns: 1,
|
|
595
|
-
pageShowBorder: false,
|
|
596
|
-
left: 0,
|
|
597
|
-
top: 0,
|
|
598
|
-
width: 190,
|
|
599
|
-
height: 277
|
|
600
|
-
}
|
|
601
|
-
];
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
// ============================================================================
|
|
607
|
-
// EXPORTAÇÕES PADRÃO
|
|
608
|
-
// ============================================================================
|
|
609
|
-
|
|
610
|
-
const api = {
|
|
611
|
-
// Inicialização
|
|
612
|
-
init,
|
|
613
|
-
configurePrinter,
|
|
614
|
-
getPrinterStatus,
|
|
615
|
-
|
|
616
|
-
// Geração de etiquetas
|
|
617
|
-
makePartLabel,
|
|
618
|
-
makeTamponamentoLabel,
|
|
619
|
-
makeInsumoLabel,
|
|
620
|
-
makeRetalhoLabel,
|
|
621
|
-
makeVolumeLabel,
|
|
622
|
-
|
|
623
|
-
// Saída e impressão
|
|
624
|
-
downloadPDF,
|
|
625
|
-
sendToPrinter,
|
|
626
|
-
|
|
627
|
-
// Envio inteligente
|
|
628
|
-
sendPartLabel,
|
|
629
|
-
sendTamponamentoLabel,
|
|
630
|
-
sendInsumoLabel,
|
|
631
|
-
sendRetalhoLabel,
|
|
632
|
-
sendVolumeLabel,
|
|
633
|
-
|
|
634
|
-
// Lote
|
|
635
|
-
makeBatchLabels,
|
|
636
|
-
|
|
637
|
-
// Constantes
|
|
638
|
-
labelTypeNames,
|
|
639
|
-
|
|
640
|
-
// Funções de formatação de dados (expostas para uso externo)
|
|
641
|
-
formatPartData,
|
|
642
|
-
formatTamponamentoData,
|
|
643
|
-
formatInsumoData,
|
|
644
|
-
formatRetalhoData,
|
|
645
|
-
formatVolumeData,
|
|
646
|
-
dataTypeList,
|
|
647
|
-
getInputsByCategory,
|
|
648
|
-
getAllCategoriesId,
|
|
649
|
-
getPartsForLabels,
|
|
650
|
-
getInputForLabels,
|
|
651
|
-
getPartsFromProjectToLabels
|
|
652
|
-
};
|
|
653
|
-
|
|
654
|
-
export default api;
|