# V41 — Sellable release (retail + F&B, manual billing, new UI)

Verified: 143 end-to-end HTTP tests (fresh install from `install_full.sql` **and** upgrade V40 → V41 with existing data),
plus browser runs in Chromium (desktop + mobile, online + offline sale with variants, super-admin approval).

## Selling
- **Variants at the POS** with per-branch stock per variant (`StockService` handles every stock mutation).
  A product with active variants must be sold/adjusted/counted/transferred per variant.
- **Non-stock items** (`track_stock=0`) for F&B menu made to order.
- **Categories** (CRUD, sort order) and a tap-grid POS; exact barcode/SKU scan (incl. variant barcodes) adds straight to the cart.
- **Tax & service charge** (per business, % with Rupiah rounding), shown on screen and receipt.
- **Receipt settings**: store name/address/phone, header/footer, 58/80 mm width; word-wrapped monospace receipt; test print.
- **Payment dialog**: method buttons, quick cash amounts (exact, rounded 10k/20k/50k/100k), change, reference no.
- **History, reprint, returns/refunds** (partial or full). Refund = returned value × (total/subtotal) so discount/tax/service are refunded proportionally; stock restored; `pos.refund` permission (Admin by default).
- **Cash sessions** now link sales/refunds via `cash_session_id` (exact expected cash; no timestamp overlap).

## Inventory & purchasing
- **Suppliers & purchases (stock in)**: posts immediately, increases stock, optional cost update, merged duplicate lines.
- **Import products** from CSV or Excel (.xlsx via SheetJS loaded on demand), upsert by SKU/barcode, auto-create categories, optional initial stock; per-row error report; template download.
- Stock opname and transfers are variant-aware; opname lines can be removed while in draft.

## Reports
- `api/reports.php`: summary (gross, returns, net, discount, tax, service, COGS, gross profit, avg ticket), daily, products (with variants), cashiers, payment methods, paginated transactions.
- **CSV export** (`;` separated, UTF-8 BOM — opens directly in Excel). Permission `report.export`.
- Dashboard: today vs yesterday, 14-day chart, top 7-day products, per-branch, low stock (incl. variants). Available on every plan (was MULTI_BRANCH-only).

## Subscription (manual payment)
- Tenant **Langganan** page: plan, expiry, devices/branches used, invoices, "Perpanjang" (creates invoice at plan price), **payment confirmation** form.
- Super Admin: pending confirmations (approve → `settlePayment` extends license by plan duration; reject with note visible to tenant), invoices (mark paid / cancel), create invoice, **plan editor** (price, duration, limits, features, apply limits to existing licenses), billing instructions & support contact.
- **Grace period** (`license_grace_days`, default 3) with banners: ≤14 days warning, in-grace alert, expired → admins redirected to the subscription page; billing endpoints work while expired.

## UI
- New design system (`public/assets/app.css`): top navigation by permission, KPI cards, tables, badges, tabs, modal dialogs, toasts (no more `alert()`/`prompt()`), mobile layout with sticky pay bar.
- New pages: `dashboard`, `products`, `purchases`, `reports`, `users`, `settings`, `subscription`; rebuilt `pos`, `branches`, `super-admin`, `login`. Old URLs redirect.
- PWA manifest icon; service worker caches the new shell only.

## Fixes found during V41 testing
- Payment confirmation returned the audit-log id instead of the confirmation id (`lastInsertId()` after audit insert).
- Settlement now refuses cancelled invoices.
- Migrations start with `SET NAMES utf8mb4` (non-ASCII seed text was garbled when imported with a latin1 client).
- `[hidden]` elements could still render when a component set `display:flex`.

## Database
- `database/v41_migration.sql` (upgrade) and **`database/install_full.sql`** (new installs, single file, schema verified identical to install + all migrations).
- New tables: `business_settings`, `sales_returns`, `sales_return_items`, `suppliers`, `purchases`, `purchase_items`, `saas_payment_confirmations`, `app_settings`.

## Tools
- `tools/v41-e2e-test.php` (143 checks), `tools/v41-demo-seed.php` (demo tenant for sales presentations).
