22 lines
586 B
SQL
22 lines
586 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`clientsDisable`
|
|
ON SCHEDULE EVERY 1 MONTH
|
|
STARTS '2023-06-01 00:00:00.000'
|
|
ON COMPLETION PRESERVE
|
|
ENABLE
|
|
DO BEGIN
|
|
UPDATE account.user u
|
|
JOIN client c ON c.id = u.id
|
|
SET u.active = FALSE
|
|
WHERE c.typeFk = 'normal'
|
|
AND u.id NOT IN (
|
|
SELECT DISTINCT c.id
|
|
FROM client c
|
|
LEFT JOIN ticket t ON t.clientFk = c.id
|
|
WHERE c.salesPersonFk IS NOT NULL
|
|
OR t.created > util.VN_CURDATE() - INTERVAL 2 MONTH
|
|
OR shipped > util.VN_CURDATE() - INTERVAL 2 MONTH
|
|
);
|
|
END$$
|
|
DELIMITER ;
|