2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketGetVisibleAvailable`(
|
|
|
|
vTicket INT)
|
|
|
|
BEGIN
|
|
|
|
DECLARE vVisibleCalc INT;
|
|
|
|
DECLARE vAvailableCalc INT;
|
|
|
|
DECLARE vShipped DATE;
|
|
|
|
DECLARE vWarehouse TINYINT;
|
|
|
|
DECLARE vAlertLevel INT;
|
2024-06-05 06:05:46 +00:00
|
|
|
DECLARE vAlertLevelFree INT;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-06-05 06:05:46 +00:00
|
|
|
SELECT t.warehouseFk, t.shipped, ts.alertLevel, al.id
|
|
|
|
INTO vWarehouse, vShipped, vAlertLevel, vAlertLevelFree
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM ticket t
|
2024-06-05 06:05:46 +00:00
|
|
|
JOIN alertLevel al ON al.code = 'FREE'
|
2024-01-15 11:31:03 +00:00
|
|
|
LEFT JOIN ticketState ts ON ts.ticketFk = vTicket
|
|
|
|
WHERE t.id = vTicket;
|
|
|
|
|
2024-06-05 06:05:46 +00:00
|
|
|
IF vAlertLevel IS NULL OR vAlertLevel = vAlertLevelFree THEN
|
2024-01-15 11:31:03 +00:00
|
|
|
IF vShipped >= util.VN_CURDATE() THEN
|
|
|
|
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped);
|
|
|
|
END IF;
|
|
|
|
IF vShipped = util.VN_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 ;
|