2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-02-15 09:04:15 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getMovable`(
|
|
|
|
vTicketFk INT,
|
|
|
|
vNewShipped DATETIME,
|
|
|
|
vWarehouseFk INT
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Cálcula el stock movible para los artículos de un ticket
|
2024-02-15 09:04:15 +00:00
|
|
|
* vNewShipped debe ser menor que vOldShipped, en los otros casos se
|
2024-01-15 11:31:03 +00:00
|
|
|
* asume que siempre es posible
|
|
|
|
*
|
|
|
|
* @param vTicketFk -> Ticket
|
2024-02-15 09:04:15 +00:00
|
|
|
* @param vNewShipped -> Nueva fecha
|
2024-01-15 11:31:03 +00:00
|
|
|
* @return Sales con Movible
|
2024-02-15 09:04:15 +00:00
|
|
|
*/
|
|
|
|
DECLARE vOldShipped DATETIME;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
SELECT t.shipped INTO vOldShipped
|
|
|
|
FROM ticket t
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE t.id = vTicketFk;
|
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
-- Añadimos un dia más para calcular el stock hasta vNewShipped inclusive
|
|
|
|
CALL item_getStock(vWarehouseFk, DATE_ADD(vNewShipped, INTERVAL 1 DAY), NULL);
|
|
|
|
CALL item_getMinacum(
|
|
|
|
vWarehouseFk,
|
|
|
|
vNewShipped,
|
|
|
|
DATEDIFF(DATE_SUB(vOldShipped, INTERVAL 1 DAY), vNewShipped),
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
SELECT s.id,
|
|
|
|
s.itemFk,
|
|
|
|
s.quantity,
|
|
|
|
s.concept,
|
|
|
|
s.price,
|
2024-01-15 11:31:03 +00:00
|
|
|
s.reserved,
|
2024-02-15 09:04:15 +00:00
|
|
|
s.discount,
|
|
|
|
i.image,
|
|
|
|
i.subName,
|
2024-01-15 11:31:03 +00:00
|
|
|
il.stock + IFNULL(im.amount, 0) AS movable
|
|
|
|
FROM ticket t
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
2024-02-15 09:04:15 +00:00
|
|
|
JOIN item i ON i.id = s.itemFk
|
|
|
|
LEFT JOIN tmp.itemMinacum im ON im.itemFk = s.itemFk
|
|
|
|
AND im.warehouseFk = vWarehouseFk
|
2024-01-15 11:31:03 +00:00
|
|
|
LEFT JOIN tmp.itemList il ON il.itemFk = s.itemFk
|
|
|
|
WHERE t.id = vTicketFk;
|
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS
|
|
|
|
tmp.itemList,
|
|
|
|
tmp.itemMinacum;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|