33 lines
803 B
MySQL
33 lines
803 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerDisable`(vUserId int)
|
||
|
mainLabel:BEGIN
|
||
|
|
||
|
IF (SELECT COUNT(*) FROM workerDisableExcluded WHERE workerFk = vUserId AND (dated > util.VN_CURDATE() OR dated IS NULL)) > 0 THEN
|
||
|
LEAVE mainLabel;
|
||
|
END IF;
|
||
|
|
||
|
DELETE cp FROM clientProtected cp
|
||
|
JOIN client c ON c.id = cp.clientFk
|
||
|
WHERE c.salesPersonFk = vUserId;
|
||
|
|
||
|
DELETE FROM account.account
|
||
|
WHERE id = vUserId;
|
||
|
|
||
|
UPDATE account.user
|
||
|
SET role = 2
|
||
|
WHERE id = vUserId;
|
||
|
|
||
|
DELETE FROM pbx.sip
|
||
|
WHERE user_id = vUserId;
|
||
|
|
||
|
UPDATE `client` c
|
||
|
JOIN payMethod p ON p.name = 'CONTADO'
|
||
|
SET c.credit = 0, c.payMethodFk = p.id, hasCoreVnl = FALSE
|
||
|
WHERE c.id = vUserId;
|
||
|
|
||
|
UPDATE `client` c
|
||
|
SET c.salesPersonFk = null
|
||
|
WHERE c.salesPersonFk = vUserId;
|
||
|
END$$
|
||
|
DELIMITER ;
|