From 7e488ee601bb989ef6298caed17f3bd3dcf20330 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 18 Apr 2024 16:09:05 +0200 Subject: [PATCH] refs #7191 check isBooked in entry_BeforeUpdate --- db/routines/vn/triggers/entry_beforeUpdate.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index 98ebe1364..afe1a25be 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -6,11 +6,20 @@ BEGIN DECLARE vIsVirtual BOOL; DECLARE vPrintedCount INT; DECLARE vHasDistinctWarehouses BOOL; + DECLARE vEntryFkCount INT; IF NEW.isBooked = OLD.isBooked THEN CALL entry_checkBooked(OLD.id); END IF; + IF NEW.isBooked = 1 THEN + SELECT COUNT(*) INTO vEntryFkCount + FROM buy WHERE entryFk = NEW.id; + IF vEntryFkCount = 0 THEN + CALL util.throw('The entry cannot be marked as booked if it does not have lines'); + END IF; + END IF; + SET NEW.editorFk = account.myUser_getId(); IF NOT (NEW.travelFk <=> OLD.travelFk) THEN