From 63e3883984a5fb2c0fa3e666b58f169a3e7c4b31 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 13 Mar 2026 21:48:10 -0300 Subject: [PATCH] Nueva funcion de impresion de pedidos --- .idea/.gitignore | 8 ++++++ index.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/index.js b/index.js index ef382b0..36f916f 100644 --- a/index.js +++ b/index.js @@ -84,6 +84,13 @@ app.post('/digitalpowerstock/ticket/gondola', (req, res) => { res.send(200) }) +app.post('/digitalpowerstock/ticket/pedido', (req, res) => { + const { cliente, direccion, altura, ciudad, cp, telefono, email, comprobante, fecha, productos, total, estado, tipo_envio, tipo_pago, calles } = req.body; + + ticketPedido(cliente, direccion, altura, ciudad, cp, telefono, email, comprobante, fecha, productos, total, estado, tipo_envio, tipo_pago, calles) + res.send(200) +}) + app.post('/facturador/ticket/a', (req, res) => { const { comercio, comercio_cuit, inicio_actividades, condicion_iva_comercio, punto_venta, cae, vencimiento_cae, iva_contenido, cliente_cuit, cliente_condicion, cliente_direccion, nombre, direccion, localidad, provincia, comprobante, cliente, fecha, qr_link, productos, total, subtotal } = req.body; ticketFacturadorA(comercio, comercio_cuit, inicio_actividades, condicion_iva_comercio, punto_venta, cae, vencimiento_cae, iva_contenido, cliente_cuit, cliente_condicion, cliente_direccion, nombre, direccion, localidad, provincia, comprobante, cliente, fecha, qr_link, productos, total, subtotal) @@ -376,6 +383,72 @@ async function ticketDPSTockGondola( } } +async function ticketPedido( + cliente, direccion, altura, ciudad, cp, telefono, email, comprobante, fecha, productos, total, estado, tipo_envio, tipo_pago, calles +) { + try { + let ticket = ""; + + // Encabezado + ticket += init(); + ticket += center(); + ticket += textDoubleSize() + boldOn() + "NUEVO PEDIDO" + boldOff() + textNormal() + line(2); + ticket += left(); + + ticket += "Comprobante: #" + comprobante + line(); + ticket += "Fecha: " + fecha + line(); + ticket += "Estado: " + estado + line(); + + ticket += printDoubleLine(); + + ticket += boldOn() + "DATOS DEL CLIENTE" + boldOff() + line(); + ticket += "Cliente: " + cliente + line(); + ticket += "Telefono: " + telefono + line(); + ticket += "Email: " + (email || "-") + line(); + + ticket += printDoubleLine(); + + ticket += boldOn() + "DATOS DE ENVIO" + boldOff() + line(); + ticket += "Tipo: " + tipo_envio + line(); + ticket += "Direccion: " + direccion + " " + altura + line(); + ticket += "Calles: " + (calles || "-") + line(); + ticket += "Ciudad: " + ciudad + " (" + cp + ")" + line(); + + ticket += printDoubleLine(); + + ticket += boldOn() + "DATOS DE PAGO" + boldOff() + line(); + ticket += "Metodo de pago: " + tipo_pago + line(); + + ticket += printDoubleLine(); + + ticket += printProducts(JSON.parse(productos)); + ticket += line(); + + // Total + ticket += boldOn(); + ticket += textDoubleHeight() + printBetween("Total: ", `$${total}`) + textNormal() + line(3); + ticket += boldOff(); + + // Corte + ticket += cut(); + + // Convertir a CP850 (acentos correctos) + const data = iconv.encode(ticket, "CP850"); + + // Enviar a la impresora + printer.printDirect({ + data, + printer: printer.getDefaultPrinterName(), + type: "RAW", + success: jobID => console.log("Trabajo enviado:", jobID), + error: err => console.error("Error:", err) + }); + + } catch (error) { + console.error("Error al imprimir:", error); + } +} + async function ticketFacturadorA( comercio, comercio_cuit, inicio_actividades, condicion_iva_comercio, punto_venta, cae, vencimiento_cae, iva_contenido, cliente_cuit, cliente_condicion, cliente_direccion, nombre, direccion, localidad, provincia, comprobante, cliente, fecha, qr_link, productos, total, subtotal ) {