29 lines
670 B
SQL
29 lines
670 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBusiness`(vSelf INT)
|
|
BEGIN
|
|
/**
|
|
* Activates an account and configures its email settings.
|
|
*
|
|
* @param vSelf account id.
|
|
*/
|
|
DECLARE vOldBusinessFk INT;
|
|
DECLARE vNewBusinessFk INT;
|
|
|
|
SELECT businessFk INTO vOldBusinessFk FROM worker WHERE id = vSelf;
|
|
|
|
SELECT id INTO vNewBusinessFk
|
|
FROM business
|
|
WHERE workerFk = vSelf
|
|
AND util.VN_CURDATE() BETWEEN started AND IFNULL(ended, util.VN_CURDATE())
|
|
LIMIT 1;
|
|
|
|
UPDATE worker
|
|
SET businessFk = vNewBusinessFk
|
|
WHERE id = vSelf;
|
|
|
|
IF vOldBusinessFk IS NULL THEN
|
|
CALL account.account_enable(vSelf);
|
|
END IF;
|
|
END$$
|
|
DELIMITER ;
|