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`.`ticket_split`(
|
2024-06-25 17:47:22 +00:00
|
|
|
vTicketFk INT,
|
|
|
|
vTicketFutureFk INT,
|
|
|
|
vDated DATE
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
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;
|
|
|
|
|
2024-06-25 17:47:22 +00:00
|
|
|
SELECT COUNT(*) INTO vTotalLines
|
2024-06-25 17:33:54 +00:00
|
|
|
FROM sale s
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE s.ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
SET vHasFullProblem = (vTotalLines = vProblemLines);
|
|
|
|
|
|
|
|
-- Ticket completo
|
|
|
|
IF vHasFullProblem THEN
|
2024-06-25 17:33:54 +00:00
|
|
|
UPDATE ticket
|
2024-06-25 17:47:22 +00:00
|
|
|
SET landed = vDated + INTERVAL 1 DAY,
|
2024-01-15 11:31:03 +00:00
|
|
|
shipped = vDated,
|
2024-06-25 17:47:22 +00:00
|
|
|
nickname = CONCAT('(',DAY(util.VN_CURDATE()),') ', nickname)
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE id = vTicketFk;
|
|
|
|
|
2024-06-25 17:47:22 +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
|
2024-06-25 17:33:54 +00:00
|
|
|
UPDATE sale s
|
2024-06-25 17:47:22 +00:00
|
|
|
JOIN tmp.salesToSplit ss ON s.id = ss.saleFk
|
2024-01-15 11:31:03 +00:00
|
|
|
SET s.ticketFk = vTicketFutureFk,
|
|
|
|
s.concept = CONCAT('(s) ', s.concept)
|
|
|
|
WHERE ss.ticketFk = vTicketFk;
|
|
|
|
|
2024-06-25 17:47:22 +00:00
|
|
|
SELECT 'future' message, NULL ticketFuture;
|
2024-01-15 11:31:03 +00:00
|
|
|
LEAVE proc;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- Ticket nuevo
|
2024-06-25 17:33:54 +00:00
|
|
|
CALL ticket_Clone(vTicketFk, vTicketFutureFk);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-06-25 17:33:54 +00:00
|
|
|
UPDATE ticket t
|
2024-06-25 17:47:22 +00:00
|
|
|
JOIN productionConfig pc
|
2024-01-15 11:31:03 +00:00
|
|
|
SET t.routeFk = IF(t.shipped = vDated , t.routeFk, NULL),
|
2024-06-25 17:47:22 +00:00
|
|
|
t.landed = vDated + INTERVAL 1 DAY,
|
2024-01-15 11:31:03 +00:00
|
|
|
t.shipped = vDated,
|
|
|
|
t.agencyModeFk = pc.defautlAgencyMode,
|
|
|
|
t.zoneFk = pc.defaultZone
|
|
|
|
WHERE t.id = vTicketFutureFk;
|
2024-06-25 17:47:22 +00:00
|
|
|
|
2024-06-25 17:33:54 +00:00
|
|
|
UPDATE sale s
|
2024-06-25 17:47:22 +00:00
|
|
|
JOIN tmp.salesToSplit sts ON sts.saleFk = s.id
|
2024-01-15 11:31:03 +00:00
|
|
|
SET s.ticketFk = vTicketFutureFk,
|
|
|
|
s.concept = CONCAT('(s) ', s.concept)
|
|
|
|
WHERE sts.ticketFk = vTicketFk;
|
|
|
|
|
2024-06-25 17:30:59 +00:00
|
|
|
CALL ticket_setState(vTicketFutureFk, 'FIXING');
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-06-25 17:47:22 +00:00
|
|
|
SELECT 'new' message, vTicketFutureFk ticketFuture;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|