diff --git a/src/Models/Invoice.php b/src/Models/Invoice.php index 6396e0b..20741e0 100644 --- a/src/Models/Invoice.php +++ b/src/Models/Invoice.php @@ -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