2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`XDiario_Quadrator`()
|
|
|
|
BEGIN
|
|
|
|
INSERT INTO vn.mail (receiver, subject, body)
|
|
|
|
SELECT 'cau@verdnatura.es',
|
|
|
|
'asientos descuadrados',
|
|
|
|
group_concat(CONCAT(' Asiento: ', ASIEN, '- importe:', quadre) SEPARATOR ' \r\n ')
|
|
|
|
FROM (
|
|
|
|
SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) quadre
|
2024-02-01 08:49:44 +00:00
|
|
|
FROM vn.XDiario
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE enlazado = FALSE
|
|
|
|
GROUP BY ASIEN
|
|
|
|
HAVING ABS(SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0))) > 0.01
|
|
|
|
) t
|
|
|
|
HAVING count(*) > 0;
|
|
|
|
|
2024-02-01 08:49:44 +00:00
|
|
|
UPDATE vn.XDiario XD
|
2024-01-15 11:31:03 +00:00
|
|
|
INNER JOIN(
|
2024-02-01 08:49:44 +00:00
|
|
|
SELECT XD.id, SUBCTA, Quadre FROM vn.XDiario XD
|
2024-01-15 11:31:03 +00:00
|
|
|
INNER JOIN (
|
|
|
|
SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) as Quadre
|
2024-02-01 08:49:44 +00:00
|
|
|
FROM vn.XDiario
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE enlazado = FALSE
|
|
|
|
GROUP BY ASIEN
|
|
|
|
HAVING Quadre != 0
|
|
|
|
) sub USING(ASIEN)
|
|
|
|
WHERE SUBCTA > '5999999999'
|
|
|
|
GROUP BY ASIEN
|
|
|
|
) sub2 USING(id)
|
|
|
|
SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre),
|
|
|
|
Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre);
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|