# Anhang 2 - Debugging

Verschiedene Auszüge vom Debugging

# Use Case 6 — KI-CRM: Aufgetretene Probleme und LösungsansätzeNeue Seite

**Projekt:** KI-CRM für Exista AG  
**Stack:** Vue.js 3, Node.js/Express, MariaDB, Redis, Nginx, Docker Compose  
**Datum:** 16.04.2026

---

## 1. Doppelter "Neue Firma" Button im Wochenbericht

### Problem

Im Wochenbericht-Modal erschienen beim Firma-Dropdown zwei separate Buttons zum Erstellen einer neuen Firma:

- `+ Neue Firma erstellen` (alter Mini-Button aus `FirmaAutocomplete.vue`)
- `+ Neue Firma anlegen` (neues vollständiges KI-Modal)

### Ursache

Die `FirmaAutocomplete.vue` Komponente renderte intern einen eigenen "Neue Firma erstellen" Button (CSS-Klasse `.ac-create`), der im Wochenbericht-Kontext nicht erwünscht war.

### Lösung

Vue 3 `:deep()` CSS-Selektor in `Wochenbericht.vue` — der alte Button wird im Kontext des Wochenberichts ausgeblendet, ohne die Komponente selbst zu verändern:

<div aria-label="vue-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-vue" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">vue</div><div class="overflow-x-auto"></div></div>```vue
<style scoped>
/* FirmaAutocomplete: "Neue Firma erstellen" Mini-Button ausblenden */
:deep(.ac-create) {
  display: none;
}
</style>
```

**Erkenntnis:** `:deep()` ist ideal um Kind-Komponenten kontextspezifisch zu stylen ohne deren Code zu ändern.

---

## 2. NeueFirmaModal — Komponente innerhalb v-if nicht gerendert

### Problem

Die `NeueFirmaModal` Komponente war korrekt importiert und referenziert, aber der `+ Neue Firma anlegen` Link öffnete kein Modal. Im Browser-DOM war die Komponente nicht vorhanden (childElementCount: 1 statt 3).

### Ursache

Die `<NeueFirmaModal>` Komponente war innerhalb eines `v-if`-Blocks platziert. Wenn der übergeordnete Block `false` war (z.B. kein Formular offen), wurde die Komponente gar nicht gerendert und konnte auch nicht geöffnet werden.

### Lösung

Die Komponente auf **Template-Root-Ebene** verschieben — direkt als Kind von `<template>`, ausserhalb aller `v-if`-Blöcke:

<div aria-label="vue-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-vue-1" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">vue</div><div class="overflow-x-auto"></div></div>```vue
<template>
  <div>
    <!-- Hauptinhalt mit v-if Blöcken -->
  </div>

  <!-- Modal AUSSERHALB aller v-if Blöcke -->
  <NeueFirmaModal v-model:visible="showNeueFirmaModal" @firma-created="onNeueFirmaCreated" />
</template>
```

**Erkenntnis:** Vue 3 unterstützt mehrere Root-Elemente im Template (Fragment). Modals immer auf Root-Ebene platzieren, nie innerhalb konditioneller Blöcke.

---

## 3. z-index Problem — Modal hinter anderem Modal versteckt

### Problem

Das `NeueFirmaModal` öffnete sich (war im DOM vorhanden), war aber nicht sichtbar weil es hinter dem übergeordneten Kontakt-Modal versteckt war.

### Ursache

Das `NeueFirmaModal` hatte `z-index: 1100`, das Kontakt-Modal hatte ebenfalls einen hohen z-index. Je nach Browser-Rendering-Reihenfolge gewann das falsche Modal.

### Lösung

Z-index des `NeueFirmaModal` auf `2000` erhöhen:

<div aria-label="vue-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-vue-2" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">vue</div><div class="overflow-x-auto"></div></div>```vue
<div v-if="visible" class="popup-overlay" style="z-index:2000">
```

**Erkenntnis:** Bei verschachtelten Modals immer klare z-index Hierarchie definieren. Empfehlung: Basis-Modal 1000, Sekundär-Modal 2000, Notifications 3000.

---

## 4. Vite Build Cache — Änderungen werden nicht deployed

### Problem

Trotz `docker compose build --no-cache` wurden Änderungen in bestimmten Vue-Komponenten (insbesondere `Kontakte.vue`) nicht im gebauten Container übernommen. Der Hash der generierten JS-Datei blieb identisch.

### Ursache

Vite speichert einen internen Dependency-Cache in `node_modules/.vite/`. Dieser wird von `--no-cache` beim Docker-Build nicht zwingend geleert, da er im Volume liegt.

### Lösung

Vite-Cache manuell löschen vor dem Build:

<div aria-label="bash-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-bash" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">bash</div><div class="overflow-x-auto"></div></div>```bash
rm -rf frontend/node_modules/.vite
docker builder prune -af  # Docker Build-Cache komplett leeren
docker compose --env-file ../.env build --no-cache frontend
docker compose --env-file ../.env up -d --force-recreate frontend
docker restart crm_nginx
```

**Verifikation:**

<div aria-label="bash-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-bash-1" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">bash</div><div class="overflow-x-auto"></div></div>```bash
# Prüfen ob neuer Code im Container ist
docker exec crm_frontend grep -rl "NeueFirmaModal" /usr/share/nginx/html/assets/
```

**Erkenntnis:** Bei hartnäckigen Build-Problemen immer `node_modules/.vite` und Docker Builder Cache löschen. Der Datei-Hash im Output-Bundle ist der zuverlässigste Indikator ob ein Rebuild stattgefunden hat.

---

## 5. Vue ref() — Fehlender .value Zugriff

### Problem

Serverseitige Filter (`filter_kundenprodukte`, `filter_firma`, etc.) wurden zwar im Frontend-Code referenziert, aber nie in der API-Request-URL übermittelt. Die Backend-Logs zeigten keinerlei Filter-Parameter.

### Ursache

`colFilters` war als `ref({})` definiert. In der `load()` Funktion wurde direkt `colFilters.firma` statt `colFilters.value.firma` verwendet. In Vue 3 muss bei `ref()` ausserhalb von Templates immer `.value` verwendet werden.

<div aria-label="javascript-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-javascript" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">javascript</div><div class="overflow-x-auto"></div></div>```javascript
// FALSCH — gibt immer undefined zurück
if (colFilters.firma) params.filter_firma = colFilters.firma

// KORREKT
if (colFilters.value.firma) params.filter_firma = colFilters.value.firma
```

### Lösung

<div aria-label="javascript-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-javascript-1" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">javascript</div><div class="overflow-x-auto"></div></div>```javascript
async function load() {
  const params = {
    page: page.value, limit: 50,
    ...filter.value,
    sortBy: sortKey.value, sortDir: sortDir.value,
  }
  if (colFilters.value.firma)          params.filter_firma          = colFilters.value.firma
  if (colFilters.value.kundenprodukte) params.filter_kundenprodukte = colFilters.value.kundenprodukte
  if (colFilters.value.notizen)        params.filter_notizen        = colFilters.value.notizen
  if (colFilters.value.marktsegment)   params.filter_marktsegment   = colFilters.value.marktsegment
  const { data } = await api.get('/firmen', { params })
}
```

**Erkenntnis:** In Vue 3 Composition API gilt: `ref()` immer mit `.value` ausserhalb von `<template>`. `reactive()` braucht kein `.value`. Bei schwer auffindbaren Bugs immer `console.log` zur Verifikation einsetzen.

---

## 6. Serverseitige Filterung vs. Clientseitige Filterung

### Problem

Die Firmen-Tabelle lädt 50 Einträge pro Seite (Pagination). Clientseitige Filter (z.B. Kundenprodukte = "ind") filterten nur die aktuell geladenen 50 Firmen — nicht alle 2600. Das Ergebnis war unvollständig und irreführend.

### Ursache

Filter wie `kundenprodukte`, `notizen`, `marktsegment` und `firma` wurden nur in der clientseitigen `filterRows()` Funktion angewendet, nicht als Query-Parameter ans Backend übergeben.

### Lösung

**Backend** (`firmen.js`) — Filter-Parameter entgegennehmen und als SQL WHERE-Bedingungen anwenden:

<div aria-label="javascript-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-javascript-2" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">javascript</div><div class="overflow-x-auto"></div></div>```javascript
const { filter_firma, filter_marktsegment, filter_kundenprodukte, filter_notizen } = req.query

if (filter_firma)          where.firma          = { [Op.like]: `%${filter_firma}%` }
if (filter_marktsegment)   where.marktsegment   = { [Op.like]: `%${filter_marktsegment}%` }
if (filter_kundenprodukte) where.kundenprodukte = { [Op.like]: `%${filter_kundenprodukte}%` }
if (filter_notizen)        where.notizen        = { [Op.like]: `%${filter_notizen}%` }
```

**Frontend** (`Firmen.vue`) — Filter-Inputs mit `@input="load"` triggern und Parameter korrekt übergeben:

<div aria-label="vue-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-vue-3" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">vue</div><div class="overflow-x-auto"></div></div>```vue
<input v-model="colFilters.value.kundenprodukte" @input="load" placeholder="Filter…" />
```

**Debugging-Methode:**

<div aria-label="bash-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-bash-2" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">bash</div><div class="overflow-x-auto"></div></div>```bash
# DB direkt testen
docker exec crm_mariadb mariadb -u root -pRoot2026! crm_semitron \
  -e "SELECT COUNT(*) FROM firmen WHERE kundenprodukte LIKE '%ind%';"
# → 217 Einträge — Backend-Filter war das Problem
```

**Erkenntnis:** Bei paginierten Tabellen müssen Filter immer serverseitig implementiert werden. Clientseitige Filter nur für berechnete Felder verwenden, die nicht in der DB gespeichert sind.

---

## 7. Sortierung berechneter Felder (potentiale\_total)

### Problem

Die Spalte "Pot. Total CHF" war nicht sortierbar, obwohl der Sort-Button vorhanden war. Klicks auf den Header hatten keinen Effekt.

### Ursache

`potentiale_total` ist ein berechnetes Feld (Subquery), das nicht direkt in der `firmen` Tabelle gespeichert ist. Die Backend-Sortier-Whitelist kannte diesen Feldnamen nicht.

### Lösung

Im Backend-Query das Feld als Subquery-Alias definieren und mit `sequelize.literal()` sortierbar machen:

<div aria-label="javascript-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-javascript-3" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">javascript</div><div class="overflow-x-auto"></div></div>```javascript
// In der Sequelize-Query als Attribut
[sequelize.literal('(SELECT COALESCE(SUM(wert), 0) FROM firma_potential_werte WHERE firma_id = `Firma`.`id`)'), 'potentiale_total']

// Sortierung
if (sortBy === 'potentiale_total') {
  order = [[sequelize.literal('potentiale_total'), sortDir]]
}
```

**Erkenntnis:** Berechnete/aggregierte Felder brauchen spezielle Behandlung bei ORM-Sortierung. `sequelize.literal()` ermöglicht rohe SQL-Ausdrücke in Sequelize-Queries.

---

## 8. Synology vs. Dev — Falsches System getestet

### Problem

Fixes wurden deployed und getestet, aber das Problem blieb bestehen. Mehrere Deploy-Zyklen ohne Verbesserung.

### Ursache

Tests wurden auf der Synology-Produktionsinstanz (`capcalc.kistudent.synology.me`) durchgeführt, während Deployments auf den Dev-Server (`192.168.0.16:8090`) gingen.

### Erkenntnis

Immer zuerst die URL in der Browser-Adressleiste prüfen:

- Dev: `192.168.0.16:8090`
- Produktion: `capcalc.kistudent.synology.me`

Synology-Deployment erfordert separaten Prozess via `tar + scp`:

<div aria-label="bash-Code" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk-bash-3" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"></path></svg></div><div class="absolute inset-0 flex items-center justify-center"><div class="transition-all opacity-0 scale-50"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M15.188 5.11a.5.5 0 0 1 .752.626l-.056.084-7.5 9a.5.5 0 0 1-.738.033l-3.5-3.5-.064-.078a.501.501 0 0 1 .693-.693l.078.064 3.113 3.113 7.15-8.58z"></path></svg></div></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0">bash</div><div class="overflow-x-auto"></div></div>```bash
tar czf /tmp/ki-crm-frontend.tar.gz --exclude='node_modules' --exclude='dist' -C frontend .
scp -P 1111 /tmp/ki-crm-frontend.tar.gz abiltec@192.168.0.82:/tmp/
ssh abiltec@192.168.0.82 -p 1111
cd /volume1/docker/ki-crm/frontend
tar xzf /tmp/ki-crm-frontend.tar.gz
sudo /usr/local/bin/docker compose --env-file /volume1/docker/ki-crm/.env build --no-cache frontend
sudo /usr/local/bin/docker compose --env-file /volume1/docker/ki-crm/.env up -d --force-recreate frontend
```

---

## Zusammenfassung — Lessons Learned

<div class="overflow-x-auto w-full px-2 mb-6" id="bkmrk-%23-problem-l%C3%B6sung-kat"><table class="min-w-full border-collapse text-sm leading-[1.7] whitespace-normal"><thead class="text-left"><tr><th class="text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold" scope="col">\#</th><th class="text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold" scope="col">Problem</th><th class="text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold" scope="col">Lösung</th><th class="text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold" scope="col">Kategorie</th></tr></thead><tbody><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">1</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Doppelter Button</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">`:deep()` CSS Selektor</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Vue Scoped Styles</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">2</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Modal nicht gerendert</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Ausserhalb v-if auf Root-Ebene</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Vue Template Struktur</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">3</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Modal versteckt</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">z-index Hierarchie</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">CSS Stacking Context</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">4</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Build Cache</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">`node_modules/.vite` + Docker Cache löschen</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Build Pipeline</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">5</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">ref() ohne .value</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">`colFilters.value.feld`</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Vue 3 Reactivity</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">6</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Clientseitige Filter</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Serverseitige Backend-Filter</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Architektur</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">7</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Berechnete Felder nicht sortierbar</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">`sequelize.literal()`</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">ORM/Backend</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">8</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Falsches System</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">URL in Adressleiste prüfen</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Deployment</td></tr></tbody></table>

</div>