# Flowchart — `units`

> Produced by the Reversa **Archaeologist** (phase: interpretation) · doc_level: `complete`
> Generated on 2026-09-18

**Confidence scale:** 🟢 CONFIRMED · 🟡 INFERRED · 🔴 GAP

## `UnitController` — reference-data editor (Encore\Admin scaffolding) 🟢

```mermaid
flowchart TD
    A["GET settings/units (index)"] --> B["Admin content: two columns"]
    B --> C["left: grid()"]
    B --> D["right: 'new unit' widget form<br/>name (required), description<br/>POST settings/units"]
    C --> E["columns: id, name, description"]
    E --> F["disable create/export/selector/filter/pagination"]
    F --> G["row actions:"]
    G --> H["disableDelete() on ALL rows"]
    G --> I{"row key == 1?"}
    I -->|yes| J["disableEdit()<br/>🟢 confirmed default unit"]
    I -->|no| K["edit allowed"]
```

## Unit consumption across the app 🟢

```mermaid
flowchart TD
    U["units table"] --> V["Unit::all()->pluck('name','name')<br/>-> products.unit base-unit dropdown (string)"]
    U --> W["Unit::all(['id','name'])<br/>-> conversion-units table (product_units.unit_id)"]
    U --> X["Unit::find(pivot.unit_id)->name<br/>-> pos-print / orders-detail / customer-orders<br/>blade unit labels"]
    W --> Y["product_units.unit_id FK -> units.id"]
    X --> Z["order_product.unit_id FK -> units.id (onDelete set null)"]
```

**Notes:**
- `store`/`update`/`destroy` are provided by the Encore\Admin `ModelForm` trait and driven by `form()` (fields `name` required, `description`); only `index`/`edit`/`grid`/`form` are overridden. 🟢
- Row actions: `disableDelete()` on every row; `disableEdit()` when the row key is `1` (`app/Http/Controllers/UnitController.php:66-71`) — unit id 1 is the confirmed default/fallback unit (this id-1 lock is active here, whereas in `categories` the equivalent block is commented out — see the `categories` module gap). 🟢
- The `Unit` model (`app/Models/Unit.php`) is completely empty (no relations, casts, or fillable); the inverse `ProductUnit::unit()` = `belongsTo(Unit)` lives on `ProductUnit`. 🟢
- 🟡 The `units` table has a nullable `category_id` column that no code reads or writes — an apparently dead/unused column (units are not scoped by category anywhere). Confirm before relying on it.
- Units are consumed in three places: the product base-unit dropdown (`products.unit`, a **string** keyed by name), the conversion-units table (`product_units.unit_id`), and order/print/customer-order-history unit labels (`Unit::find(pivot.unit_id)->name` in `pos-print.blade.php:57`, `orders-detail.blade.php:72`, `customer-orders.blade.php:66`). 🟢
