2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_split`(vTicketFk INT, vTicketFutureFk INT, vDated DATE)
|
|
|
|
proc:BEGIN
|
|
|
|
/**
|
|
|
|
* Mueve las lineas con problemas a otro ticket existente o a uno nuevo.
|
|
|
|
*
|
|
|
|
* @param vTicketFk Identificador del ticket a splittar
|
|
|
|
* @param vTicketFutureFk Identificador del ticket al que se quieren mover las lineas
|
|
|
|
* @param vDate Fecha a la que se va a mover
|
|
|
|
* @table tmp.salesToSplit(saleFk, ticketFk, problem)
|
|
|
|
*/
|
|
|
|
DECLARE vHasFullProblem BOOL;
|
|
|
|
DECLARE vProblemLines INT;
|
|
|
|
DECLARE vTotalLines INT;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vProblemLines
|
|
|
|
FROM tmp.salesToSplit
|
|
|
|
WHERE ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
SELECT count(*) INTO vTotalLines
|
|
|
|
FROM vn.sale s
|
|
|
|
WHERE s.ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
SET vHasFullProblem = (vTotalLines = vProblemLines);
|
|
|
|
|
|
|
|
-- Ticket completo
|
|
|
|
IF vHasFullProblem THEN
|
|
|
|
|
|
|
|
UPDATE vn.ticket
|
|
|
|
SET landed = vDated + INTERVAL 1 DAY,
|
|
|
|
shipped = vDated,
|
|
|
|
nickname = CONCAT('(',DAY(util.VN_CURDATE()),') ', nickname )
|
|
|
|
WHERE id = vTicketFk;
|
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
SELECT "moved" message, NULL ticketFuture;
|
2024-01-15 11:31:03 +00:00
|
|
|
LEAVE proc;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- Ticket a futuro existe
|
|
|
|
IF vTicketFutureFk THEN
|
|
|
|
|
|
|
|
UPDATE vn.sale s
|
|
|
|
JOIN tmp.salesToSplit ss ON s.id = ss.saleFk
|
|
|
|
SET s.ticketFk = vTicketFutureFk,
|
|
|
|
s.concept = CONCAT('(s) ', s.concept)
|
|
|
|
WHERE ss.ticketFk = vTicketFk;
|
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
SELECT "future" message, NULL ticketFuture;
|
2024-01-15 11:31:03 +00:00
|
|
|
LEAVE proc;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- Ticket nuevo
|
|
|
|
CALL vn.ticket_Clone(vTicketFk, vTicketFutureFk);
|
|
|
|
|
|
|
|
UPDATE vn.ticket t
|
|
|
|
JOIN vn.productionConfig pc
|
|
|
|
SET t.routeFk = IF(t.shipped = vDated , t.routeFk, NULL),
|
|
|
|
t.landed = vDated + INTERVAL 1 DAY,
|
|
|
|
t.shipped = vDated,
|
|
|
|
t.agencyModeFk = pc.defautlAgencyMode,
|
|
|
|
t.zoneFk = pc.defaultZone
|
|
|
|
WHERE t.id = vTicketFutureFk;
|
|
|
|
|
|
|
|
UPDATE vn.sale s
|
|
|
|
JOIN tmp.salesToSplit sts ON sts.saleFk = s.id
|
|
|
|
SET s.ticketFk = vTicketFutureFk,
|
|
|
|
s.concept = CONCAT('(s) ', s.concept)
|
|
|
|
WHERE sts.ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
CALL vn.ticketStateUpdate(vTicketFutureFk, 'FIXING');
|
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
SELECT "new" message,vTicketFutureFk ticketFuture;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|