# TSHIRTORDER-1651 — API notes for Frontend

## Where the new parts go in the UI

Checked against the frontend source (`develop`, 15/10/2026). None of these parts exist in the frontend yet.

| New part | Where | Frontend files |
|---|---|---|
| **Tryckplaceringar page** | Menu **Catalog** (Katalog): new item **"Tryckplaceringar"** right after "Productions", before "Brands". New route `/app/tryck-placements`, same access group as `/app/products` | Menu: `components/Header/Header.js` (`Catalog` group) and `components/Sidebar/Sidebar.js`. Route: `components/Layout/Layout.js`. New page: `pages/tryck-placements/` |
| **Prints of a Tryck** | Product edit page `/app/products/{id}/detail` when "Tryck product" is ticked. **New tab "Tryck"** (or "Tryckfiler"), **shown only when `isTryck`**, right after the "Connect products" tab. Content per `prints44.jpg`: Tryck 1/4 … 4/4 + "Lägg till tryck" (can be the "Ladda upp tryckfil" modal opened from this tab) | `pages/products/detail/edit.js` (new `NavItem` + `TabPane`, same pattern as tab 7 "Connect products") |
| "Productions" tab of a Tryck | **Unchanged** (the single print from 1628). Do not merge it with the new tab | — |
| "Ecom" and "Kickback & stock" tabs of a Tryck | Hide when `isTryck` (see below; still shown today) | `pages/products/detail/edit.js` |
| **Tryck / placement lines in an order** | Order detail page `/app/orders/{orderNr}/detail`: the items table and the "Totalt" count under it | `pages/order/products.js` |
| Credit / return order | Placement lines show as normal item lines in the modals (backend handles credit/return correctly). Indenting them like the order table is nice to have | `pages/order/credit-modal.js`, `pages/order/return-order-modal.js` |
| Create order `/app/orders/create` | **No change**: pick shirts as before, the backend adds Tryck + placement lines on save | — |

## Tryck product: tabs Ecom and "Kickback & stock" removed

For `productKind = tryck` the API always stores these values on add / update / massedit, whatever is sent:

| Field | Value |
|---|---|
| `showOnEcom` | `false` |
| `manageStock` | `false` |
| `outStock` | `false` |
| `wooSyncStock` | `false` |
| `addOnProduct` | `false` |
| `noKickback` | `true` |
| `procentage` | `0` |
| `fixSum` | `0` |

Hide the **Ecom** tab and the **Kickback & stock** tab in the Tryck form. `isActive` ("Aktiv") is unchanged and still editable.

Order side: Tryck lines never change product stock and never carry kickback (even if a line is picked manually in the product picker and `priceKickback` is sent).

## Tryckplaceringar admin page (`tryckplaceringar.png`)

The shared list of print placements (Bröst vänster, Rygg, ...). Not per channel, no image. Base `/api/v1/tryck-placements`, Bearer token.

A placement is stored as a product (`productKind = "tryck_placement"`), but the frontend only manages it through this API, never through the product form. Its price is added **on top of** the Tryck's own price in orders.

| Action | Request | Notes |
|---|---|---|
| List | `GET /tryck-placements/` | Sorted by `sortOrder`, then `id`. Optional `?isActive=true` (use it for the picker in the print modal) |
| Detail | `GET /tryck-placements/{id}` | |
| Create ("Ny placering") | `POST /tryck-placements/` | `name` (required), `sku` (required, max 255, unique among all products incl. sizes, case-insensitive, trimmed), `price` (>= 0, `0` = show "Ingår"), `sortOrder`, `isActive` (default `true`) |
| Edit (pencil) | `POST /tryck-placements/{id}` | Same fields, any subset (`sku` can be changed, still required + unique). A new price / sku only applies to order lines created after the change |
| Delete (bin) | `DELETE /tryck-placements/{id}` | `400` while a Tryck product still uses it: `{"message": "...", "tryckProducts": [{id, name, sku}]}` |

Item returned:
```json
{ "id": 812, "name": "Rygg", "sku": "RYGG", "price": 40, "taxCode": 25, "sortOrder": 4, "isActive": true }
```
The mockup has no SKU, but the create / edit form needs a required **SKU** field (placements are matched by SKU when imported from another system). Showing it as a column in the list is optional.

Errors `400`: `{"name": "..."}`, `{"sku": "This value should not be blank."}`, `{"sku": "Sku already existed"}`, `{"sku": "Sku is too long (max 255 characters)"}`, `{"price": "Price must be 0 or more"}`. `404` when not found.

Placements never show up in `GET /products` lists or the order product picker. `DELETE /products/{id}` on a placement returns `400` (use `DELETE /tryck-placements/{id}`).

Deactivating a placement (`isActive: false`): it can no longer be picked for a new print, but prints that already use it are kept, can be saved again unchanged, and still add their line to orders.

## Tryck product: prints (`prints44.jpg`, "Ladda upp tryckfil" modal)

Max 4 prints per Tryck, set once on the Tryck product (not per linked T-shirt). Each print = one placement (each placement once per Tryck) + its own print file (required), mockup (optional), note.

### Save: `POST /products/` · `POST /products/{id}` with `productKind: "tryck"`

Field `tryckPrints`:
- key absent = prints unchanged
- `[]` (or `""` in multipart) = remove all prints
- array = replaces all prints, in the order sent

| Field per print | Required | Notes |
|---|---|---|
| `placementProductId` | ✅ | id from `/tryck-placements` |
| `printFile` | ✅ | a new file upload, **or** the existing path string (from `tryckPrints[i].printFile` of the detail) to keep it |
| `mockupFile` | | same as `printFile` |
| `name` | | "Tryck 1" field, empty = `Tryck {n}` |
| `note` | | "Placeringsanteckning" |
| `sortOrder` | | default = position in the array |

Multipart example:
```
tryckPrints[0][placementProductId]=812
tryckPrints[0][printFile]=<file>
tryckPrints[0][note]=8 cm under kragen
tryckPrints[1][placementProductId]=815
tryckPrints[1][printFile]=products/back.png      <- keep the existing file
tryckPrints[1][mockupFile]=<file>
```
`tryckPrints` may also be sent as a JSON string (files then have to be existing paths).

Errors `400`, keyed by print index:
```json
{ "tryckPrints": { "max": "A Tryck product can have at most 4 prints", "1": "Each placement can only be used once", "2": "Missing print file" } }
```
Other messages: `Placement not found`, `Placement is not active` (only for a placement newly added to this Tryck), `Upload file failed: ...`.

### Read: `GET /products/{id}` (Tryck only)
```json
"tryckPrints": [
  { "id": 3, "placementProductId": 812, "placementName": "Rygg", "placementPrice": 40, "placementDeleted": false,
    "name": "Tryck 1", "printFile": "products/back.png", "mockupFile": null, "note": "8 cm under kragen", "sortOrder": 1 }
]
```
Copying a Tryck ("copy to new") copies its prints. Deleting a Tryck deletes its prints.

The existing single print of the Tryck ("Productions" tab: `printFile` + production fields) is unchanged and kept alongside the new prints.

## Order: Tryck and placement lines

Nothing to send. The backend builds them from the shirt lines:

```
Premium T-shirt S        x3  199   (sent by the frontend)
  Tryck "Logo Ica"       x3   50   tryckParentOrderProductId = shirt line,  productKind "tryck"
    Bröst vänster        x3   25   tryckParentOrderProductId = Tryck line,  productKind "tryck_placement"
    Rygg                 x3   40   tryckParentOrderProductId = Tryck line,  productKind "tryck_placement"
    Vänster ärm          x3    0   ("Ingår")
Premium T-shirt M        x4  199   (sent by the frontend)
  Tryck "Logo Ica"       x4   50
    ... same placement lines, x4
```
Each size is its own shirt line, so each one gets its own Tryck line and placement lines. Print cost = (50 + 25 + 40 + 0) × 7, whatever the size split.

- **Quantity of the Tryck line and its placement lines = quantity of the shirt line**, updated on every save. (Before: Tryck line was always 1.)
- One placement line per print, even when the price is 0 ("Ingår").
- Items in the order response come sorted so a Tryck line directly follows its shirt line and placement lines follow their Tryck line; to nest them in the UI use `tryckParentOrderProductId` and `productKind`.
- New fields on every item: `tryckPrintFile`, `tryckMockupFile` (set on placement lines). The note is in `productionComment`, the placement name in `productionPlacements`.
- **Auto-added Tryck / placement lines sent back in `items` (with `orderProductId`) are ignored**: their quantity/price cannot be edited, they are kept or removed together with their shirt line. Removing a shirt line removes its Tryck line and placement lines.
- A Tryck picked by hand in the picker also gets its placement lines (same quantity as that Tryck line). The hand-picked Tryck line stays editable; its placement lines are not.
- A Tryck with price 0 is now auto-added when it has prints. Orders created from ecom never get Tryck / placement lines.
- `totalQuantity` of the order counts only the shirts (not Tryck / placement lines).
- Changing the prints of a Tryck updates existing orders the next time they are saved (lines of removed prints go away, files/notes follow; price stays as it was when the line was added).
