USE `bridge`;
DROP PROCEDURE IF EXISTS `sinkronisasiPenerimaanSka`;
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `sinkronisasiPenerimaanSka`()
BEGIN
	DECLARE VID VARCHAR(50);
	
	DECLARE DATA_NOT_FOUND TINYINT DEFAULT FALSE;
	DECLARE CR_PENERIMAAN_SKA_SINKRON CURSOR FOR
		SELECT ID FROM bridge.ska_penerimaan
			WHERE FLAG_KIRIM=1 AND `STATUS` IN (0,1,2,3) LIMIT 2;
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET DATA_NOT_FOUND = TRUE;
			
	OPEN CR_PENERIMAAN_SKA_SINKRON;
	EOF: LOOP
		FETCH CR_PENERIMAAN_SKA_SINKRON INTO VID;
		
		IF DATA_NOT_FOUND THEN
			UPDATE temp.temp SET ID = 0 WHERE ID = 0;
			LEAVE EOF;
		END IF;
		
		CALL bridge.sendBridgePenerimaanSka(VID);
		
	END LOOP;
	CLOSE CR_PENERIMAAN_SKA_SINKRON;
END//
DELIMITER ;