2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-05-07 11:17:56 +00:00
|
|
|
LEFT JOIN account.account a ON a.id = u.id
|
2024-01-15 11:31:03 +00:00
|
|
|
SET u.active = FALSE
|
2024-04-03 08:03:59 +00:00
|
|
|
WHERE c.typeFk = 'normal'
|
2024-05-07 11:17:56 +00:00
|
|
|
AND a.id IS NULL
|
|
|
|
AND u.active
|
|
|
|
AND c.created < util.VN_CURDATE() - INTERVAL 12 MONTH
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-05-07 11:17:56 +00:00
|
|
|
OR t.created > util.VN_CURDATE() - INTERVAL 12 MONTH
|
|
|
|
OR shipped > util.VN_CURDATE() - INTERVAL 12 MONTH
|
2024-01-15 11:31:03 +00:00
|
|
|
);
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|