2024-01-15 11:31:03 +00:00
|
|
|
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-01-15 11:31:03 +00:00
|
|
|
|
2024-06-19 09:30:50 +00:00
|
|
|
CREATE TEMPORARY TABLE tNewSaleList
|
2024-01-15 11:31:03 +00:00
|
|
|
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-01-15 11:31:03 +00:00
|
|
|
|
2024-06-19 09:30:50 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tNewSaleList;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|