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

36 lines
1.0 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`copyComponentsFromSaleList`(vTargetTicketFk INT)
BEGIN
/* Copy sales and components to the target ticket
*
* ¡¡¡¡ Requires tmp.saleList(saleFk, itemFk, quantity, concept, price, discount, orden) !!!!!
*
* param VTargetTicketFk id del ticket a rellenar
*/
INSERT INTO vn.sale(ticketFk, itemFk, quantity,concept,price,discount)
SELECT vTargetTicketFk, itemFk, quantity,concept,price,discount
FROM tmp.saleList
ORDER BY orden;
SET @order = 0;
2024-06-19 09:30:50 +00:00
DROP TEMPORARY TABLE IF EXISTS tNewSaleList;
2024-06-19 09:30:50 +00:00
CREATE TEMPORARY TABLE tNewSaleList
SELECT id as saleFk, @order := @order + 1 as orden
FROM vn.sale
WHERE ticketFk = vTargetTicketFk
ORDER BY saleFk;
INSERT INTO vn.saleComponent(saleFk,componentFk,value)
SELECT ns.saleFk, sc.componentFk, sc.value
FROM vn.saleComponent sc
JOIN tmp.saleList s ON s.saleFk = sc.saleFk
2024-06-19 09:30:50 +00:00
JOIN tNewSaleList ns ON ns.orden = s.orden;
2024-06-24 06:03:43 +00:00
DROP TEMPORARY TABLE tNewSaleList;
END$$
DELIMITER ;