# Python scripts for FPSMS backend

This folder holds Python programs that integrate with the FPSMS backend (e.g. calling the public `/py` API).

## Setup

```bash
cd python
pip install -r requirements.txt
```

## Configuration

Set the backend base URL (optional, default below):

- Environment: `FPSMS_BASE_URL` (default: `http://localhost:8090/api` — includes context path `/api`)
- Or edit the default in each script.

## Scripts

| Script | Description |
|--------|-------------|
| `Bag1.py` | **GUI**: date selector (default today) and job orders as buttons; click shows "Clicked on Job Order code XXXX item xxxx". Run: `python Bag1.py` |
| `fetch_job_orders.py` | CLI: fetches job orders by plan date from `GET /py/job-orders` |
| `label_zpl.py` | ZPL label generator (90° rotated, UTF-8 Chinese, QR). `generate_zpl(batch_no, item_code, chinese_desc)`, `send_zpl(zpl, host, port)`. Run: `python label_zpl.py` to print one test label. |

## Building Bag1 as a standalone .exe

To distribute Bag1 to customer PCs **without giving them source code or requiring Python**:

1. On your development PC (with Python installed), open a terminal in the `python` folder.
2. Install build dependencies:

   ```bash
   pip install -r requirements-build.txt
   ```

3. Run the build script:

   ```bash
   build_exe.bat
   ```

   Or run PyInstaller directly:

   ```bash
   pyinstaller --onefile --windowed --name Bag1 Bag1.py
   ```

4. The executable is created at `dist\Bag1.exe`. Copy **only** `Bag1.exe` to the customer computer and run it; no Python or source code is needed. The app will save its settings (`bag1_settings.json`) in the same folder as the exe.

## Adding new scripts

Add new `.py` files here and list them in this README. Use `requirements.txt` for any new dependencies.
