DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`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 ',a.id,' ',a.bank,' ha finalizado.') subject, CONCAT('El seguro de la poliza ',a.id,' ',a.bank,' ha finalizado.') body FROM bankPolicy bp LEFT JOIN supplier s ON s.id = bp.supplierFk LEFT JOIN accounting a ON a.id = bp.accountingFk WHERE bp.insuranceExpired = util.VN_CURDATE(); END$$ DELIMITER ;