|
|
|
@ -8,22 +8,15 @@ BEGIN
|
|
|
|
|
DECLARE vDone BOOL DEFAULT FALSE;
|
|
|
|
|
DECLARE vBuyerEmail VARCHAR(40);
|
|
|
|
|
DECLARE vTravelLink TEXT;
|
|
|
|
|
DECLARE vMailBody TEXT DEFAULT '';
|
|
|
|
|
DECLARE vMailBody TEXT;
|
|
|
|
|
DECLARE vDaysBetweenDates INT;
|
|
|
|
|
DECLARE vSubject VARCHAR(30);
|
|
|
|
|
|
|
|
|
|
DECLARE vCur CURSOR FOR
|
|
|
|
|
SELECT GROUP_CONCAT(DISTINCT
|
|
|
|
|
CONCAT('https://salix.verdnatura.es/#!/travel/',
|
|
|
|
|
ttm.travelFk,
|
|
|
|
|
'/summary ')
|
|
|
|
|
ORDER BY ttm.travelFk SEPARATOR '\n\r') travelLink,
|
|
|
|
|
CONCAT(u.name, '@verdnatura.es') buyerEmail
|
|
|
|
|
FROM tTravelToMove ttm
|
|
|
|
|
JOIN entry e ON e.travelFk = ttm.travelFk
|
|
|
|
|
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;
|
|
|
|
|
DECLARE vTravels CURSOR FOR
|
|
|
|
|
SELECT GROUP_CONCAT(DISTINCT travelLink ORDER BY id SEPARATOR '\n\r'),
|
|
|
|
|
buyerEmail
|
|
|
|
|
FROM tTravelToMove
|
|
|
|
|
GROUP BY buyerEmail;
|
|
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
|
|
|
|
|
|
|
|
@ -34,35 +27,50 @@ BEGIN
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tTravelToMove
|
|
|
|
|
SELECT id travelFk,
|
|
|
|
|
util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded
|
|
|
|
|
FROM travel
|
|
|
|
|
WITH travels AS (
|
|
|
|
|
SELECT id,
|
|
|
|
|
CONCAT('https://salix.verdnatura.es/#!/travel/', id,'/summary') travelLink,
|
|
|
|
|
util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded,
|
|
|
|
|
util.VN_CURDATE() - INTERVAL DATEDIFF(landed, shipped) + daysInForward DAY newShipped
|
|
|
|
|
FROM vn.travel
|
|
|
|
|
WHERE isRaid
|
|
|
|
|
AND daysInForward;
|
|
|
|
|
AND daysInForward
|
|
|
|
|
)SELECT t.id,
|
|
|
|
|
t.travelLink,
|
|
|
|
|
t.newLanded,
|
|
|
|
|
t.newShipped,
|
|
|
|
|
CONCAT(u.name, '@verdnatura.es') buyerEmail
|
|
|
|
|
FROM travels t
|
|
|
|
|
STRAIGHT_JOIN vn.entry e ON e.travelFk = t.id
|
|
|
|
|
JOIN vn.buy b ON b.entryFk = e.id
|
|
|
|
|
JOIN vn.item i ON i.id = b.itemFk
|
|
|
|
|
JOIN vn.itemType it ON it.id = i.typeFk
|
|
|
|
|
JOIN account.user u ON u.id = it.workerFk
|
|
|
|
|
GROUP BY t.id;
|
|
|
|
|
|
|
|
|
|
START TRANSACTION;
|
|
|
|
|
|
|
|
|
|
UPDATE travel tr
|
|
|
|
|
JOIN tTravelToMove ttm ON ttm.travelFk = tr.id
|
|
|
|
|
SET tr.landed = ttm.newLanded;
|
|
|
|
|
JOIN tTravelToMove ttm ON ttm.id = tr.id
|
|
|
|
|
SET tr.landed = ttm.newLanded,
|
|
|
|
|
tr.shipped = ttm.newShipped;
|
|
|
|
|
|
|
|
|
|
OPEN vCur;
|
|
|
|
|
OPEN vTravels;
|
|
|
|
|
|
|
|
|
|
l: LOOP
|
|
|
|
|
SET vDone = FALSE;
|
|
|
|
|
FETCH vCur INTO vTravelLink, vBuyerEmail;
|
|
|
|
|
FETCH vTravels INTO vTravelLink, vBuyerEmail;
|
|
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
|
LEAVE l;
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
CALL `vn`.`mail_insert`(
|
|
|
|
|
vBuyerEmail,
|
|
|
|
|
'noreply@verdnatura.es',
|
|
|
|
|
'Cambio de fecha en Redadas',
|
|
|
|
|
CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink));
|
|
|
|
|
SET vSubject = 'Cambio de fecha en Redadas',
|
|
|
|
|
vMailBody = CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink);
|
|
|
|
|
|
|
|
|
|
CALL mail_insert(vBuyerEmail, 'noreply@verdnatura.es', vSubject, vMailBody);
|
|
|
|
|
END LOOP;
|
|
|
|
|
CLOSE vCur;
|
|
|
|
|
CLOSE vTravels;
|
|
|
|
|
COMMIT;
|
|
|
|
|
DROP TEMPORARY TABLE tTravelToMove;
|
|
|
|
|
END$$
|
|
|
|
|