Skip to content

04 — Current Printing Flow (what we are replacing)

Historical (Excel era). This page describes the printing path before 10.0 (Excel/QXlsx/cscript), kept as design background; function names, line numbers and QR sizes below are the old baseline and no longer exist. The shipped code is src/printing/ and src/imprimir/ (buildTicket / printTicket); see ../printing.md and ../imprimir.md for the current flow, including the QR sizing (30-40 mm) and the leyenda rule (row 0 ENVIADA, or PENDIENTE just issued by the direct client).

This is the baseline: how src/imprimir/ prints today, the exact layout the new ESC/POS code must reproduce, and every place that calls the printing API (the integration surface a rewrite must keep working). Source: ../../../src/imprimir/imprimir.cpp and ../../../src/imprimir/imprimir.h.

The pipeline today

getTicketInfo()          → SELECT * FROM ingresos WHERE n_recibo = ?   (optionally AND seq, pagado)
createTicketExcel(...)   → QXlsx::Document writes ~/.laideal_ticket.xlsx (header, table, totals, QR, policy)
printTicket()            → writes ~/.laideal_print.vbs, runs:  cscript //nologo //B <vbs>
                              the VBS drives Excel COM: CreateObject("Excel.Application")
                              → Workbooks.Open(xlsx) → PrintOut → Close → Quit
                              → Excel prints to the DEFAULT Windows printer (the TM-T20III queue)

What each piece costs us

  • Microsoft Excel must be installed and licensed on the shop PC — a hard runtime dependency for printing a receipt.
  • COM automation of Excel is slow (the process launches per print) and brittle (a left-over EXCEL.EXE, a dialog, a macro-security prompt can hang it; process.waitForFinished(60000) is a 60 s ceiling).
  • A .vbs script is generated to disk and executed via cscript on every print — extra moving parts and an antivirus/Smart-screen surface.
  • QXlsx (vendored, with a local setPageMargins patch) is pulled in only for this.
  • No status feedback — the app cannot tell whether the ticket actually printed, or whether paper/cover was the problem.
  • Layout is fought through spreadsheet cells — column widths in Excel units, merged cells, manual row heights — tuned empirically against the physical printer.

All of this disappears with direct ESC/POS.

Exact layout to reproduce

createTicketExcel(bool copyForClient, bool addPayedInfo) builds three columns (Uds. | Prendas | Importe) and these blocks, top to bottom. The new renderer must produce the same content and ordering within the printer's column width.

  1. Header (centered):
  2. Business name — large (Excel 22 pt) → ESC/POS double-size, centered.
  3. verifactuName() (company legal name), NIF: <verifactuNif()>, businessAddress(), businessCity(), Tlf: <businessPhone()> — bold; phone row closed by a double rule.
  4. Document type: Recibo (claim ticket) or FACTURA SIMPLIFICADA.
  5. Nº: <displayInvoiceId()> — bold, right-aligned. displayInvoiceId() = first non-empty verifactu_invoice_id across the rows, else the bare n_recibo.
  6. Cliente: <name> (from row 0).
  7. Recepción: <fecha_recepcion> (-→/).
  8. Complete-invoice extras (only when isCompleteInvoice): Dirección: (looked up, or prompted; split across two lines if ≥ 42 chars) and DNI: (prompted).
  9. Double-rule separator, then table header Uds. | Prendas | Importe.
  10. Garment rows — for each ingresos row (recibo: all; factura: only paid rows):
  11. cantidad | garment name (+ - <size> when size ≠ 0) | importe (2 decimals).
  12. Accumulates ticketTotalF.
  13. Totals:
  14. Recibo: TOTAL (IVA incl.): <total>.
  15. Factura: Base Imponible: <base>, IVA (<rate>%): <iva>, TOTAL: <total> — base = total / (1 + rate/100), iva = total - base (matches Facturas::taxBaseFromGross).
  16. IMPORTE PAGADO line when addPayedInfo, else a blank spacer.
  17. Copy marker (recibo only): (Copia para el cliente) or (Copia para el establecimiento).
  18. Verifactu QR (facturas only, never recibos): the resolveQrCode() QPixmap (≈140×140 then; now redrawn at 30-40 mm), followed — only when row 0 verifactu_estado == ENVIADA then — by the small legend Factura verificable en la sede electrónica de la AEAT.
  19. Legal policy (client copy only): the RD 1453/1987 clauses + RGPD first-layer notice (small font, fixed wording in imprimir.cpp).
  20. Timestamp: dd/MM/yyyy - hh:mm:ss, top-ruled.

QR / Verifactu rules to preserve (resolveQrCode())

  • Only on facturas, never recibos (a recibo is a claim ticket, not a tax document).
  • Emit a QR only when at least one row has a real verifactu_csv and no row is ANULADA / RECTIFICADA / ERROR.
  • Uses displayInvoiceId() for the InvoiceID and the first paid row's fecha_pago for the date (must equal what was submitted to AEAT).
  • Fetches the QR asynchronously with a 5 s local-event-loop wait; prints without QR on timeout. The new code must keep this async-fetch-then-render behaviour (the QR pixmap is the byte-exact AEAT artifact — see the rastering note in 03_escpos_command_reference.md).

Integration surface (callers + settings)

A rewrite should preserve the Imprimir public interface (or provide a drop-in) so these call sites keep working. Today they all follow the pattern getTicketInfo() → createTicketExcel(copyForClient, addPayedInfo) → if (enablePrinting()) printTicket().

Caller Location Flow
Save ticket / invoice MainWindow::printRecibo / printFra (mainwindow.cpp) recibo: client copy then establishment copy; factura.
Print menu actions mainwindow.cpp (Imprimir → Recibo / Factura / Factura completa) set isRecibo/isCompleteInvoice then show the dialog.
Pay (Cobrar) PayDialog::printPartialFactura (pay_dialog.cpp) single customer factura after partial payment (a recibo when AEAT did not reply).
Reprint from Recogida RecogPrendas::printFactura (recog_prendas.cpp) the clicked row's payment event.
Dialog print button Imprimir::onPrintClicked (imprimir.cpp) multi-seq factura chooser, recibo shop copy tick-box.

Public members used by callers: ctor Imprimir(db, parent); getTicketInfo(); createTicketExcel(bool, bool); printTicket(); flags isRecibo, isCompleteInvoice, invoiceSeq; verifactuIntegration; qrCode.

Settings consumed (all already exist)

Setting Getter Use
print.enable enablePrinting() Guards the actual print (testing mode still built the file).
business.name businessName() Header title.
business.address / business.city / business.phone businessAddress() / businessCity() / businessPhone() Header lines; phone also RGPD contact.
verifactu.company_name / verifactu.nif verifactuName() / verifactuNif() Legal name + NIF in header.
(fixed) AppSettings::ivaRate() = 21, no longer configurable Base/IVA split on facturas.
(internal) ticketExcelPath() / ticketPrintScriptPath() ~/.laideal_ticket.xlsx, ~/.laideal_print.vbs — both retired by the rewrite.

New settings the rewrite will add: printer queue name (and/or "use default printer"), paper width (58/80 mm). See 05_implementation_plan.md.

Things to delete when the rewrite lands

  • createTicketExcel() / printTicket() bodies (replace with ESC/POS build + RAW send).
  • ~/.laideal_ticket.xlsx and ~/.laideal_print.vbs generation + the cscript QProcess.
  • The QXlsx dependency from src/imprimir/CMakeLists.txt (and, if no other module uses it, the vendored QXlsx/ and its CMake wiring — verify first).
  • The AppSettings::ticketExcelPath() / ticketPrintScriptPath() helpers.

References