# CNPERP Local Server Installation

On-premise deployment for a single office: one Windows PC runs the ERP for everyone on the LAN. Licenses are issued and renewed through the CNP cloud hub.

## Customer flow

1. **License** — Purchase or receive a license key from the CNP cloud site (super-admin issues keys in Settings → Licensing).
2. **Download** — Open [Local Server Install](/install/local) on the cloud site and download `Install-CNPERP-Local.ps1` (or use a full release ZIP from CNP Solutions).
3. **Install** — Run PowerShell **as Administrator** from the CNPERP application folder:
   ```powershell
   Set-ExecutionPolicy -Scope Process Bypass
   .\deploy\local-server\Install-CNPERP-Local.ps1 -CloudUrl "https://your-cloud-host"
   ```
4. **Start server** — Desktop shortcut **CNPERP Server** (keep the window open; default port **8010**).
5. **Setup** — **CNPERP Setup Wizard** shortcut → validate license → company registration at `/setup`.
6. **Cloud link** — Add `license_key` to `deploy\license-node.json`, then:
   ```powershell
   .\deploy\local-server\Connect-Cloud.ps1
   ```
   Optional: `deploy\setup_license_heartbeat_task.ps1` for scheduled heartbeats.

## Prerequisites

| Component | Requirement |
|-----------|-------------|
| OS | Windows 10/11 or Server 2019+ |
| Python | 3.10+ on PATH |
| PostgreSQL | 14+ (installer creates `cnperp_local` / `cnperp_user`) |
| RAM | 4 GB+ recommended |

## Scripts

| File | Purpose |
|------|---------|
| `Install-CNPERP-Local.ps1` | Verify deps, venv, `.env`, DB bootstrap, firewall, shortcuts |
| `Start-CNPERP-Server.ps1` | Run uvicorn on `0.0.0.0:8010` for LAN access |
| `Connect-Cloud.ps1` | Register node + heartbeat after license is configured |
| `local-install.env.template` | Reference for manual `.env` |

Database initialization is handled by `scripts/bootstrap_local_install.py`.

## API (cloud site)

- `GET /install/local` — Installation guide page
- `GET /api/v1/installer/local` — JSON metadata and download URLs
- `GET /api/v1/installer/download/{filename}` — Installer script files

## Building a release ZIP

```powershell
.\deploy\local-server\Create-LocalInstallPackage.ps1
```

Produces `dist/cnperp-local-install-<version>.zip` with app code + installer scripts for offline copy to the customer server.

## Parameters (installer)

- `-InstallPath` — Path to repo root (folder containing `app\main.py`)
- `-CloudUrl` — License validation hub (default in script)
- `-Port` — HTTP port (default `8010`)
- `-DbPassword` — PostgreSQL password (auto-generated if omitted)
- `-SkipPythonDeps` / `-SkipDbBootstrap` — For upgrades or re-runs

## LAN users

After the server is running, other PCs open:

`http://<server-ip>:8010`

They use the same login created during setup; no separate install on client machines.
