44 lines
1.0 KiB
SQL
44 lines
1.0 KiB
SQL
DROP PROCEDURE IF EXISTS `vn`.`tpvTransaction_checkStatus`;
|
|
DELIMITER $$
|
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`tpvTransaction_checkStatus`()
|
|
BEGIN
|
|
/**
|
|
* Envia notificaiones de los cobros web
|
|
* que no se han trasladado a la ficha del cliente
|
|
*/
|
|
DECLARE vAmount DECIMAL (10,2);
|
|
DECLARE vClientFk INT;
|
|
DECLARE vCreated DATE;
|
|
DECLARE vDone INT DEFAULT FALSE;
|
|
DECLARE vCursor CURSOR FOR
|
|
SELECT t.amount / 100 amount, t.clientFk, t.created
|
|
FROM hedera.tpvTransaction t
|
|
WHERE t.receiptFk IS NULL
|
|
AND t.status = 'ok'
|
|
AND t.created < (NOW() - INTERVAL 2 DAY)
|
|
GROUP BY t.clientFk;
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
|
|
|
OPEN vCursor;
|
|
read_loop: LOOP
|
|
|
|
FETCH vCursor INTO vAmount, vClientFk, vCreated;
|
|
|
|
IF vDone THEN
|
|
LEAVE read_loop;
|
|
END IF;
|
|
|
|
SET vParams = JSON_OBJECT(
|
|
'amount', vAmount,
|
|
'clientFk', vClientFk,
|
|
'created', vCreated
|
|
);
|
|
|
|
SELECT util.notification_send('client-web-payment-confirm-lost', vParams, NULL) INTO @id;
|
|
|
|
END LOOP;
|
|
CLOSE vCursor;
|
|
END$$
|
|
DELIMITER ;
|