salix/db/routines/vn/procedures/ticketComponentUpdate.sql

63 lines
1.3 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`(
vTicketFk INT,
2024-01-25 16:33:54 +00:00
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk TINYINT,
vCompanyFk SMALLINT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption VARCHAR(25))
BEGIN
2024-01-25 16:33:54 +00:00
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
2024-01-25 16:33:54 +00:00
RESIGNAL;
END;
START TRANSACTION;
2024-01-25 16:33:54 +00:00
IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN
UPDATE ticket t
JOIN address a ON a.id = vAddressFk
SET t.nickname = a.nickname
WHERE t.id = vTicketFk;
2024-01-25 16:33:54 +00:00
END IF;
UPDATE ticket t
SET
t.clientFk = vClientFk,
t.agencyModeFk = vAgencyModeFk,
t.addressFk = vAddressFk,
t.warehouseFk = vWarehouseFk,
2024-01-25 16:33:54 +00:00
t.companyFk = vCompanyFk,
t.landed = vLanded,
t.shipped = vShipped,
2024-01-25 16:33:54 +00:00
t.isDeleted = vIsDeleted
WHERE
t.id = vTicketFk;
2024-01-25 16:33:54 +00:00
IF vHasToBeUnrouted THEN
UPDATE ticket t SET t.routeFk = NULL
WHERE t.id = vTicketFk;
2024-01-25 16:33:54 +00:00
END IF;
2024-01-25 16:33:54 +00:00
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk))
ENGINE = MEMORY
SELECT id AS saleFk, vWarehouseFk warehouseFk
FROM sale s WHERE s.ticketFk = vTicketFk;
2024-01-25 16:33:54 +00:00
CALL ticketComponentUpdateSale (vOption);
DROP TEMPORARY TABLE tmp.sale;
COMMIT;
END$$
DELIMITER ;