2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelving_clean`()
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
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)
|
2024-01-15 11:31:03 +00:00
|
|
|
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]'
|
2024-01-15 11:31:03 +00:00
|
|
|
), TRUE);
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|