initial upload

This commit is contained in:
Kai Waggeling 2025-05-17 16:23:48 +02:00
parent ac114da487
commit 7c1cfdff51
63 changed files with 6883 additions and 0 deletions

89
functions/generateZPL.mjs Normal file
View file

@ -0,0 +1,89 @@
import {
Label,
Grid,
Text,
Line,
Box,
Circle,
Barcode,
FontFamily,
PrintDensity,
Spacing,
SizeType
} from "jszpl";
import {
Printer as PrinterTable
} from "../sequelize/printer.model.mjs";
import {
Template as TemplateTable
} from "../sequelize/template.model.mjs";
import {
Medium as MediaTable
} from "../sequelize/media.model.mjs";
import {
Queue as QueueTable
} from "../sequelize/queue.model.mjs";
import {
Job as JobTable
} from "../sequelize/job.model.mjs";
export async function GenerateZPL(queueId, limit = undefined)
{
let queue = await QueueTable.findByPk(queueId);
let printer = await queue.getPrinter();
let medium = await printer.getMedium();
let jobs = await queue.getJobs({
limit
});
var Result = '';
while (jobs.length > 0) {
// get jobs for row
let nextJobs = jobs.splice(0, medium.columns);
// generate new Label
const label = new Label();
label.printDensity = new PrintDensity(printer.density);
label.width = 100;
label.height = 50;
label.padding = new Spacing(10);
// generate Grid
const grid = new Grid();
label.content.push(grid);
grid.border = 1;
grid.columnSpacing = 2;
grid.rowSpacing = 0;
for (let cIndex = 0; cIndex < medium.columns; cIndex++) {
grid.columns.push(new Size(1, SizeType.Relative));
}
grid.rows.push(new Size(1, SizeType.Relative));
nextJobs.forEach((job, columnNumber) => {
let template = job.getTemplate();
const text = new Text();
label.content.push(text);
text.fontFamily = new FontFamily("0");
text.text = 'Hello World!';
});
Result += label.generateZPL();
}
return Result;
}