Skip to main content

Printing

Overview & Version Comparison​

The Printing System bridges the CodeIgniter 4 web application and physical Zebra (ZT411, ZT411R, ZD421) label printers in the factory. Both v2 and v1 coexist in the codebase until v1 is deprecated; jobs are tagged via print_job.print_engine ('zpl' for v2, 'bartender' for v1).

CapabilityPrinting System v2 (Current — Direct ZPL)Printing System v1 (Legacy — BarTender)
Engine Flagprint_job.print_engine = 'zpl'print_job.print_engine = 'bartender'
Worker / Agentshelter-print-agent (Python service on SEI-APP1)BarTender Automation Suite (.btin integrations on SEI-APP1 / PLANT 05)
Printer TransportDirect raw TCP socket (Port 9100) using ZPL II & SGDWindows Print Spooler via Print Maestro
Printer Registryprinter database table, managed at /admin/printers & synced via /api/printer/get_allHardcoded in .btin integrations & Windows queues
Templateszpl_template table + shelter-print-agent/templates/*.zpl (managed at /admin/zpl_templates)BarTender Designer .btw files
Progress & TelemetryLive X / Y tracking (~HS + SGD odometer), ~HQES error bitmask decoding, live heartbeatNone (fire-and-forget queue)
CancellationRemote cancel via /api/printer/pending_cancellations -> Zebra ~JA RAM purgeManual cancel in Print Maestro
Primary UI/eifs/full_line_labels_v2/eifs/full_line_labels and legacy station views

Printing System v2 (Current — Direct ZPL Architecture)​

Architecture Flow​

Web App (CI4) -> Insert row in print_job (print_engine='zpl')
-> shelter-print-agent polls GET /api/printer/pending_jobs & GET /api/printer/get_all
-> Renders .zpl template (substitutes {{vars}} + ^PQ{copies},0,1,Y)
-> Dispatches raw ZPL over TCP 9100 to target Zebra printer
-> Polls ~HS / ~HQES / SGD odometer -> POST /api/printer/job_progress & /api/printer/report_status
-> Label Printing Center v2 polls GET /api/printer/status every 3s

Database Schema (v2 Additions)​

  1. printer Table (migrations 2026-10-23-151000_CreatePrinterTable & 2026-11-24-154500_AddRoutingFieldsToPrinterTable):
    • Identity & network: id, name, model, ip_address, port (default 9100), windows_queue_name
    • Routing: location_id (FK -> location.id), print_types (JSON array of ints, e.g. [2,3,4]), template_suffix (e.g. _Rotation)
    • Live telemetry: status, status_details, buffer_count, last_status_check
    • Archiving: is_active (1 = active, 0 = archived)
    • Model: App\Models\Printer_model (normalizes print_types to int[])
  2. zpl_template & zpl_template_history Tables (migration 2026-11-23-231500_CreateZplTemplateTables):
    • Stores ZPL template source, dimensions (width_in, height_in, dpmm), orientation metadata, content hashes, and revision history.
  3. print_job Visibility & Deferred Inventory Columns (migrations 2026-10-23-150000_UpdatePrintJobTableForVisibility, 2026-11-24-140000_AddPrintEngineToPrintJob, & 2026-11-24-213000_AddDeferredInventoryToPrintJob):
    • Adds print_engine ('zpl' / 'bartender'), live status, printed_copies, error_message, cancellation tracking, and deferred inventory columns (inventory_payload, inventory_committed).
    • Also registers the Print Job Cancelled notification type in notification_type for mid-print cancellation alerts.

v2 Controllers & API Endpoints​

App\Controllers\Api\Printer (/api/printer/*)​

  • GET /api/printer/get_all — Returns active printers (is_active = 1) with location, print_types, and template_suffix. Pass ?include_archived=1 to include archived printers (used by /admin/printers).
  • GET /api/printer/status — Returns active printers plus the cached print agent heartbeat summary for the Label Printing Center v2 UI.
  • POST /api/printer/heartbeat — Lightweight agent heartbeat endpoint.
  • POST /api/printer/report_status — Receives live Zebra telemetry (status, status_details, buffer_count) from shelter-print-agent. Does not overwrite ip_address (database is the source of truth).
  • GET /api/printer/pending_jobs — Returns queued ZPL jobs for shelter-print-agent to execute.
  • GET /api/printer/pending_cancellations — Returns jobs cancelled in the web UI so the agent can issue ~JA.
  • POST /api/printer/job_progress — Receives real-time X / Y progress, odometer readings, and terminal job states (completed, cancelled, error states). Automatically commits deferred inventory via App\Libraries\PrintInventoryService when a ZPL job transitions to completed.
  • POST /api/printer/create (Admin) — Adds a new printer to the printer table.
  • POST /api/printer/update/{id} (Admin) — Updates printer name, IP, port, model, location, print_types, template_suffix, or windows_queue_name.
  • POST /api/printer/set_archived/{id} (Admin) — Archives (is_active = 0) or restores (is_active = 1) a printer.

App\Controllers\Api\PrintJob (/api/print_job/*)​

  • GET /api/print_job/for_job/{job_id} — Returns active/queued ZPL jobs, recent terminal jobs, active printers, and agent heartbeat scoped to a specific production job_id.
  • POST /api/print_job/cancel/{id} — Cancels a queued or active ZPL print job. Accepts optional commit_partial (0/1) and partial_quantity for mid-print cancellations; records a Print Job Cancelled notification detailing whether partial inventory was committed or 0 inventory was created.

App\Controllers\Api\ZplTemplate (/api/zpl_template/*)​

  • Lists active ZPL templates, renders live previews (with upright vs printer orientation), and saves versioned template updates.

Admin & Operator Views (v2)​

  • /eifs/full_line_labels_v2 (Eifs::full_line_labels_v2, src/app/Views/eifs/full_line_labels_v2.php, src/public/js/eifs/full_line_labels_v2.js) — Label Printing Center v2 with live Zebra status cards, ZPL preview, active job progress, and cancel button.
  • /admin/printers (Admin::printers, src/app/Views/admin/printers.php, src/public/js/admin/printers.js) — Admin Printer Management UI (add, edit, search, archive/restore).
  • /admin/zpl_templates (Admin::zpl_templates, src/app/Views/admin/zpl_templates.php, src/public/js/admin/zpl_templates.js) — Admin ZPL Template Manager & Live Preview Editor.
  • In-Progress Job Print Status Widget (Beta) (src/app/Views/templates/job_print_status.php, src/public/js/templates/job_print_status.js) — Embedded on Shape Mold, RoboPack, and EIFS in-progress pages. Polls GET /api/print_job/for_job/{job_id}, displays target printer status and label progress, and handles print cancellation with deferred inventory (PrintInventoryService).
    • Go-Live Reminder (Admin-Only Gate): The in-progress Print v2.0 preview/toggle is currently restricted to factory_admin and higher (inGroup('super_admin', 'admin', 'factory_admin')) via $can_use_print_v2 in ShapeMold::job_in_progress, Robopack::in_progress, Eifs::in_progress, and Views/templates/job_print_status.php. When moving Print v2.0 out of beta for all floor operators, remove that group restriction and switch the default from BarTender to ZPL.

Python Print Agent (shelter-print-agent)​

  • Located in the shelter-print-agent repository; deployed on SEI-APP1.
  • Database-Driven Printer Sync: Pulls active printers from GET /api/printer/get_all on startup and every printer_sync_interval_seconds (default 30s) instead of reading a hardcoded "printers" array from settings.json.
  • Parallel Per-Printer Workers: Spawns one dedicated worker thread per printer key so jobs on different printers execute concurrently. Each worker resolves the latest synced printer record before dispatching so IP/port/routing edits apply without restarting the agent.
  • Engine Isolation: Automatically skips print_job rows where print_engine == 'bartender' so v1 and v2 can run side-by-side safely.
    • Current Phased Rollout Status: mass_send() (1), send_manual_shape_mold() (4), sill_seal_labels() (5), and send_line() (6 in ZPL mode) accept print_engine = 'zpl' and route via shelter-print-agent. In-progress station endpoints send() (Robo Pack 0) and send_shape_mold() (BuildBlock 2 / CreteHeat 3) now also accept print_engine = 'zpl' with deferred inventory commit (inventory_payload / inventory_committed), while defaulting to print_engine = 'bartender' until the beta toggle is enabled (currently visible only to factory_admin and higher).
  • Job Routing Precedence (resolve_printer_for_job):
    1. Explicit printer_ip or printer_id on the job
    2. Matching print_type + location_id
    3. Matching print_type with location_id IS NULL
    4. First printer matching print_type

Printing System v1 (Legacy — BarTender Automation Suite)​

Status: Legacy. Maintained alongside v2 until BarTender is fully deprecated.

v1 Architecture Flow​

Web Application (CodeIgniter 4) -> Insert Row into print_job Table
-> BarTender Integration (SEI-APP1 Server) monitors database for new rows
-> BarTender Automation Engine populates .btw label template with data
-> Print Maestro manages Windows print queue -> Zebra Printer -> Printed Label

Currently, BarTender runs on SEI-APP1 (and PLANT 05 in the shipping office, accessible via realVNC).

1. Print Job Database Table (print_job)​

Core fields driving both v1 and v2 job creation:

  • id: Primary key
  • label_name: Template name (matches .btw in v1 or .zpl in v2)
  • copies: Number of identical labels to print
  • print_type: Integer (0–6) determining printer routing:
    • 0 — Robo Pack EIFS
    • 1 — Manual EIFS
    • 2 — Shape Mold BuildBlock
    • 3 — Shape Mold CreteHeat
    • 4 — Manual Shape Mold
    • 5 — Sill Seal
    • 6 — Line Stickers (FullLot)
  • job_id: Foreign key linking to the parent job
  • location_id: Foreign key linking to the location table

Type-Specific Fields:

  • EIFS: lot_number, size_value, size_numerator, size_denominator, sequential numbering (size_count, size_total, job_count, job_total), pcs_per_bag, customer (12 char max), sales_order, bag_type (20 char max).
  • Shape Mold: part_type, part_number, thickness, piece_count, operator initials, shift, web_location (BuildBlock), production_date (BuildBlock).
  • Line Sticker: pages and custom formatting fields.

2. BarTender Integration Files​

Hosted on the local Windows Server (c:\Users\jmess\Downloads\Label Printing Files(1)):

  • Integration Files (.btin):
    • Robo Pack Integration.btin
    • Shape Mold Integration.btin
    • Print Stickers Function.btin
  • Label Templates (.btw):
    • FullLot.btw, divider.btw, and subdirectories EIFS, ShapeMold, SillSeal.
  • BarTender Suite Applications: Administration Console, Integration Builder, and Print Maestro.

3. Shared Web Application Integration (App\Controllers\Api\PrintJob)​

  • send() — Creates EIFS Robo Pack print jobs (print_type = 0). Validates parameters, finds EIFS bag type, calculates sequential numbers, creates EIFS bags, deducts inventory, and inserts into print_job.
  • mass_send() — Batch EIFS print jobs (print_type = 1), incrementing job_count across all sizes.
  • send_line() — Creates custom line sticker print jobs (print_type = 6, no inventory deduction).
  • send_shape_mold() — Creates BuildBlock (2) or CreteHeat (3) labels with job context.
  • send_manual_shape_mold() — Manual shape mold labels (print_type = 4).
  • sill_seal_labels() — Sill Seal box/roll labels (print_type = 5).
  • get_label_info() — Returns printed jobs and pending targets for an EIFS job.

Helper Functions (src/app/Helpers/print_job_helper.php)​

  • get_eifs_target_print_label() — Determines template name (LotStickerEPS, LotStickerEPSFrac, LotStickerGPS, LotStickerGPSFrac, plus DB drainage suffix)
  • format_printed_jobs() — Transforms query results
  • find_starting_number() — Calculates next sequential number for 3-digit padded displays
  • find_print_job_count() — Returns total labels for a job
  • delete_previous_print_job() — Removes old jobs during a resend operation
  • get_eifs_target_print_job() — Generates print job data structure

Label Templates Reference​

  • EIFS: LotStickerEPS, LotStickerEPSFrac, LotStickerGPS, LotStickerGPSFrac (plus DB suffix for drainage)
  • Shape Mold: BuildBlock (Portrait & Landscape / _Rotation), CreteHeat (Portrait & Landscape / _Rotation)
  • Sill Seal:
    • SillSealBox (3.5, 5.5, 7.5) Sill seal box
    • SillSealRoll (3.5, 5.5, 7.5) Sill seal roll

4. Data Flow & Integration Points​

  • Inventory Management: Print job creation deducts stickers (remove_sticker()), deducts bags (remove_bag()), and creates eifs_bag records (make_eifs_bags()). (Print jobs still succeed even if inventory is insufficient.)
  • Sequential Numbering: size_count and job_count are zero-padded to 3 digits; resend operations can intentionally create gaps.
  • Notifications: Resend operations and "Block not found" errors trigger admin notifications.
  • Locations: location_id links print_job and printer to factory locations/buildings.

5. Legacy Front-End Files​

  • Robo Pack: src/public/js/robopack/robo_pack_in_progress.js (/api/print_job/send)
  • Shape Mold: src/public/js/shape_mold/shape_mold_in_progress.js (/api/print_job/send_shape_mold, /api/print_job/send_manual_shape_mold)
  • Full Line EIFS (v1): src/public/js/eifs/full_line_labels.js (/api/print_job/mass_send)

6. v1 Known Limitations & Support Contacts​

  • Database polling latency, manual cleanup of old print_job rows, printer downtime queueing in Print Maestro, .btw template edits requiring Integration Builder, and character limits (12 chars customer, 20 chars bag type).
  • BarTender Tech Support: (425) 274-3610
  • SSE Technologies (Reseller):