update structure DB

This commit is contained in:
Bernat 2018-07-03 11:43:05 +02:00
parent 371c24a9ad
commit 844fa3a682
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
USE `vn`;
DROP procedure IF EXISTS `ticketGetVisibleAvailable`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`% `PROCEDURE` ticketGetVisibleAvailable`(
vTicket INT)
BEGIN
DECLARE vVisibleCalc INT;
DECLARE vAvailableCalc INT;
DECLARE vShipped DATE;
DECLARE vWarehouse TINYINT;
DECLARE vAlertLevel INT;
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 vAlertLevel IS NULL OR vAlertLevel = 0 THEN
IF vShipped > CURDATE() THEN
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped);
END IF;
IF vShipped = CURDATE() THEN
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped);
CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse);
END IF;
END IF;
SELECT s.itemFk, s.quantity, s.price, s.discount, i.val1 ,i.val2, i.val3, i.val4, i.val5, i.val6,v.visible, av.available
FROM vn.sale s
JOIN vn.itemTagArranged i ON i.itemFk = s.itemFk
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
WHERE s.ticketFk = vTicket;
END$$
DELIMITER ;