From 308895419e3aca86c2dc2ae0cd6f4c8ec53a0e7e Mon Sep 17 00:00:00 2001 From: fds2610-bot Date: Sun, 26 Apr 2026 12:02:21 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#54:=20L=C3=B6schreihenfolge=20korrigiert?= =?UTF-8?q?=20=E2=80=93=20invoices=20vor=20belege=20l=C3=B6schen=20(FK-Con?= =?UTF-8?q?straint)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Invoice.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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