2021-12-17 11:38:56 +00:00
|
|
|
DROP PROCEDURE IF EXISTS `vn`.`ticket_getVisibleAvailable`;
|
|
|
|
|
|
|
|
DELIMITER $$
|
|
|
|
$$
|
2021-12-20 12:50:31 +00:00
|
|
|
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getVisibleAvailable`(`vTicket` INT, `vDate` DATE)
|
2021-12-17 11:38:56 +00:00
|
|
|
BEGIN
|
|
|
|
DECLARE vVisibleCalc INT;
|
|
|
|
DECLARE vAvailableCalc INT;
|
|
|
|
DECLARE vShipped DATE;
|
|
|
|
DECLARE vWarehouse TINYINT;
|
2021-12-20 12:50:31 +00:00
|
|
|
DECLARE vAlertLevel INT;
|
2021-12-17 11:38:56 +00:00
|
|
|
|
|
|
|
SELECT t.warehouseFk, t.shipped, ts.alertLevel
|
|
|
|
INTO vWarehouse, vShipped, vAlertLevel
|
|
|
|
FROM ticket t
|
|
|
|
LEFT JOIN ticketState ts ON ts.ticketFk = vTicket
|
|
|
|
WHERE t.id = vTicket;
|
|
|
|
|
|
|
|
IF vDate IS NULL THEN
|
|
|
|
SET vDate = vShipped;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF vAlertLevel IS NULL OR vAlertLevel = 0 THEN
|
|
|
|
IF vDate >= CURDATE() THEN
|
|
|
|
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vDate);
|
|
|
|
END IF;
|
|
|
|
IF vDate = CURDATE() THEN
|
|
|
|
CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse);
|
|
|
|
END IF;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT s.id,
|
|
|
|
s.itemFk,
|
|
|
|
s.quantity,
|
|
|
|
s.concept,
|
|
|
|
s.price,
|
|
|
|
s.reserved,
|
|
|
|
s.discount,
|
|
|
|
v.visible,
|
|
|
|
av.available,
|
|
|
|
it.image,
|
|
|
|
it.subName
|
|
|
|
FROM sale s
|
|
|
|
LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCalc
|
|
|
|
LEFT JOIN cache.available av ON av.item_id = s.itemFk AND av.calc_id = vAvailableCalc
|
|
|
|
LEFT JOIN item it ON it.id = s.itemFk
|
|
|
|
WHERE s.ticketFk = vTicket
|
|
|
|
ORDER BY s.concept;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|