Files
Atlas/SESSION-STATUS.md
2025-11-12 20:21:32 +01:00

282 lines
7.0 KiB
Markdown

# ✅ Session-Zusammenfassung: Auto-Workflow & Kalender
**Datum**: 2025-11-12 17:00
**Status**: Auto-Workflow implementiert, Kalender-Integration bereit
---
## ✅ WAS WURDE IMPLEMENTIERT
### 1. Nextcloud CalDAV-Integration
- ✅ CalDAV-Client (`tsdav`) installiert
- ✅ Service-Klasse: `lib/nextcloud-calendar.ts`
- ✅ Funktionen:
- `createBookingEvent()` - Erstellt Kalender-Eintrag
- `updateBookingEvent()` - Aktualisiert Eintrag
- `deleteBookingEvent()` - Löscht Eintrag
- `updateEventStatus()` - Ändert Status-Emoji (🟡 → 🟢)
- ✅ ICS-Format-Generierung (kompatibel mit Nextcloud)
- ✅ Credentials in `.env` hinterlegt (siehe NEXTCLOUD-SETUP.md)
**Nextcloud-Zugangsdaten**:
- URL: https://cloud.savethemoment.photos
- Benutzername: SaveTheMoment-Atlas
- Passwort: T.H,Nwq>S"83Vp7
### 2. Auto-Workflow Cron-Job
**Datei**: `app/api/cron/process-pending-bookings/route.ts`
**Läuft**: Alle 5 Minuten
**Was passiert**:
1. ✅ Findet neue Buchungen (`aiParsed=false`)
2. ✅ KI-Analyse mit GPT-4 (E-Mail-Entwurf)
3. ✅ LexOffice Kontakt erstellen
4. ✅ LexOffice Angebot-Entwurf erstellen
5. ✅ Kalender-Eintrag in Nextcloud erstellen
6. ✅ Status: `readyForAssignment=true` (Admin kann jetzt prüfen)
### 3. Cron-Jobs aktualisiert
**Datei**: `vercel.json`
```json
{
"crons": [
{
"path": "/api/cron/email-sync",
"schedule": "*/5 * * * *" // Alle 5 Min (vorher 15)
},
{
"path": "/api/cron/process-pending-bookings",
"schedule": "*/5 * * * *" // NEU: Auto-Workflow
},
{
"path": "/api/cron/check-contracts",
"schedule": "*/15 * * * *" // Bleibt bei 15 Min
}
]
}
```
### 4. Sidebar erweitert: Weitere Projekte
**Datei**: `components/DashboardSidebar.tsx`
**Neue Menüpunkte** (klappbar unter "Weitere Projekte"):
- 🔵 Die Fotoboxjungs (www.diefotoboxjungs.de)
- 🟢 Die Klönbox (www.die-kloenbox.de)
- 🩷 Hochzeitsbuchstaben (www.hochzeitsbuchstaben.de)
- 🟣 Forte & Friends (www.forte.dj)
- 🟡 Melobox (www.melobox.de)
---
## 🔄 WORKFLOW-ABLAUF (Automatisch)
### Phase 1: E-Mail-Eingang → Auto-Verarbeitung
```
Cron-Job läuft alle 5 Min
Prüft IMAP-Postfach (Lübeck)
Neue E-Mail → Erstellt Booking (Status: RESERVED, aiParsed=false)
Cron-Job "process-pending-bookings" findet Buchung
GPT-4 generiert E-Mail-Antwort-Entwurf
LexOffice erstellt Kontakt
LexOffice erstellt Angebot-Entwurf
Nextcloud Kalender: Eintrag erstellt (🟡 Reserviert)
Status: readyForAssignment=true
```
### Phase 2: Admin-Review (UI fehlt noch!)
```
Dashboard zeigt: "Offene Anfragen" Badge
Admin klickt auf Anfrage
Sieht:
- KI-generierte E-Mail (Entwurf)
- LexOffice Angebot (Link)
- Extrahierte Kundendaten
Admin prüft & klickt:
[✓ Senden] oder [✗ Korrigieren]
```
### Phase 3: Auto-Versand (noch zu implementieren!)
```
Admin klickt "Senden"
System sendet E-Mail mit:
- Personalisierte Nachricht
- Angebot (PDF-Anhang)
- Mietvertrag (PDF-Anhang)
Kalender-Update: 🟡 → 🟢 (CONFIRMED)
Status: RESERVED
```
---
## ⚙️ SETUP ANLEITUNG
### 1. Nextcloud-Credentials hinzufügen
Öffne `.env` und füge hinzu:
```bash
NEXTCLOUD_URL="https://cloud.savethemoment.photos"
NEXTCLOUD_USERNAME="SaveTheMoment-Atlas"
NEXTCLOUD_PASSWORD="T.H,Nwq>S\"83Vp7"
```
### 2. Server neu starten
```bash
npm run dev
```
### 3. Kalender-Verbindung testen
```bash
# Test-Endpunkt (muss noch erstellt werden):
curl http://localhost:3001/api/calendar/test
```
### 4. Cron-Jobs lokal testen
```bash
# E-Mail-Sync (manuelle Trigger):
curl -H "Authorization: Bearer your-cron-secret" \
http://localhost:3001/api/cron/email-sync
# Auto-Workflow:
curl -H "Authorization: Bearer your-cron-secret" \
http://localhost:3001/api/cron/process-pending-bookings
```
---
## 📋 NÄCHSTE SCHRITTE (noch zu implementieren)
### 1. Admin-Review UI (Dashboard-Widget)
- [ ] Widget: "Offene Anfragen" auf Dashboard
- [ ] Review-Modal mit Tabs:
- E-Mail-Vorschau
- Angebot-Vorschau (LexOffice Link)
- Kundendaten bearbeiten
- [ ] Button: "Prüfen & Senden"
### 2. Auto-Versand API
- [ ] API: `/api/bookings/[id]/approve-and-send`
- [ ] E-Mail-Versand mit Anhängen
- [ ] Kalender-Update (Status-Change)
### 3. Datenbank-Erweiterung (neue Felder)
```prisma
model Booking {
// Workflow-Status
aiDraftReady Boolean @default(false)
adminReviewedAt DateTime?
adminReviewedBy String?
// Kalender-Sync
calendarEventId String?
calendarSynced Boolean @default(false)
calendarSyncedAt DateTime?
// Versand-Status
documentsSentAt DateTime?
documentsSentTo String?
}
```
### 4. Kalender-Test-API erstellen
- [ ] `GET /api/calendar/test` - Testet Nextcloud-Verbindung
- [ ] `POST /api/calendar/sync` - Sync manuell triggern
### 5. Multi-Projekt-Support
- [ ] Projekt-Model im Schema
- [ ] Buchungen mit Projekt verknüpfen
- [ ] Projekt-spezifische Preise & Settings
- [ ] Projekt-Filter im Dashboard
---
## 🧪 TESTING
### Was du jetzt testen kannst:
1. **Tour erstellen** (3 CONFIRMED Buchungen vorhanden):
- http://localhost:3001/dashboard/tours
- Wähle 2-3 Buchungen aus
- Routenoptimierung startet automatisch
2. **LexOffice-Integration** (manuell):
```bash
curl -X POST http://localhost:3001/api/bookings/[BOOKING-ID]/create-quotation
```
3. **Sidebar**: Weitere Projekte
- Klicke auf "Weitere Projekte" (sollte aufklappen)
- 5 neue Projekte sichtbar
### Was noch NICHT funktioniert:
1. ❌ **Nextcloud-Kalender** (Credentials müssen in `.env` eingetragen werden)
2. ❌ **Auto-Workflow Cron** (läuft erst auf Vercel oder mit lokalem Cron-Trigger)
3. ❌ **Admin-Review UI** (Widget fehlt noch)
4. ❌ **Auto-Versand** (E-Mail-Funktion fehlt noch)
---
## 🔐 WICHTIGE ERINNERUNGEN
### 1. Nextcloud-Passwort enthält Sonderzeichen!
```bash
# RICHTIG:
NEXTCLOUD_PASSWORD="T.H,Nwq>S\"83Vp7"
# FALSCH (ohne Quotes):
NEXTCLOUD_PASSWORD=T.H,Nwq>S"83Vp7
```
### 2. Cron-Jobs funktionieren nur auf Vercel!
Lokal musst du sie manuell triggern:
```bash
curl -H "Authorization: Bearer your-cron-secret" \
http://localhost:3001/api/cron/process-pending-bookings
```
### 3. SMTP-Settings nur in Lübeck
Für Auto-Versand wird die E-Mail-Config von Location "Lübeck" verwendet.
---
## 📊 IMPLEMENTATION STATUS
| Feature | Status | Geschätzte Zeit |
|---------|--------|----------------|
| ✅ Nextcloud CalDAV | Komplett | - |
| ✅ Auto-Workflow Cron | Komplett | - |
| ✅ Sidebar: Projekte | Komplett | - |
| ✅ Cron: 5-Min-Intervall | Komplett | - |
| ⏳ Admin-Review UI | Ausstehend | 2-3 Tage |
| ⏳ Auto-Versand API | Ausstehend | 1-2 Tage |
| ⏳ DB-Migration (neue Felder) | Ausstehend | 1 Tag |
| ⏳ Multi-Projekt-Support | Ausstehend | 3-4 Tage |
**Gesamt-Fortschritt**: ~40% (Basis-Infrastruktur fertig)
---
**Nächster Schritt**:
1. `.env` mit Nextcloud-Credentials ergänzen
2. Kalender-Verbindung testen
3. Entscheidung: Soll ich mit Admin-Review UI weitermachen?
---
_Erstellt: 2025-11-12 17:05_