diff --git a/db/routines/vn/procedures/invoiceIn_checkBooked.sql b/db/routines/vn/procedures/invoiceIn_checkBooked.sql new file mode 100644 index 000000000..862870eb4 --- /dev/null +++ b/db/routines/vn/procedures/invoiceIn_checkBooked.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_checkBooked`( + vSelf INT +) +BEGIN +/** + * Comprueba si una factura recibida está contabilizada, + * y si lo está retorna un throw. + * + * @param vSelf Id invoiceIn + */ + DECLARE vIsBooked BOOL; + + SELECT isBooked INTO vIsBooked + FROM invoiceIn + WHERE id = vSelf; + + IF vIsBooked THEN + CALL util.throw('InvoiceIn is already booked'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql b/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql new file mode 100644 index 000000000..f4df48dcd --- /dev/null +++ b/db/routines/vn/triggers/invoiceInCorrection_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInCorrection_beforeDelete` + BEFORE DELETE ON `invoiceInCorrection` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.correctingFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInCorrection_beforeUpdate.sql b/db/routines/vn/triggers/invoiceInCorrection_beforeUpdate.sql new file mode 100644 index 000000000..bd324863b --- /dev/null +++ b/db/routines/vn/triggers/invoiceInCorrection_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInCorrection_beforeUpdate` + BEFORE UPDATE ON `invoiceInCorrection` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.correctingFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql b/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql new file mode 100644 index 000000000..3b0f90d0d --- /dev/null +++ b/db/routines/vn/triggers/invoiceInDueDay_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_beforeDelete` + BEFORE DELETE ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.id); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql b/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql index f7e4265a7..c23ead0e4 100644 --- a/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql +++ b/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql @@ -5,6 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_befor BEGIN DECLARE vIsNotified BOOLEAN; + CALL invoiceIn_checkBooked(OLD.invoiceInFk); SET NEW.editorFk = account.myUser_getId(); SELECT isNotified INTO vIsNotified diff --git a/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql b/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql new file mode 100644 index 000000000..412b091f4 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInIntrastat_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_beforeDelete` + BEFORE DELETE ON `invoiceInIntrastat` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.invoiceInFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInIntrastat_beforeUpdatesql b/db/routines/vn/triggers/invoiceInIntrastat_beforeUpdatesql new file mode 100644 index 000000000..649c9ef30 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInIntrastat_beforeUpdatesql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInIntrastat_beforeUpdate` + BEFORE UPDATE ON `invoiceInIntrastat` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.invoiceInFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql b/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql new file mode 100644 index 000000000..a43f602b4 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInTax_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeDelete` + BEFORE DELETE ON `invoiceInTax` + FOR EACH ROW +BEGIN + CALL invoiceIn_checkBooked(OLD.invoiceInFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql b/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql index 30918b7c5..3e5ecf030 100644 --- a/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql +++ b/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql @@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeUp BEFORE UPDATE ON `invoiceInTax` FOR EACH ROW BEGIN + CALL invoiceIn_checkBooked(OLD.invoiceInFk); + IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); END IF; diff --git a/db/routines/vn/triggers/invoiceIn_afterDelete.sql b/db/routines/vn/triggers/invoiceIn_afterDelete.sql index c088f6492..90fac193d 100644 --- a/db/routines/vn/triggers/invoiceIn_afterDelete.sql +++ b/db/routines/vn/triggers/invoiceIn_afterDelete.sql @@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_afterDelete AFTER DELETE ON `invoiceIn` FOR EACH ROW BEGIN + CALL invoiceIn_checkBooked(OLD.id); + INSERT INTO invoiceInLog SET `action` = 'delete', `changedModel` = 'InvoiceIn', diff --git a/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql b/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql index 4503c7dbd..688a3af92 100644 --- a/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql +++ b/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql @@ -5,6 +5,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdat BEGIN DECLARE vWithholdingSageFk INT; + CALL invoiceIn_checkBooked(OLD.id); + IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN CALL util.throw('The invoiceIn reference contains invalid characters'); END IF;