37 lines
1.1 KiB
SQL
37 lines
1.1 KiB
SQL
DROP PROCEDURE IF EXISTS `vn`.`ticket_getProblems`;
|
|
|
|
DELIMITER $$
|
|
$$
|
|
CREATE
|
|
DEFINER = root@`%` PROCEDURE `vn`.`ticket_getProblems`(IN vIsTodayRelative TINYINT(1))
|
|
BEGIN
|
|
/**
|
|
* 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
|
|
*/
|
|
CALL sale_getProblems(vIsTodayRelative);
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_problems;
|
|
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
|
|
tmp.sale_problems;
|
|
END;;$$
|
|
DELIMITER ;
|