salix/db/routines/vn/procedures/shelving_clean.sql

39 lines
995 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelving_clean`()
BEGIN
DELETE FROM shelving
WHERE length(code) > 3
AND parked < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
DELETE FROM itemShelving
WHERE visible <= 0
AND created < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE());
DELETE ish.*
FROM itemShelving ish
2024-11-13 08:03:44 +00:00
JOIN vn.shelving sh ON sh.id = ish.shelvingFk
WHERE sh.parkingFk IS NULL
AND ish.created < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
UPDATE shelving sh
2024-11-13 08:03:44 +00:00
LEFT JOIN itemShelving its ON its.shelvingFk = sh.id
SET isPrinted = 0,
parkingFk = NULL
WHERE its.id IS NULL
AND sh.isRecyclable
AND (
sh.parked IS NULL
OR
2024-09-18 09:48:50 +00:00
sh.parked < util.VN_CURDATE() - INTERVAL 2 WEEK
)
AND IF(code REGEXP '^[A-Za-z]{2}[0-9]', LEFT (code, 2) NOT IN (
2024-11-13 08:03:44 +00:00
SELECT DISTINCT LEFT(sh.code, 2)
FROM itemShelving its
2024-11-13 08:03:44 +00:00
JOIN shelving sh ON sh.id = its.shelvingFk
WHERE sh.code REGEXP '^[A-Za-z]{2}[0-9]'
), TRUE);
END$$
DELIMITER ;