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_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comprueba que los tickets entre un rango de fechas tienen componentes
|
|
|
|
* y recalcula sus componentes
|
|
|
|
*
|
|
|
|
* @param vShippedFrom rango inicial de fecha
|
|
|
|
* @param vShippedTo rango final de fecha
|
|
|
|
*/
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.coste
|
|
|
|
(primary key (id)) ENGINE = MEMORY
|
|
|
|
SELECT s.id
|
|
|
|
FROM ticket t
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
|
|
JOIN item i ON i.id = s.itemFk
|
|
|
|
JOIN itemType tp ON tp.id = i.typeFk
|
|
|
|
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
|
|
|
JOIN saleComponent sc ON sc.saleFk = s.id
|
|
|
|
JOIN component c ON c.id = sc.componentFk
|
2024-07-01 09:11:16 +00:00
|
|
|
JOIN componentType ct ON ct.id = c.typeFk
|
|
|
|
AND ct.code = 'cost'
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo
|
|
|
|
AND ic.merchandise;
|
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales
|
2024-01-15 11:31:03 +00:00
|
|
|
(primary key (id)) ENGINE = MEMORY
|
2024-01-25 16:33:54 +00:00
|
|
|
SELECT DISTINCT s.id
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM ticket t
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
|
|
JOIN item i ON i.id = s.itemFk
|
|
|
|
JOIN itemType tp ON tp.id = i.typeFk
|
|
|
|
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
|
|
|
LEFT JOIN tmp.coste c ON c.id = s.id
|
|
|
|
WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo
|
|
|
|
AND c.id IS NULL
|
|
|
|
AND ic.merchandise;
|
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
CALL sale_recalcComponent('renewPrices');
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.recalculateSales;
|
2024-01-15 11:31:03 +00:00
|
|
|
DROP TEMPORARY TABLE tmp.coste;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|