DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`clean`()
BEGIN
	DECLARE vDateShort DATETIME;
	DECLARE vDateLong DATETIME;
	DECLARE vOneYearAgo DATETIME;

	SET vDateShort = TIMESTAMPADD(MONTH, -2, util.VN_CURDATE());
	SET vDateLong = TIMESTAMPADD(MONTH, -18,util.VN_CURDATE());
	SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,util.VN_CURDATE());

	DELETE FROM bi.Greuge_Evolution 
		WHERE (Fecha < vDateShort AND weekday(Fecha) != 1) 
			OR Fecha < vOneYearAgo;

	DELETE FROM bi.defaulters WHERE `date` < vDateLong;
	DELETE FROM bi.defaulting WHERE `date` < vDateLong;
END$$
DELIMITER ;
