feat: Equipment-System, Buchungsbearbeitung, Kundenadresse, LexOffice-Fix
- Vintage Modell hinzugefuegt - Equipment Multi-Select (Neue Buchung + Bearbeitung) - Kundenadresse in Formularen - Bearbeiten-Seite fuer Buchungen - Abbau-Zeiten in Formularen und Uebersicht - Vertrag PDF nur bei Privatkunden - LexOffice Kontakt-Erstellung Fix (BUSINESS) - Zurueck-Pfeil auf Touren-Seite
This commit is contained in:
54
app/api/bookings/[id]/quotation-pdf/route.ts
Normal file
54
app/api/bookings/[id]/quotation-pdf/route.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { lexofficeService } from '@/lib/lexoffice';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session || session.user.role !== 'ADMIN') {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const bookingId = params.id;
|
||||
|
||||
const booking = await prisma.booking.findUnique({
|
||||
where: { id: bookingId },
|
||||
select: {
|
||||
id: true,
|
||||
bookingNumber: true,
|
||||
lexofficeOfferId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!booking) {
|
||||
return NextResponse.json({ error: 'Buchung nicht gefunden' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (!booking.lexofficeOfferId) {
|
||||
return NextResponse.json({ error: 'Kein LexOffice Angebot vorhanden' }, { status: 404 });
|
||||
}
|
||||
|
||||
const pdfBuffer = await lexofficeService.getQuotationPDF(booking.lexofficeOfferId);
|
||||
|
||||
return new NextResponse(pdfBuffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `attachment; filename="Angebot_${booking.bookingNumber}.pdf"`,
|
||||
},
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('❌ PDF-Download Fehler:', error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'PDF-Download fehlgeschlagen' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user