diff --git a/docs/INSIGHT-CRM.md b/docs/INSIGHT-CRM.md index 5b8e6f6..a88cd9d 100644 --- a/docs/INSIGHT-CRM.md +++ b/docs/INSIGHT-CRM.md @@ -623,4 +623,267 @@ Komplette Frontend-Integration fuer Lexware Office, basierend auf den neuen Back --- +## 2026-03-11 | Backend: Company Detail Overhaul — Neue Entitaeten und Endpoints + +### Ueberblick + +Die Company-Entity wurde massiv erweitert: Branchen, Kontotypen und Beziehungstypen sind jetzt als admin-konfigurierbare Entitaeten implementiert (statt Freitext). Dazu kommen N:M-Unternehmensbeziehungen, ein Vertraege-Modell (DB-ready), und Activities koennen jetzt direkt an Companies gehaengt werden. + +### Neue Prisma-Models + +| Model | Tabelle | Beschreibung | +|-------|---------|-------------| +| `Industry` | `industries` | Admin-konfigurierbare Branchen mit Farbe (unique pro Tenant) | +| `AccountType` | `account_types` | Admin-konfigurierbare Kontotypen (unique pro Tenant) | +| `RelationshipType` | `relationship_types` | Admin-konfigurierbare Beziehungstypen (unique pro Tenant) | +| `CompanyRelationship` | `company_relationships` | N:M Company-zu-Company Beziehungen mit Typ und Notizen | +| `Contract` | `contracts` | Vertraege (DB-Modell vorhanden, UI-Platzhalter) | + +### Aenderungen an Company + +Neue Felder auf dem Company-Objekt: + +```typescript +{ + industryId?: string; // UUID -> Industry + accountTypeId?: string; // UUID -> AccountType + ownerId?: string; // UUID (Referenz auf core User, kein FK) + ownerName?: string; // Denormalisiert, z.B. "Thomas Reitz" + industryRef?: { // Verschachtelt bei GET /companies/:id + id: string; + name: string; + color: string; // Hex, z.B. "#3B82F6" + }; + accountType?: { // Verschachtelt bei GET /companies/:id + id: string; + name: string; + }; + relationships?: CompanyRelationship[]; // Bei GET /companies/:id + contracts?: Contract[]; // Bei GET /companies/:id +} +``` + +**Wichtig**: Das alte `industry`-Freitext-Feld bleibt vorlaeufig bestehen. Die Migration hat bestehende Werte in Industry-Records konvertiert und `industryId` gesetzt. + +### Aenderungen an Activity + +`contactId` ist jetzt **optional** (war vorher required). Neues Feld `companyId` (optional). Mindestens eines von beiden muss gesetzt sein. + +```typescript +{ + contactId?: string; // UUID, optional + companyId?: string; // UUID, NEU, optional + company?: { id: string; name: string }; // Verschachtelt +} +``` + +**Neuer Query-Parameter fuer aggregierten Feed:** +``` +GET /crm/activities?companyId=X&includeContacts=true +``` +Liefert alle Aktivitaeten die direkt an der Company haengen PLUS alle Aktivitaeten der verknuepften Kontakte. Kontakt-Aktivitaeten haben `contact`-Objekt im Response. + +### Neue API-Endpoints: Industries (Branchen) + +| Methode | Pfad | Beschreibung | +|---------|------|-------------| +| GET | `/crm/industries` | Liste aller Branchen (sortiert nach sortOrder) | +| POST | `/crm/industries` | Branche erstellen (`name`*, `color?`, `sortOrder?`) | +| PATCH | `/crm/industries/:id` | Branche bearbeiten | +| DELETE | `/crm/industries/:id` | Branche loeschen (Schutz bei Referenzen) | + +### Neue API-Endpoints: AccountTypes (Kontotypen) + +| Methode | Pfad | Beschreibung | +|---------|------|-------------| +| GET | `/crm/account-types` | Liste aller Kontotypen | +| POST | `/crm/account-types` | Kontotyp erstellen (`name`*, `sortOrder?`) | +| PATCH | `/crm/account-types/:id` | Kontotyp bearbeiten | +| DELETE | `/crm/account-types/:id` | Kontotyp loeschen | + +### Neue API-Endpoints: RelationshipTypes (Beziehungstypen) + +| Methode | Pfad | Beschreibung | +|---------|------|-------------| +| GET | `/crm/relationship-types` | Liste aller Beziehungstypen | +| POST | `/crm/relationship-types` | Beziehungstyp erstellen (`name`*, `sortOrder?`) | +| PATCH | `/crm/relationship-types/:id` | Beziehungstyp bearbeiten | +| DELETE | `/crm/relationship-types/:id` | Beziehungstyp loeschen | + +### Neue API-Endpoints: Company Relationships (Unternehmensbeziehungen) + +| Methode | Pfad | Beschreibung | +|---------|------|-------------| +| GET | `/crm/companies/:id/relationships` | Beziehungen eines Unternehmens (bidirektional) | +| POST | `/crm/companies/:id/relationships` | Beziehung erstellen | +| DELETE | `/crm/companies/:id/relationships/:relId` | Beziehung loeschen | + +**POST-Body:** +```json +{ + "relatedCompanyId": "uuid", + "relationshipTypeId": "uuid", + "notes": "optional" +} +``` + +**GET-Response (einzelne Beziehung):** +```json +{ + "id": "uuid", + "relatedCompany": { "id": "uuid", "name": "Firma XY" }, + "relationshipType": { "id": "uuid", "name": "Endkunde" }, + "direction": "outgoing", + "notes": "..." +} +``` +`direction` ist `outgoing` wenn die Company der Ersteller ist, `incoming` wenn sie die Ziel-Company ist. + +### Neuer Endpoint: Tenant-User (fuer Owner-Dropdown) + +| Methode | Pfad | Beschreibung | +|---------|------|-------------| +| GET | `/crm/users` | Liste der Tenant-Benutzer | + +**Response:** +```json +{ + "data": [ + { "id": "uuid", "firstName": "Thomas", "lastName": "Reitz", "email": "treitz@xinion.de" } + ] +} +``` + +### Seed-Daten (Standard-Konfiguration) + +**Industries (8):** IT & Software (#3B82F6), Produktion (#F59E0B), Handel (#10B981), Dienstleistung (#8B5CF6), Gesundheit (#EF4444), Finanzen (#6366F1), Bildung (#EC4899), Oeffentlicher Sektor (#6B7280) + +**AccountTypes (4):** Interessent, Endkunde, Personaldienstleister, Partner + +**RelationshipTypes (4):** Endkunde, Abrechnungspartner, Muttergesellschaft, Tochtergesellschaft + +### Deployment-Info + +- Branch: `feature/crm-service` +- Prisma Migration: `20260311_add_company_detail_overhaul` +- Neue Module in app.module.ts: IndustriesModule, AccountTypesModule, RelationshipTypesModule, CompanyRelationshipsModule +- Seed-Data muss nach Migration ausgefuehrt werden + +--- + +## 2026-03-11 | Frontend: Company Detail Page Overhaul — 3-Spalten-Layout + +### Was wurde umgesetzt + +Kompletter Umbau der CompanyDetailPage von 2-Spalten auf 3-Spalten-Layout. Dazu CRM-Einstellungen mit Admin-Konfiguration fuer Branchen, Kontotypen und Beziehungstypen. + +### Neue Dateien + +``` +packages/frontend/src/crm/companies/ + ActivityFeed.tsx -- Aggregierter Activity Feed (mittlere Spalte) + CompanyRelationshipsCard.tsx -- N:M Unternehmensbeziehungen Card + ContractsCard.tsx -- Platzhalter "Modul in Entwicklung" +``` + +### Geaenderte Dateien + +| Datei | Aenderung | +|-------|-----------| +| `types.ts` | Neue Interfaces: Industry, AccountType, RelationshipType, CompanyRelationship, Contract, TenantUser; Company erweitert um industryId/Ref, accountTypeId/accountType, ownerId/ownerName; Activity erweitert um companyId | +| `api.ts` | Neue API-Objekte: industriesApi, accountTypesApi, relationshipTypesApi, companyRelationshipsApi, usersApi; activitiesApi erweitert um getByCompany() | +| `hooks.ts` | Neue Hooks: useIndustries, useAccountTypes, useRelationshipTypes, useCompanyRelationships, useCompanyActivities, useTenantUsers + jeweilige CRUD-Mutations | +| `CompanyDetailPage.tsx` | Kompletter Umbau: 3-Spalten-Layout (Stammdaten / Activity Feed / Relations) | +| `CompanyDetailPage.module.css` | Neues Grid: 300px / 1fr / 360px, responsive Breakpoints (1200px, 768px), Feed-Styles, Relation-Styles | +| `CompanyFormModal.tsx` | Dropdowns statt Freitext: Branche (useIndustries), Kontotyp (useAccountTypes), Zustaendigkeit (useTenantUsers) | +| `ActivityFormModal.tsx` | contactId jetzt optional, neues Prop companyId | +| `DealsPage.tsx` | Spacing Fix: minWidth fuer Stage (120px) und Wert (100px) Spalten | +| `settings/CrmSettingsPage.tsx` | 3 neue Config-Sektionen: Branchen (mit Color-Picker), Kontotypen, Beziehungstypen | +| `settings/CrmSettingsPage.module.css` | Styles fuer Config-Tabellen, Inline-Edit, Sort-Buttons | + +### CompanyDetailPage — 3-Spalten-Layout + +``` ++------------------+------------------------+--------------------+ +| Linke Spalte | Mittlere Spalte | Rechte Spalte | +| (300px) | (flex) | (360px) | ++------------------+------------------------+--------------------+ +| Stammdaten: | Activity Feed: | Kontakte (Tabelle) | +| - Name | - Inline-Notiz-Form | Vorgaenge (Tabelle)| +| - Branche Badge | - Tabs: Notiz/Email/ | Beziehungen Card | +| (farbig) | Aufgabe | Vertraege | +| - Kontotyp | - Chronologische | (Platzhalter) | +| - Zustaendigkeit | Liste aller | Lexware Belege | +| - E-Mail, Tel | Aktivitaeten | | +| - Website | - "via [Kontakt]" | | +| - Adresse | Badge fuer | | +| - Tags | Kontakt-Aktivitaeten | | +| - Notizen | | | ++------------------+------------------------+--------------------+ +``` + +**Responsive:** +- Ab 1200px: 2 Spalten (Links+Mitte gestapelt | Rechts) +- Ab 768px: 1 Spalte (alles gestapelt) + +### Activity Feed Details + +- Nutzt `GET /crm/activities?companyId=X&includeContacts=true` +- Inline-Formular oben: Betreff + Beschreibung + "Notiz speichern" Button +- Tabs: "Notiz" (aktiv), "E-Mail" (disabled, Platzhalter), "Aufgabe" (disabled, Platzhalter) +- Jeder Eintrag: Typ-Icon (SVG), Betreff, Ersteller, Zeitpunkt +- Kontakt-Aktivitaeten zeigen "via [Kontaktname]" Badge + +### CRM-Einstellungen — Admin-Konfiguration + +Drei neue Sektionen in `/crm/settings`: + +1. **Branchen**: CRUD-Tabelle mit Name, Farb-Badge + Color-Picker, Sortier-Pfeile +2. **Kontotypen**: CRUD-Tabelle mit Name, Sortier-Pfeile +3. **Beziehungstypen**: CRUD-Tabelle mit Name, Sortier-Pfeile + +Alle mit Inline-Add (Eingabezeile oben), Inline-Edit, Delete mit Bestaetigung. + +### CompanyFormModal — Dropdown-Aenderungen + +| Feld | Vorher | Nachher | +|------|--------|---------| +| Branche | Freitext-Input | Select-Dropdown aus `GET /crm/industries` | +| Kontotyp | — (neu) | Select-Dropdown aus `GET /crm/account-types` | +| Zustaendigkeit | — (neu) | Select-Dropdown aus `GET /crm/users` | + +`ownerName` wird beim Submit aus der User-Liste aufgeloest und im Payload mitgesendet. + +### Genutzte neue Backend-Endpoints + +| Hook | Endpoint | Verwendung | +|------|----------|-----------| +| `useIndustries()` | `GET /crm/industries` | CompanyFormModal Dropdown, CRM Settings | +| `useAccountTypes()` | `GET /crm/account-types` | CompanyFormModal Dropdown, CRM Settings | +| `useRelationshipTypes()` | `GET /crm/relationship-types` | AddRelationshipModal, CRM Settings | +| `useCompanyRelationships(id)` | `GET /crm/companies/:id/relationships` | CompanyRelationshipsCard | +| `useCompanyActivities(id)` | `GET /crm/activities?companyId=X&includeContacts=true` | ActivityFeed | +| `useTenantUsers()` | `GET /crm/users` | CompanyFormModal Owner-Dropdown | +| `useCreateIndustry()` | `POST /crm/industries` | CRM Settings | +| `useUpdateIndustry()` | `PATCH /crm/industries/:id` | CRM Settings | +| `useDeleteIndustry()` | `DELETE /crm/industries/:id` | CRM Settings | +| (analog fuer AccountTypes + RelationshipTypes) | | | +| `useCreateCompanyRelationship()` | `POST /crm/companies/:id/relationships` | CompanyRelationshipsCard | +| `useDeleteCompanyRelationship()` | `DELETE /crm/companies/:id/relationships/:relId` | CompanyRelationshipsCard | + +### Offene Punkte + +- [ ] **Migration auf Server anwenden**: `20260311_add_company_detail_overhaul` + Seed-Data +- [ ] **Container neu bauen und deployen** (Frontend + Backend) +- [ ] **Kanban-Board fuer Vorgaenge** — Feature fuer spaeter geplant +- [ ] **Vertraege-UI implementieren** — DB-Modell vorhanden, UI ist noch Platzhalter +- [ ] **Activity Feed E-Mail/Aufgabe Tabs** — Derzeit Platzhalter (disabled) + +### TypeScript-Status + +- Frontend: `npx tsc --noEmit` — 0 Fehler +- Backend: `npx tsc --noEmit` — 0 Fehler (nach `prisma generate`) + +--- + *Bitte neue Eintraege unten anfuegen. Format: `## YYYY-MM-DD | Absender: Betreff`*