29 lines
882 B
SQL
29 lines
882 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`XDiario_check`()
|
|
BEGIN
|
|
/**
|
|
* Realiza la revisión diaria de los asientos contables,
|
|
* identificando y notificando los asientos descuadrados
|
|
* y ajustando los saldos en caso necesario.
|
|
*/
|
|
|
|
UPDATE XDiario xd
|
|
JOIN (
|
|
SELECT xd.id, SUBCTA, recon
|
|
FROM XDiario xd
|
|
JOIN (
|
|
SELECT ASIEN,
|
|
SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon
|
|
FROM XDiario
|
|
WHERE NOT enlazado
|
|
GROUP BY ASIEN
|
|
HAVING recon
|
|
) sub ON sub.ASIEN = xd.ASIEN
|
|
WHERE xd.SUBCTA > '5999999999'
|
|
GROUP BY xd.ASIEN
|
|
) sub ON sub.id = xd.id
|
|
SET xd.Eurohaber = IF(IFNULL(xd.Eurohaber, 0) = 0, xd.Eurohaber, xd.Eurohaber + sub.recon),
|
|
xd.Eurodebe = IF(IFNULL(xd.Eurodebe, 0) = 0, xd.Eurodebe, xd.Eurodebe - sub.recon);
|
|
END$$
|
|
DELIMITER ;
|