DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`bankPolicy_notifyExpired`()
BEGIN
/**
*
* Manda correo cuando caduca un seguro
* de los leasing
*
*/ 
	INSERT INTO mail (receiver,replyTo,subject,body)
		SELECT 'administracion@verdnatura.es' receiver,
				'noreply@verdnatura.es' replyTo,
				CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') subject,
				CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') body
			FROM  vn.bankPolicy bp 
				LEFT JOIN vn.supplier s 
					ON s.id = bp.supplierFk
				LEFT JOIN vn.bank b
					ON b.id = bp.accountingFk
		    WHERE bp.insuranceExpired = util.VN_CURDATE();
END$$
DELIMITER ;
