refactor: refs #6495 Migrated procs to vn #2108
|
@ -1,100 +0,0 @@
|
|||
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('<p><font face="verdana" >',
|
||||
'<h2> Relación de envíos.</h2>',
|
||||
'<h3><font color="green">Dia: ', v_Date, '</font></h3>');
|
||||
|
||||
WHILE NOT done DO
|
||||
|
||||
SET txt = CONCAT(txt, '<br><br>',
|
||||
'<table>
|
||||
<tr>
|
||||
<th> <a href = "https://shop.verdnatura.es/#!form=ecomerce/ticket&ticket=',MyIdTicket,'">
|
||||
<font color="green"> Ticket ', MyIdTicket,'</font></th>
|
||||
<th></th><th></th><th></th><th></th>
|
||||
<th></th><th></th><th></th><th></th>
|
||||
<th> <font color="orange"> ', MyImporte, ' € </a></font></th>
|
||||
</tr>
|
||||
</table>'
|
||||
, ' ', MyAlias, '<br>'
|
||||
, ' ', MyDomicilio, '(', MyPoblacion, ')');
|
||||
|
||||
FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion;
|
||||
|
||||
END WHILE;
|
||||
|
||||
SET txt = CONCAT(
|
||||
txt,
|
||||
'<table>',
|
||||
'<tr><th></th></tr>',
|
||||
'</table>',
|
||||
'<br><br>Puede acceder al detalle de los albaranes haciendo click sobre el número de Ticket',
|
||||
'<br><h3> Muchas gracias por su confianza</h3>',
|
||||
'</font></p>');
|
||||
|
||||
-- Envío del email
|
||||
IF emptyList = 0 THEN
|
||||
|
||||
SELECT CONCAT(`e-mail`,',pako@verdnatura.es') INTO MyMailTo
|
||||
FROM Clientes
|
||||
WHERE Id_Cliente = v_Client_Id AND `e-mail`>'';
|
||||
|
||||
IF v_Client_Id = 7818 THEN -- LOEWE
|
||||
SET MyMailTo = 'isabel@elisabethblumen.com,emunozca@loewe.es,pako@verdnatura.es';
|
||||
END IF;
|
||||
|
||||
CALL vn.mail_insert(
|
||||
IFNULL(MyMailTo,'pako.natek@gmail.com'),
|
||||
'pako@verdnatura.es',
|
||||
'Resumen de pedidos preparados',
|
||||
txt
|
||||
);
|
||||
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,27 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`emailYesterdayPurchasesLauncher`()
|
||||
BEGIN
|
||||
|
||||
DECLARE done INT DEFAULT 0;
|
||||
DECLARE vMyClientId INT;
|
||||
|
||||
DECLARE rs CURSOR FOR
|
||||
SELECT Id_Cliente
|
||||
FROM Clientes
|
||||
WHERE EYPBC != 0;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
|
||||
|
||||
OPEN rs;
|
||||
|
||||
FETCH rs INTO vMyClientId;
|
||||
|
||||
WHILE NOT done DO
|
||||
|
||||
CALL emailYesterdayPurchasesByConsigna(util.yesterday(), vMyClientId);
|
||||
|
||||
FETCH rs INTO vMyClientId;
|
||||
|
||||
END WHILE;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,51 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`embalajes_stocks`(IN idPEOPLE INT, IN bolCLIENT BOOLEAN)
|
||||
BEGIN
|
||||
|
||||
if bolCLIENT then
|
||||
|
||||
select m.Id_Article, Article, - cast(sum(m.Cantidad) as decimal) as Saldo
|
||||
from Movimientos m
|
||||
join Articles a on m.Id_Article = a.Id_Article
|
||||
join Tipos tp on tp.tipo_id = a.tipo_id
|
||||
join Tickets t using(Id_Ticket)
|
||||
join Consignatarios cs using(Id_Consigna)
|
||||
where cs.Id_Cliente = idPEOPLE
|
||||
and Tipo = 'Contenedores'
|
||||
and t.Fecha > '2010-01-01'
|
||||
group by m.Id_Article;
|
||||
|
||||
else
|
||||
|
||||
select Id_Article, Article, sum(Cantidad) as Saldo
|
||||
from
|
||||
(select Id_Article, Cantidad
|
||||
from Compres c
|
||||
join Articles a using(Id_Article)
|
||||
join Tipos tp using(tipo_id)
|
||||
join Entradas e using(Id_Entrada)
|
||||
join travel tr on tr.id = travel_id
|
||||
where Id_Proveedor = idPEOPLE
|
||||
and landing >= '2010-01-01'
|
||||
and reino_id = 6
|
||||
|
||||
union all
|
||||
|
||||
select Id_Article, - Cantidad
|
||||
from Movimientos m
|
||||
join Articles a using(Id_Article)
|
||||
join Tipos tp using(tipo_id)
|
||||
join Tickets t using(Id_Ticket)
|
||||
join Consignatarios cs using(Id_Consigna)
|
||||
join proveedores_clientes pc on pc.Id_Cliente = cs.Id_Cliente
|
||||
where Id_Proveedor = idPEOPLE
|
||||
and reino_id = 6
|
||||
and t.Fecha > '2010-01-01') mov
|
||||
|
||||
join Articles a using(Id_Article)
|
||||
group by Id_Article;
|
||||
|
||||
end if;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,78 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`embalajes_stocks_detalle`(IN idPEOPLE INT, IN idARTICLE INT, IN bolCLIENT BOOLEAN)
|
||||
BEGIN
|
||||
|
||||
|
||||
if bolCLIENT then
|
||||
|
||||
select m.Id_Article
|
||||
, Article
|
||||
, IF(Cantidad < 0, - Cantidad, NULL) as Entrada
|
||||
, IF(Cantidad < 0, NULL, Cantidad) as Salida
|
||||
, 'T' as Tabla
|
||||
, t.Id_Ticket as Registro
|
||||
, t.Fecha
|
||||
, w.name as Almacen
|
||||
, cast(Preu as Decimal(5,2)) Precio
|
||||
, c.Cliente as Proveedor
|
||||
, abbreviation as Empresa
|
||||
from Movimientos m
|
||||
join Articles a using(Id_Article)
|
||||
join Tickets t using(Id_Ticket)
|
||||
join empresa e on e.id = t.empresa_id
|
||||
join warehouse w on w.id = t.warehouse_id
|
||||
join Consignatarios cs using(Id_Consigna)
|
||||
join Clientes c on c.Id_Cliente = cs.Id_Cliente
|
||||
where cs.Id_Cliente = idPEOPLE
|
||||
and m.Id_Article = idARTICLE
|
||||
and t.Fecha > '2010-01-01';
|
||||
|
||||
else
|
||||
|
||||
select Id_Article, Tabla, Registro, Fecha, Article
|
||||
, w.name as Almacen, Entrada, Salida, Proveedor, cast(Precio as Decimal(5,2)) Precio
|
||||
|
||||
from
|
||||
|
||||
(select Id_Article
|
||||
, IF(Cantidad > 0, Cantidad, NULL) as Entrada
|
||||
, IF(Cantidad > 0, NULL,- Cantidad) as Salida
|
||||
, 'E' as Tabla
|
||||
, Id_Entrada as Registro
|
||||
, landing as Fecha
|
||||
, tr.warehouse_id
|
||||
, Costefijo as Precio
|
||||
from Compres c
|
||||
join Entradas e using(Id_Entrada)
|
||||
join travel tr on tr.id = travel_id
|
||||
where Id_Proveedor = idPEOPLE
|
||||
and Id_Article = idARTICLE
|
||||
and landing >= '2010-01-01'
|
||||
|
||||
union all
|
||||
|
||||
select Id_Article
|
||||
, IF(Cantidad < 0, - Cantidad, NULL) as Entrada
|
||||
, IF(Cantidad < 0, NULL, Cantidad) as Salida
|
||||
, 'T'
|
||||
, Id_Ticket
|
||||
, Fecha
|
||||
, t.warehouse_id
|
||||
, Preu
|
||||
from Movimientos m
|
||||
join Tickets t using(Id_Ticket)
|
||||
join Consignatarios cs using(Id_Consigna)
|
||||
join proveedores_clientes pc on pc.Id_Cliente = cs.Id_Cliente
|
||||
where Id_Proveedor = idPEOPLE
|
||||
and Id_Article = idARTICLE
|
||||
and t.Fecha > '2010-01-01') mov
|
||||
|
||||
join Articles a using(Id_Article)
|
||||
join Proveedores p on Id_Proveedor = idPEOPLE
|
||||
join warehouse w on w.id = mov.warehouse_id
|
||||
;
|
||||
|
||||
end if;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,2 @@
|
|||
DELETE FROM bs.nightTask
|
||||
WHERE `procedure` = 'emailYesterdayPurchasesLauncher';
|
Loading…
Reference in New Issue