2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_get`(vParamFk INT)
|
2024-04-11 10:16:00 +00:00
|
|
|
RETURNS INT(11)
|
2024-01-15 11:31:03 +00:00
|
|
|
NOT DETERMINISTIC
|
|
|
|
READS SQL DATA
|
2024-04-11 10:16:00 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Devuelve el número de ticket / collection / sectorCollection consultando
|
|
|
|
* en que tabla se encuantra en la última semana
|
|
|
|
*
|
|
|
|
* @param vParamFk Número a validar
|
|
|
|
* @return vReturn Identificador validado
|
|
|
|
*/
|
|
|
|
DECLARE vReturn INT DEFAULT NULL;
|
|
|
|
DECLARE vDated DATE;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-04-11 10:16:00 +00:00
|
|
|
SET vDated = util.VN_CURDATE() - INTERVAL 1 WEEK;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-04-11 10:16:00 +00:00
|
|
|
SELECT COALESCE(
|
|
|
|
(SELECT s.ticketFk
|
|
|
|
FROM sale s
|
|
|
|
JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
|
|
|
JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
|
|
|
WHERE sg.id = vParamFk
|
|
|
|
AND sg.created > vDated
|
|
|
|
LIMIT 1),
|
|
|
|
(SELECT c.id
|
|
|
|
FROM collection c
|
|
|
|
WHERE c.id = vParamFk
|
|
|
|
AND c.created > vDated),
|
|
|
|
(SELECT id
|
|
|
|
FROM ticket
|
|
|
|
WHERE id = vParamFk
|
|
|
|
AND shipped > vDated),
|
|
|
|
(SELECT id
|
|
|
|
FROM sectorCollection
|
|
|
|
WHERE id = vParamFk
|
|
|
|
AND created > vDated)
|
|
|
|
) INTO vReturn;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-04-11 10:16:00 +00:00
|
|
|
RETURN vReturn;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|