2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`greuge_add`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Group inserts into vn.greuge and then deletes the records just inserted
|
|
|
|
*/
|
|
|
|
DECLARE vDated DATE;
|
|
|
|
|
|
|
|
SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL yearsToDelete YEAR) INTO vDated
|
|
|
|
FROM vn.greugeConfig;
|
|
|
|
|
|
|
|
INSERT INTO vn.greuge(clientFk, description, amount, shipped, created, greugeTypeFk)
|
|
|
|
SELECT clientFk, 'Suma agrupada', SUM(amount), MAX(shipped), MAX(created), greugeTypeFk
|
|
|
|
FROM vn.greuge
|
|
|
|
WHERE shipped <= vDated AND description <> 'Suma agrupada'
|
|
|
|
GROUP BY clientFk, greugeTypeFk;
|
|
|
|
|
|
|
|
DELETE
|
|
|
|
FROM vn.greuge
|
|
|
|
WHERE shipped <= vDated AND description <> 'Suma agrupada';
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|