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

36 lines
923 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`recipe_Plaster`(vItemFk INT, vTicketFk INT, vQuantity INT)
BEGIN
DECLARE vLastCost DECIMAL(10,2);
2024-01-25 16:33:54 +00:00
DECLARE vWarehouseFk INT;
DECLARE vShipped DATE;
DECLARE vEntryFk INT;
DECLARE vTravelFk INT;
CALL cache.last_buy_refresh(FALSE);
SELECT warehouseFk, shipped
INTO vWarehouseFk, vShipped
FROM vn.ticket
2024-01-25 16:33:54 +00:00
WHERE id = vTicketFk;
UPDATE vn.ticket t
JOIN vn.item i ON i.id = vItemFk
2024-01-25 16:33:54 +00:00
SET t.nickname = CONCAT(vQuantity,' ',i.longName)
WHERE t.id = vTicketFk;
2024-01-25 16:33:54 +00:00
SELECT b.buyingValue INTO vLastCost
FROM vn.buy b
JOIN cache.last_buy lb ON lb.buy_id = b.id
WHERE lb.item_id = vItemFk
2024-01-25 16:33:54 +00:00
ORDER BY (lb.warehouse_id = vWarehouseFk) DESC
LIMIT 1;
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price)
SELECT vTicketFk, 98, - vQuantity, i.longName, vLastCost
FROM vn.item i
2024-01-25 16:33:54 +00:00
WHERE i.id = vItemFk;
END$$
DELIMITER ;