# Receipt printing with QZ Tray

Café ERP generates ESC/POS bytes from the saved bill or test slip. The cashier's browser sends the bytes to QZ Tray on the same computer. QZ can use an installed printer queue or send raw commands to a printer on the cashier's network.

## Deploy

1. Deploy the application and public assets together. Run `composer install --no-dev --optimize-autoloader` from the project directory to install the locked ESC/POS library. Printer settings require no database migration.
2. Create a directory outside the entire web document root and give the PHP service account exclusive write access. Set the private production `.env` to the actual path, for example `QZ_SIGNING_DIRECTORY = '/home/account/private/cafe-qz'`. Restrict directory access to the PHP account and administrators. Use a separate directory for each Café ERP deployment and back it up securely.
3. Serve the production ERP over HTTPS. PHP needs OpenSSL. The private key stays in the configured server directory. The browser receives the public certificate and a signature for each authorized receipt or test slip.

## Configure a cashier browser

1. Install QZ Tray and start it on the cashier computer. For an installed printer queue, install the printer driver and use the exact queue name shown by the operating system. For a network printer, confirm the cashier computer can reach its IP or hostname and raw TCP port (usually 9100).
2. Sign in as a manager on that computer and open **Settings → Receipt printer**. Select the print method and 58 mm or 80 mm paper. Turn on cutting only for a printer with a cutter.
3. For signed printing, use QZ Tray 2.1 or later and upload `digital-certificate.txt` and the matching unencrypted `private-key.pem`. Save the settings and select **Test QZ printer**. Confirm the slip, cutter setting, and QR code on paper.
4. Check a POS receipt and a reprint from **Sales** on that same browser. Choose **Browser print dialog** in Settings to use the HTML receipt and your browser's print dialog.

The printer profile follows the browser profile and website origin. Configure each cashier browser separately. Clearing site storage assigns a new profile. A certificate must be trusted by the QZ installation for remembered approval. QZ's demo certificates are intended for development and are trusted only where installed. See [QZ Tray signing](https://qz.io/docs/signing) and [certificate setup](https://qz.io/docs/generate-certificate).

## Connector source

The vendored QZ Tray 2.3.0 JavaScript connector comes from BOOKSAFE and includes its patch to include the signature algorithm on pre-signed requests. Keep this behavior when updating the connector. The upstream source and license are available in the [QZ Tray repository](https://github.com/qzind/tray).
