# How to use Siraya Printer Service

The agent runs on the **same PC as the POS browser**, listens on **http://127.0.0.1:5000**, and shows a setup UI to pick a printer and test print.

Configure Siraya POS build:

```env
NEXT_PUBLIC_PRINT_SERVICE_URL=http://127.0.0.1:5000
```

---

## Windows (register PC)

### Option A — USB folder (recommended for technicians)

**On a build machine (Windows):**

```powershell
cd thermal-printer-service
npm install
npm run build:release
```

**Copy to the register PC:** entire folder `dist\release\`

**On the register PC:**

1. Double-click **`Install.cmd`**
2. Approve **UAC** once
3. Browser opens **http://127.0.0.1:5000**
4. Select printer queue → **Test print**

Service name: `SirayaPrinterService` (starts on boot)  
Install path: `C:\Program Files\Siraya\Printer`  
Log: `%TEMP%\SirayaPrinter-Install.log`

### Option B — Installer EXE

1. Download **`SirayaPrinterSetup.exe`** from GitHub Releases (or `npm run build:setup` after `build:release`)
2. Double-click → UAC → browser opens

Silent: `SirayaPrinterSetup.exe /SILENT /SUPPRESSMSGBOXES`

### Verify (Windows)

```powershell
.\scripts\verify-install.ps1
```

---

## Ubuntu / Debian

### Option A — `.deb` package (recommended)

**Build the package (on Ubuntu 22.04+ amd64):**

```bash
cd thermal-printer-service
npm install
npm run build:deb
# Output: dist/deb/siraya-printer_2.0.0_amd64.deb
```

**Install on the register PC:**

```bash
sudo dpkg -i dist/deb/siraya-printer_2.0.0_amd64.deb
sudo apt-get install -f    # install missing dependencies if needed
```

Open **http://127.0.0.1:5000** in a browser (Firefox/Chromium).

**Service commands:**

```bash
sudo systemctl status siraya-printer
sudo journalctl -u siraya-printer -f
sudo systemctl restart siraya-printer
```

Data: `/var/lib/siraya/printer`  
App: `/opt/siraya/printer`

### Option B — USB folder (same layout as Windows)

**Build on Ubuntu:**

```bash
npm run build:release:linux
```

**Copy** `dist/release/` to the register PC, then:

```bash
cd /path/to/release
sudo ./install.sh
```

### Uninstall (Linux)

```bash
sudo apt-get remove siraya-printer
# purge data:
sudo apt-get purge siraya-printer
```

---

## Receipt designer

Open **http://127.0.0.1:5000/designer** on the register PC to customize receipt layout:

- Business title, phone, website, tagline
- Footer lines
- Section toggles (items, totals, loyalty, payment)
- Paper width (32 or 42 chars)

Click **Save template**, then **Test print**. Siraya POS uses this layout when orders are placed.

Template file: `{SIRAYA_DATA_DIR}/receipt-template.json`

---

## POS integration

Siraya POS prints a customer receipt when an order is created. The print agent must be running on the same machine as the browser.

---

## Development (any OS)

```bash
cp .env.example .env
npm install
npm start
```

Open http://127.0.0.1:5000

---

## Troubleshooting

| Issue | Check |
|-------|--------|
| Browser cannot connect | `curl http://127.0.0.1:5000/health` |
| Windows service down | `services.msc` → SirayaPrinterService |
| Linux service down | `systemctl status siraya-printer` |
| No printers listed | Windows: printer in Devices; Linux: CUPS `lpstat -p` |
| POS still not printing | POS env `NEXT_PUBLIC_PRINT_SERVICE_URL` must be `http://127.0.0.1:5000` |
