DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`emailYesterdayPurchasesByConsigna`(IN v_Date DATE, IN v_Client_Id INT) BEGIN DECLARE MyIdTicket BIGINT; DECLARE MyAlias VARCHAR(50); DECLARE MyDomicilio VARCHAR(255); DECLARE MyPoblacion VARCHAR(25); DECLARE MyImporte DOUBLE; DECLARE MyMailTo VARCHAR(250); DECLARE MyMailReplyTo VARCHAR(250); DECLARE done INT DEFAULT FALSE; DECLARE emptyList INT DEFAULT 0; DECLARE txt TEXT; DECLARE rs CURSOR FOR SELECT t.Id_Ticket, Alias, cast(amount as decimal(10,2)) Importe, Domicilio, POBLACION FROM Tickets t JOIN Consignatarios cs ON t.Id_Consigna = cs.Id_Consigna JOIN ( SELECT `Movimientos`.`Id_Ticket` AS `Id_Ticket`, sum( `Movimientos`.`Cantidad` * `Movimientos`.`Preu` * (100 - `Movimientos`.`Descuento`) / 100 ) AS `amount` FROM ( `vn2008`.`Movimientos` JOIN `vn2008`.`Tickets` ON( `Movimientos`.`Id_Ticket` = `Tickets`.`Id_Ticket` ) ) WHERE `Tickets`.`Fecha` >= `util`.`VN_CURDATE`() + INTERVAL -6 MONTH GROUP BY `Movimientos`.`Id_Ticket` ) v ON v.Id_Ticket = t.Id_Ticket WHERE t.Fecha BETWEEN v_Date AND util.dayEnd(v_Date) AND t.Id_Cliente = v_Client_Id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET v_Date = IFNULL(v_Date, util.yesterday()); OPEN rs; FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion; SET emptyList = done; SET txt = CONCAT('
',
' Relación de envíos.
',
'Dia: ', v_Date, '
');
WHILE NOT done DO
SET txt = CONCAT(txt, '
',
'
'
, ' ', MyAlias, '
Ticket ', MyIdTicket,'
', MyImporte, ' €
'
, ' ', MyDomicilio, '(', MyPoblacion, ')');
FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion;
END WHILE;
SET txt = CONCAT(
txt,
'',
'
',
' ',
'
Puede acceder al detalle de los albaranes haciendo click sobre el número de Ticket',
' Muchas gracias por su confianza
',
'