DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_confirmAll`(vDate DATE)
BEGIN
/**
 * Confirma todas las transacciones confirmadas por el cliente pero no
 * por el banco para una fecha dada.
 *
 * @param vDate Fecha deseada
 */
	DECLARE vOrder INT;
	DECLARE vDone BOOLEAN DEFAULT FALSE;
	DECLARE vDateIni DATETIME DEFAULT TIMESTAMP(vDate, '00:00:00');
	DECLARE vDateEnd DATETIME DEFAULT TIMESTAMP(vDate, '23:59:59');

	DECLARE cTransactions CURSOR FOR
	SELECT id
		FROM tpvTransaction
			WHERE created BETWEEN vDateIni AND vDateEnd
			AND status = 'ok'
			AND response IS NULL;

	DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;

	OPEN cTransactions;

	l: LOOP
		FETCH cTransactions INTO vOrder;

		IF vDone THEN
			LEAVE l;
		END IF;

		CALL tpvTransaction_confirmById (vOrder);
	END LOOP l;

	CLOSE cTransactions;
END$$
DELIMITER ;
