salix/db/routines/vn/procedures/ticket_setNextState.sql

24 lines
554 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT)
BEGIN
/**
* Cambia el estado del ticket al siguiente estado según la tabla state
*
* @param vSelf id dle ticket
*/
DECLARE vStateFk INT;
DECLARE vNewStateFk INT;
SELECT stateFk INTO vStateFk
FROM ticketState
WHERE ticketFk = vSelf;
SELECT nextStateFk INTO vNewStateFk
FROM state
WHERE id = vStateFk;
INSERT INTO ticketTracking(stateFk, ticketFk, userFk)
VALUES (vNewStateFk, vSelf, account.myUser_getId());
END$$
DELIMITER ;