2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT)
|
|
|
|
BEGIN
|
|
|
|
/*
|
|
|
|
* Recalcula los componentes un ticket clonado,
|
|
|
|
* las lineas a precio cero fuerza para que tengan precio, el resto lo respeta
|
|
|
|
* @param vTicketNew nuevo ticket clonado
|
|
|
|
* @param vTicketOld icket original, a partir del qual se clonara el nuevo
|
|
|
|
*/
|
|
|
|
|
|
|
|
REPLACE INTO orderTicket(orderFk,ticketFk)
|
|
|
|
SELECT orderFk, vTicketNew
|
|
|
|
FROM orderTicket
|
2024-01-25 16:33:54 +00:00
|
|
|
WHERE ticketFk = vTicketOld;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
-- Bionizamos lineas con Preu = 0
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales
|
|
|
|
(PRIMARY KEY (id)) ENGINE = MEMORY
|
2024-01-25 16:33:54 +00:00
|
|
|
SELECT id
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM sale
|
|
|
|
WHERE ticketFk = vTicketNew AND price = 0;
|
2024-01-25 16:33:54 +00:00
|
|
|
|
|
|
|
CALL sale_recalcComponent('renewPrices');
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
-- Bionizamos lineas con Preu > 0
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales
|
|
|
|
(PRIMARY KEY (id)) ENGINE = MEMORY
|
|
|
|
SELECT id
|
|
|
|
FROM sale
|
|
|
|
WHERE ticketFk = vTicketNew AND price > 0;
|
2024-01-25 16:33:54 +00:00
|
|
|
|
|
|
|
CALL sale_recalcComponent('imbalance');
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
2024-01-25 16:33:54 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|