Merge pull request 'refactor: refs #7375 Refactor clientsDisable' (!2471) from 7375-clientsDisable into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2471 Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
commit
b33d4ce319
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`client_userDisable`
|
||||||
|
ON SCHEDULE EVERY 1 MONTH
|
||||||
|
STARTS '2023-06-01 00:00:00.000'
|
||||||
|
ON COMPLETION PRESERVE
|
||||||
|
ENABLE
|
||||||
|
DO CALL client_userDisable()$$
|
||||||
|
DELIMITER ;
|
|
@ -1,25 +0,0 @@
|
||||||
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
|
|
||||||
LEFT JOIN account.account a ON a.id = u.id
|
|
||||||
SET u.active = FALSE
|
|
||||||
WHERE c.typeFk = 'normal'
|
|
||||||
AND a.id IS NULL
|
|
||||||
AND u.active
|
|
||||||
AND c.created < util.VN_CURDATE() - INTERVAL 12 MONTH
|
|
||||||
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 12 MONTH
|
|
||||||
OR shipped > util.VN_CURDATE() - INTERVAL 12 MONTH
|
|
||||||
);
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_userDisable`()
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Desactiva los clientes inactivos en los últimos X meses.
|
||||||
|
*/
|
||||||
|
DECLARE vMonths INT;
|
||||||
|
|
||||||
|
SELECT monthsToDisableUser INTO vMonths
|
||||||
|
FROM clientConfig;
|
||||||
|
|
||||||
|
IF vMonths IS NULL THEN
|
||||||
|
CALL util.throw('Config parameter not set');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
UPDATE account.user u
|
||||||
|
JOIN client c ON c.id = u.id
|
||||||
|
LEFT JOIN account.account a ON a.id = u.id
|
||||||
|
SET u.active = FALSE
|
||||||
|
WHERE c.typeFk = 'normal'
|
||||||
|
AND a.id IS NULL
|
||||||
|
AND u.active
|
||||||
|
AND c.created < util.VN_CURDATE() - INTERVAL vMonths MONTH
|
||||||
|
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 vMonths MONTH
|
||||||
|
OR shipped > util.VN_CURDATE() - INTERVAL vMonths MONTH
|
||||||
|
);
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE vn.clientConfig
|
||||||
|
ADD monthsToDisableUser int(10) unsigned DEFAULT NULL NULL;
|
||||||
|
|
||||||
|
UPDATE IGNORE vn.clientConfig
|
||||||
|
SET monthsToDisableUser = 12;
|
Loading…
Reference in New Issue