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

32 lines
996 B
MySQL
Raw Normal View History

2024-03-05 11:41:54 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`raidUpdate`()
2024-03-05 11:41:54 +00:00
BEGIN
2024-04-12 05:58:18 +00:00
/**
* Actualiza el travel de las entradas de redadas
*/
2024-03-05 11:41:54 +00:00
UPDATE entry e
JOIN entryVirtual ev ON ev.entryFk = e.id
JOIN travel t ON t.id = e.travelFk
JOIN (
SELECT *
FROM (
2024-04-12 10:13:07 +00:00
SELECT t.id, t.landed, tt.warehouseInFk, tt.warehouseOutFk
2024-03-05 11:41:54 +00:00
FROM travel t
JOIN (
SELECT t.warehouseInFk, t.warehouseOutFk
FROM entryVirtual ev
JOIN entry e ON e.id = ev.entryFk
JOIN travel t ON t.id = e.travelFk
GROUP BY t.warehouseInFk, t.warehouseOutFk
) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk
2024-04-12 10:13:07 +00:00
WHERE shipped > util.VN_CURDATE() AND NOT isDelivered
2024-03-05 11:41:54 +00:00
ORDER BY t.landed
LIMIT 10000000000000000000
2024-04-12 06:44:06 +00:00
) t
2024-04-12 10:13:07 +00:00
GROUP BY t.warehouseInFk, t.warehouseOutFk
2024-03-05 11:41:54 +00:00
) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk
SET e.travelFk = t.id;
END$$
DELIMITER ;