2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getAlert3StateTest`(vTicket INT)
|
|
|
|
RETURNS varchar(45) CHARSET latin1 COLLATE latin1_swedish_ci
|
|
|
|
NOT DETERMINISTIC
|
|
|
|
READS SQL DATA
|
|
|
|
BEGIN
|
|
|
|
DECLARE vDeliveryType INTEGER DEFAULT 0;
|
|
|
|
DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE;
|
|
|
|
DECLARE vCode VARCHAR(45);
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
a.Vista
|
|
|
|
INTO vDeliveryType
|
2024-02-05 12:52:28 +00:00
|
|
|
FROM ticket t
|
|
|
|
JOIN vn2008.Agencias a ON a.Id_Agencia = t.agencyModeFk
|
2024-04-22 08:48:37 +00:00
|
|
|
WHERE t.id = vTicket;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
CASE vDeliveryType
|
|
|
|
WHEN 1 THEN -- AGENCIAS
|
|
|
|
SET vCode = 'DELIVERED';
|
|
|
|
|
|
|
|
WHEN 2 THEN -- REPARTO
|
|
|
|
SET vCode = 'ON_DELIVERY';
|
|
|
|
|
|
|
|
ELSE -- MERCADO, OTROS
|
2024-02-05 12:52:28 +00:00
|
|
|
SELECT t.warehouseFk <> w.warehouse_id INTO isWaitingForPickUp
|
|
|
|
FROM ticket t
|
2024-01-15 11:31:03 +00:00
|
|
|
LEFT JOIN vn2008.warehouse_pickup w
|
2024-02-05 12:52:28 +00:00
|
|
|
ON w.agency_id = t.agencyModeFk AND w.warehouse_id = t.warehouseFk
|
|
|
|
WHERE t.id = vTicket;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
IF isWaitingForPickUp THEN
|
|
|
|
SET vCode = 'WAITING_FOR_PICKUP';
|
|
|
|
ELSE
|
|
|
|
SET vCode = 'DELIVERED';
|
|
|
|
END IF;
|
|
|
|
END CASE;
|
|
|
|
RETURN vCode;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|