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`.`travel_moveRaids`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
2024-10-24 10:33:47 +00:00
|
|
|
/**
|
|
|
|
* Desplaza los travels en el futuro y avisa a los compradores
|
2024-11-21 14:09:58 +00:00
|
|
|
*
|
2024-01-15 11:31:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vDone BOOL DEFAULT FALSE;
|
2024-10-24 10:33:47 +00:00
|
|
|
DECLARE vBuyerEmail VARCHAR(40);
|
|
|
|
DECLARE vTravelLink TEXT;
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE vMailBody TEXT DEFAULT '';
|
|
|
|
|
|
|
|
DECLARE vCur CURSOR FOR
|
2024-11-21 14:09:58 +00:00
|
|
|
SELECT GROUP_CONCAT(DISTINCT
|
|
|
|
CONCAT('https://salix.verdnatura.es/#!/travel/',
|
|
|
|
ttm.travelFk,
|
2024-10-24 10:33:47 +00:00
|
|
|
'/summary ')
|
|
|
|
ORDER BY ttm.travelFk SEPARATOR '\n\r') travelLink,
|
|
|
|
CONCAT(u.name, '@verdnatura.es') buyerEmail
|
|
|
|
FROM tTravelToMove ttm
|
2024-11-21 14:09:58 +00:00
|
|
|
JOIN entry e ON e.travelFk = ttm.travelFk
|
2024-01-15 11:31:03 +00:00
|
|
|
JOIN buy b ON b.entryFk = e.id
|
|
|
|
JOIN item i ON i.id = b.itemFk
|
|
|
|
JOIN itemType it ON it.id = i.typeFk
|
|
|
|
JOIN account.user u ON u.id = it.workerFk
|
|
|
|
GROUP BY u.name;
|
|
|
|
|
2024-11-21 14:09:58 +00:00
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
ROLLBACK;
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
2024-10-24 10:33:47 +00:00
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tTravelToMove
|
2024-11-21 14:09:58 +00:00
|
|
|
SELECT id travelFk,
|
2024-10-24 10:33:47 +00:00
|
|
|
util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded
|
|
|
|
FROM travel
|
2024-11-21 14:09:58 +00:00
|
|
|
WHERE isRaid
|
|
|
|
AND daysInForward;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
START TRANSACTION;
|
|
|
|
|
|
|
|
UPDATE travel tr
|
2024-10-24 10:33:47 +00:00
|
|
|
JOIN tTravelToMove ttm ON ttm.travelFk = tr.id
|
|
|
|
SET tr.landed = ttm.newLanded;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
OPEN vCur;
|
|
|
|
|
|
|
|
l: LOOP
|
|
|
|
SET vDone = FALSE;
|
2024-10-24 10:33:47 +00:00
|
|
|
FETCH vCur INTO vTravelLink, vBuyerEmail;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE l;
|
|
|
|
END IF;
|
|
|
|
|
2024-10-24 10:33:47 +00:00
|
|
|
CALL `vn`.`mail_insert`(
|
|
|
|
vBuyerEmail,
|
|
|
|
'noreply@verdnatura.es',
|
|
|
|
'Cambio de fecha en Redadas',
|
|
|
|
CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink));
|
2024-01-15 11:31:03 +00:00
|
|
|
END LOOP;
|
|
|
|
CLOSE vCur;
|
|
|
|
COMMIT;
|
2024-10-24 10:33:47 +00:00
|
|
|
DROP TEMPORARY TABLE tTravelToMove;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|