diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4e01532e2..1ac832ba9 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1980,10 +1980,10 @@ INSERT INTO `pbx`.`sip`(`user_id`, `extension`) (5, 1102), (9, 1201); -INSERT INTO `vn`.`professionalCategory` (`id`, `name`, `level`, `dayBreak`) +INSERT INTO `vn`.`professionalCategory` (`id`, `description`) VALUES - (1, 'employee', NULL, NULL), - (2, 'florist', NULL, NULL); + (1, 'employee'), + (2, 'florist'); INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES diff --git a/db/routines/vn/functions/entry_count b/db/routines/vn/functions/entry_count deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/routines/vn/procedures/entry_checkBooked.sql b/db/routines/vn/procedures/entry_checkBooked.sql new file mode 100644 index 000000000..50990cd43 --- /dev/null +++ b/db/routines/vn/procedures/entry_checkBooked.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkBooked`( + vSelf INT +) +BEGIN +/** + * Comprueba si una entrada está contabilizada, + * y si lo está retorna un throw. + * + * @param vSelf Id de entrada + */ + DECLARE vIsBooked BOOL; + + SELECT isBooked INTO vIsBooked + FROM `entry` + WHERE id = vSelf; + + IF vIsBooked THEN + CALL util.throw('Entry is already booked'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_beforeDelete.sql b/db/routines/vn/triggers/buy_beforeDelete.sql index eb7c0ef70..85f1cf298 100644 --- a/db/routines/vn/triggers/buy_beforeDelete.sql +++ b/db/routines/vn/triggers/buy_beforeDelete.sql @@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeDelete` BEFORE DELETE ON `buy` FOR EACH ROW BEGIN + CALL entry_checkBooked(OLD.entryFk); IF OLD.printedStickers <> 0 THEN CALL util.throw("it is not possible to delete buys with printed labels "); END IF; diff --git a/db/routines/vn/triggers/buy_beforeInsert.sql b/db/routines/vn/triggers/buy_beforeInsert.sql index a05f2810b..bc51ac852 100644 --- a/db/routines/vn/triggers/buy_beforeInsert.sql +++ b/db/routines/vn/triggers/buy_beforeInsert.sql @@ -15,6 +15,7 @@ trig: BEGIN LEAVE trig; END IF; + CALL entry_checkBooked(NEW.entryFk); IF NEW.printedStickers <> 0 THEN CALL util.throw('it is not possible to create buy lines with printedstickers other than 0'); END IF; diff --git a/db/routines/vn/triggers/buy_beforeUpdate.sql b/db/routines/vn/triggers/buy_beforeUpdate.sql index 40e0df984..2403091c6 100644 --- a/db/routines/vn/triggers/buy_beforeUpdate.sql +++ b/db/routines/vn/triggers/buy_beforeUpdate.sql @@ -13,6 +13,7 @@ trig:BEGIN LEAVE trig; END IF; + CALL entry_checkBooked(OLD.entryFk); SET NEW.editorFk = account.myUser_getId(); SELECT defaultEntry INTO vDefaultEntry diff --git a/db/routines/vn/triggers/entry_beforeDelete.sql b/db/routines/vn/triggers/entry_beforeDelete.sql index 82a3dabd5..1d2c84b9e 100644 --- a/db/routines/vn/triggers/entry_beforeDelete.sql +++ b/db/routines/vn/triggers/entry_beforeDelete.sql @@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeDelete` BEFORE DELETE ON `entry` FOR EACH ROW BEGIN + CALL entry_checkBooked(OLD.id); DELETE FROM buy WHERE entryFk = OLD.id; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index 384feb458..98ebe1364 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -6,9 +6,13 @@ BEGIN DECLARE vIsVirtual BOOL; DECLARE vPrintedCount INT; DECLARE vHasDistinctWarehouses BOOL; + + IF NEW.isBooked = OLD.isBooked THEN + CALL entry_checkBooked(OLD.id); + END IF; SET NEW.editorFk = account.myUser_getId(); - + IF NOT (NEW.travelFk <=> OLD.travelFk) THEN IF NEW.travelFk IS NOT NULL AND NOT travel_hasUniqueAwb(NEW.travelFk) THEN diff --git a/db/routines/vn/views/salesPersonSince.sql b/db/routines/vn/views/salesPersonSince.sql index 43c45adc0..4234ecac4 100644 --- a/db/routines/vn/views/salesPersonSince.sql +++ b/db/routines/vn/views/salesPersonSince.sql @@ -12,5 +12,5 @@ FROM ( `pc`.`id` = `b`.`workerBusinessProfessionalCategoryFk` ) ) -WHERE `pc`.`name` = 'Aux ventas' +WHERE `pc`.`description` = 'Aux ventas' GROUP BY `b`.`workerFk` diff --git a/db/versions/10968-salmonBamboo/00-firstScript.sql b/db/versions/10968-salmonBamboo/00-firstScript.sql new file mode 100644 index 000000000..b79201071 --- /dev/null +++ b/db/versions/10968-salmonBamboo/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.professionalCategory DROP COLUMN dayBreak, DROP COLUMN `level`; +ALTER TABLE vn.professionalCategory + CHANGE name description varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;