salix/db/routines/edi/procedures/ekt_refresh.sql

43 lines
851 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_refresh`(
`vSelf` INT, vMailFk INT)
BEGIN
/**
* Updates a transaction, generates it's barcode.
*/
DECLARE vRewriteKop INT DEFAULT NULL;
DECLARE vTruncatePutOrder INT DEFAULT NULL;
DECLARE vKop INT;
DECLARE vPutOrderFk BIGINT;
SELECT kop, putOrderFk
INTO vKop, vPutOrderFk
FROM ekt
WHERE id = vSelf;
-- Rewrites the kop parameter
IF vKop IS NULL THEN
SELECT defaultKop INTO vKop FROM exchangeConfig;
END IF;
SELECT e.kop INTO vRewriteKop
FROM mailSender e
JOIN mail m ON m.senderFk = e.id
WHERE m.id = vMailFk;
SET vKop = IFNULL(vRewriteKop, vKop);
-- Format order id
SET vTruncatePutOrder = vPutOrderFk MOD 1000000;
-- Refresh EKT
2024-07-02 12:37:22 +00:00
UPDATE ekt
SET kop = vKop,
putOrderFk = vTruncatePutOrder
WHERE id = vSelf;
END$$
DELIMITER ;