salix/db/routines/vn/procedures/ticketCalculateClon.sql

38 lines
1.1 KiB
MySQL
Raw Normal View History

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;
-- 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
FROM sale
WHERE ticketFk = vTicketNew AND price = 0;
2024-01-25 16:33:54 +00:00
CALL sale_recalcComponent('renewPrices');
-- 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
2024-05-09 10:54:57 +00:00
CALL sale_recalcComponent('buyerDiscount');
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
2024-01-25 16:33:54 +00:00
END$$
DELIMITER ;