2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
INTO vWarehouseFk, vShipped
|
|
|
|
FROM vn.ticket
|
2024-01-25 16:33:54 +00:00
|
|
|
WHERE id = vTicketFk;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
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)
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE t.id = vTicketFk;
|
2024-01-25 16:33:54 +00:00
|
|
|
|
2024-01-15 11:31:03 +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;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
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;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|