Pruebas de impresion

This commit is contained in:
2026-01-14 17:39:26 +01:00
parent 6d989423bb
commit 21febde514
5 changed files with 302 additions and 271 deletions

View File

@@ -1,2 +1,2 @@
#/bin/bash
docker compose -f deployment/local/docker/docker-compose.yaml --project-directory ./ up
docker compose -f deployment/local/docker/docker-compose.yaml --project-directory ./ build

View File

@@ -0,0 +1,15 @@
// Order fulfillment is the process of preparing, packing,
// and shipping items to customers after they place an order.
//
// Contiene los datos de estado de envio, empresa encargada y direccion.
//
// Order -n-> FulfillmentOrder -n-> Fulfillment
// Fulfillment Representa el trabajo completado
export const FULFILLMENTORDER = {
}
export const FULFILLMENT = {
}

View File

@@ -1,6 +1,62 @@
import { NullablePartial } from "#shared/NullablePartail.js"
export declare namespace Shopify {
export type DeliveryMethod = {
id: number,
method_type: "local" | "delivery" | string,
min_delivery_date_time: string,
max_delivery_date_time: string,
additional_information: {
},
service_code: "Economy" | string,
source_reference: "Shopify" | string,
branded_promise: {
name: string,
handle: string
},
presented_name: "Economy" | string,
f
}
export type FulfillmentOrder = {
id: string,
order_id: number,
shop_id: number,
status: "open" | "close" | "hold",
assigned_location_id: number,
destienation: Address,
delivery_method: DeliveryMethod,
fulfill_at: string, // solo fecha, sin hora
fulfill_by: string, // solo fecha, sin hora
fulfillment_holds: {
reason: string, // hay una lista de codigos de fulfillment_holds
reason_notes: string
}[],
international_duties: {
// Lista de aranceles
},
line_items: LineItem[],
request_status: "submitted" | "unsubmitted" | string,
supported_actions: string[],
merchant_request: {
message: string,
request_options: {
shipping_method: string,
note: string,
date: string, // ISO date
},
kind: string,
}[],
assigned_location: Address,
created_at: string, // ISO date
updated_at: string, // ISO date
}
export type Fulfillment = {
}
export type ShippingLine = {
id: number,
carrier_identifier: string,

File diff suppressed because one or more lines are too long

230
src/printer-ejemplo.ts Normal file
View File

@@ -0,0 +1,230 @@
import net from "net"
import cors from 'cors';
import express from "express"
const app = express();
const PORT = 3000;
const client = new net.Socket();
// Middleware
app.use(cors());
// Webhooks often require raw body for signature verification if not handled by express.json()
// using verify option in body-parser/express.json to get raw body if needed.
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// GET Endpoint: /process
// Example usage: /process?name=Alex&attr1=fast&attr2=smart&attr3=kind&depto="I.T. DEPARTMENT"
app.get('/print', (req, res) => {
console.log("Conexion reibida", req.query)
const { name, attr1, attr2, attr3, depto } = req.query;
// Basic validation to ensure all parameters are provided
if (!name) {
return res.status(400).json({
error: "Missing parameters. Please provide name, attr1, attr2, and attr3."
});
}
client.connect(PRINTER_PORT, PRINTER_IP, () => {
console.log('Connected to ZSim Printer');
const res = client.write(zplData(String(name), [String(attr1), String(attr2), String(attr3)], String(depto)), (res) => {
console.log("resultado de la impresion", res)
});
console.log("Resultado", res)
});
client.on('close', () => console.log('Print job sent and connection closed.'));
client.on('error', (err) => console.error('Printer Error:', err.message));
// Logic for handling the data
const responseData = {
message: `Data received for ${name}`,
receivedAttributes: {
attribute_one: attr1,
attribute_two: attr2,
attribute_three: attr3
},
timestamp: new Date().toISOString()
};
res.json(responseData);
});
app.get("/health", (req, res) => {
res.json({ date: new Date().toISOString(), status: "que no imprimas" })
})
/**
app.listen(PORT, "0.0.0.0", () => {
console.log(`Server is running on http://localhost:${PORT}`);
console.log(`Test link: http://localhost:${PORT}/process?name=User&attr1=val1&attr2=val2&attr3=val3`);
});
*/
// Printer details
const PRINTER_IP = '192.168.1.254';
const PRINTER_PORT = 9100; // Standard raw printing port
const NOMBRE = "ALVAR SAN MARTIN"
const ATTR1 = ""
const ATTR2 = ""
const ATTR3 = ""
const LOGO = `
^FO310,65^FD - --.. ^FS
^FO310,77^FD )*ttefCf5J2523uv ^FS
^FO310,89^FD _ngd44dVdVVdVVVVz_ ^FS
^FO310,101^FD -I! IEhhhhhhhhhhhhhh3##z}>+ ^FS
^FO310,113^FD +TS[- jdhhhhhhhhhhhhhhVddddgqL) ^FS
^FO310,125^FD )uws >6Vhhhhhhhhhhhhhhhhhhhhh4Su: ^FS
^FO310,137^FD <oz%ii?6VhhhhhhhhhhhhhhhhhhhhhhhVEq% ^FS
^FO310,149^FD |t5h4Vhhhhhhhhhhhhhhhhhdddd4dS6o}| ^FS
^FO310,161^FD -)?u!- |%7i:_<jqFVVhhhhhhhhhhhhhhCoeLaet]|_ ^FS
^FO310,173^FD _2F5* )J wS|sfhhhhhhhhhhhhhhhq3TIr ^FS
^FO310,185^FD .#+Ipyl >n Jgi=)]qVdhhhhhhhhhhhhVVd4j ^FS
^FO310,197^FD .J= _1mJ))n Cgl)>ioIugdhhhhhhhhhhhhhhg! ^FS
^FO310,209^FD J: +7mfT Cg: |vjS4VhhhhhhhhhhhVg> ^FS
^FO310,221^FD _>yx: <Tn -)fqr<<>i[] )o6hhhhhhhhhhhhVC ^FS
^FO310,233^FD -===_ : -=|)%11?I!%< -%5VhVhhhhhhhhhhj. ^FS
^FO310,245^FD :6q):|?Sw+.=z43ydVhhhhhhhdC ^FS
^FO310,257^FD 56. >gq< .Lh}%yVVhhhhhV6= ^FS
^FO310,269^FD .5ql!fJ*= .nVl rmhdhhhV2= ^FS
^FO310,281^FD 56-:t6o_ .TVl?IvTgdhVw ^FS
^FO310,293^FD .:6S+ <Jp?+- -#d[ )LSEy_ ^FS
^FO310,305^FD :)+- =i}Iv+ l?l<. _* )7p| ^FS
^FO310,317^FD :)vx<- _|: =. ^FS
^FO310,329^FD _+i)c:_. .:|cri<. ^FS
^FO310,341^FD :|ilv)):. ..=)v)xi|=. ^FS
^FO310,353^FD ._:>xii)vi_+::=:+:=)+<)ivv|)>+ ^FS
^FO310,365^FD .-:+||)>|>)x)i)+:):_- ^FS
^FO310,377^FD ^FS
^FO310,389^FD^FS
`
// Simple ZPL label example
const zplData = (name: string, attrs: string[], departamento: string) => `
^XA
^FX Header bar
^FO30,50^GD20,20,15,B,R^FS
^FO50,50^GD20,20,15,B,R^FS
^FO70,50^GD20,20,15,B,R^FS
^FO90,50^GD20,20,15,B,R^FS
^FO110,50^GD20,20,15,B,R^FS
^FO130,50^GD20,20,15,B,R^FS
^FO150,50^GD20,20,15,B,R^FS
^FO170,50^GD20,20,15,B,R^FS
^FO190,50^GD20,20,15,B,R^FS
^FO210,50^GD20,20,15,B,R^FS
^FO230,50^GD20,20,15,B,R^FS
^FO250,50^GD20,20,15,B,R^FS
^FO270,50^GD20,20,15,B,R^FS
^FO290,50^GD20,20,15,B,R^FS
^FO310,50^GD20,20,15,B,R^FS
^FO330,50^GD20,20,15,B,R^FS
^FO350,50^GD20,20,15,B,R^FS
^FO370,50^GD20,20,15,B,R^FS
^FO390,50^GD20,20,15,B,R^FS
^FO410,50^GD20,20,15,B,R^FS
^FO30,80^GB400,5,5,B,R^FS
^FX Name section
^As,100,60
^FO40,100^FDEVA2026^FS
^FX Logo
${LOGO}
^FX Side bars
^Asb,30,6
^FO700,0^FD SAVEFAMILYGPS SAVEFAMILYGPS SAVEFAMILYGPS SAVEFAMILYGPS SAVEFAMILYGPS SAVEFAMILYGPS SAVEFAMILYGPS SAVEFAMILYGPS ^FS
^FO40,440^GB30,500,30,B,R^FS
^FO37,440^GD45,20,7,W,L^FS
^FO37,460^GD45,20,7,W,L^FS
^FO37,480^GD45,20,7,W,L^FS
^FO37,500^GD45,20,7,W,L^FS
^FO37,520^GD45,20,7,W,L^FS
^FO37,540^GD45,20,7,W,L^FS
^FO37,560^GD45,20,7,W,L^FS
^FO37,580^GD45,20,7,W,L^FS
^FO37,600^GD45,20,7,W,L^FS
^FO37,620^GD45,20,7,W,L^FS
^FO37,640^GD45,20,7,W,L^FS
^FO37,660^GD45,20,7,W,L^FS
^FO37,680^GD45,20,7,W,L^FS
^FO37,700^GD45,20,7,W,L^FS
^FO37,720^GD45,20,7,W,L^FS
^FO37,740^GD45,20,7,W,L^FS
^FO37,760^GD45,20,7,W,L^FS
^FO37,780^GD45,20,7,W,L^FS
^FO37,800^GD45,20,7,W,L^FS
^FO37,820^GD45,20,7,W,L^FS
^FO37,840^GD45,20,7,W,L^FS
^FO37,860^GD45,20,7,W,L^FS
^FO37,880^GD45,20,7,W,L^FS
^FO37,900^GD45,20,7,W,L^FS
^FO37,920^GD45,20,7,W,L^FS
^FX Data
^As,60,20
^FO40,275^FD${name}^FS
^CI28
^FO40,350^FDアーラナー・エートー^FS
^FO30,390^GB600,5,5,B,R^FS
^FO30,397^GB600,5,5,B,R^FS
^As,14,4
^FO100,470^FD${attrs[0]}^FS
^FO300,480^FD携帯電話^FS
^As,14,4
^FO100,560^FD${attrs[1]}^FS
^FO300,570^FDデベロッパー^FS
^As,14,4
^FO100,610^FD${attrs[2]}^FS
^FO300,620^FD技師^FS
^FX footer
^FO330,740^GB250,80,3,B,R^FS
^As,40,20
^FO350,760^FDDO NOT TOUCH^FS
^As,100,60
^FO40,950^FD${departamento}^FS
^CI28
^FO40,1060^FD情報技術・局^FS
^As,20
^FO40,1150^FD2026.01.01 EDITION^FS
^XZ
`;
const AITZ = `
^XA
^FO10,10 ^BQ, 2,5
^FDMA,https://www.youtube.com/watch?v=XfELJU1mRMg^FS
^XZ
`
client.connect(PRINTER_PORT, PRINTER_IP, () => {
console.log('Connected to ZSim Printer');
const res = client.write(AITZ, (res) => {
console.log("resultado de la impresion", res)
});
console.log("Resultado", res)
});
client.on('close', () => console.log('Print job sent and connection closed.'));
client.on('error', (err) => console.error('Printer Error:', err.message));