salix/db/changes/10320-monitors/00-ticket_getProblems.sql

37 lines
1.1 KiB
MySQL
Raw Normal View History

DROP PROCEDURE IF EXISTS `vn`.`ticket_getProblems`;
DELIMITER $$
$$
CREATE
2021-05-25 08:01:18 +00:00
DEFINER = root@`%` PROCEDURE `vn`.`ticket_getProblems`(IN vIsTodayRelative TINYINT(1))
BEGIN
2021-05-26 11:05:58 +00:00
/**
* Calcula los problemas para un conjunto de tickets.
* Agrupados por ticket
*
* @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular
* @return tmp.ticket_problems
*/
2021-05-25 08:01:18 +00:00
CALL sale_getProblems(vIsTodayRelative);
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_problems;
2021-05-25 08:01:18 +00:00
CREATE TEMPORARY TABLE tmp.ticket_problems
(INDEX (ticketFk))
ENGINE = MEMORY
SELECT
ticketFk,
MAX(p.isFreezed) AS isFreezed,
MAX(p.risk) AS risk,
MAX(p.hasTicketRequest) AS hasTicketRequest,
MIN(p.isAvailable) AS isAvailable,
MAX(p.itemShortage) AS itemShortage,
MIN(p.isTaxDataChecked) AS isTaxDataChecked,
MAX(p.hasComponentLack) AS hasComponentLack
FROM tmp.sale_problems p
GROUP BY ticketFk;
DROP TEMPORARY TABLE
2021-05-25 08:01:18 +00:00
tmp.sale_problems;
END;;$$
DELIMITER ;