salix/db/routines/vn/functions/ticketSplitCounter.sql

22 lines
624 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketSplitCounter`(vTicketFk INT)
RETURNS varchar(15) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
NOT DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE vSplitCounter VARCHAR(15);
SELECT CONCAT(printedStickers,'/',Total, IF(printedStickers = Total ,' LS','')) INTO vSplitCounter
FROM
(
SELECT count(l.Id_Movimiento) as printedStickers, COUNT(*) as Total
FROM vn.sale s
LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id
WHERE ticketFk = vTicketFk
) sub;
RETURN IFNULL(vSplitCounter,'--');
END$$
DELIMITER ;