Fix #54: Löschreihenfolge korrigiert – invoices vor belege löschen (FK-Constraint)

This commit is contained in:
fds2610-bot 2026-04-26 12:02:21 +02:00
parent eb41c910fc
commit 308895419e

View file

@ -237,12 +237,15 @@ class Invoice
$invoice = self::find($id);
if (!$invoice) return;
if (!empty($invoice['beleg_id'])) {
Database::execute('DELETE FROM bookings WHERE beleg_id = ?', [$invoice['beleg_id']]);
Database::execute('DELETE FROM belege WHERE id = ?', [$invoice['beleg_id']]);
}
$belegId = !empty($invoice['beleg_id']) ? (int)$invoice['beleg_id'] : null;
Database::execute('DELETE FROM invoice_lines WHERE invoice_id = ?', [$id]);
Database::execute('DELETE FROM invoices WHERE id = ?', [$id]);
if ($belegId !== null) {
Database::execute('DELETE FROM bookings WHERE beleg_id = ?', [$belegId]);
Database::execute('DELETE FROM belege WHERE id = ?', [$belegId]);
}
}
public static function generateRechnungsNr(): string