2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`(
|
2024-01-25 16:33:54 +00:00
|
|
|
vTicketFk INT,
|
2024-01-15 11:31:03 +00:00
|
|
|
vClientFk INT,
|
2024-01-25 16:33:54 +00:00
|
|
|
vNickname VARCHAR(50),
|
2024-01-15 11:31:03 +00:00
|
|
|
vAgencyModeFk INT,
|
2024-01-25 16:33:54 +00:00
|
|
|
vAddressFk INT,
|
|
|
|
vZoneFk INT,
|
2024-01-15 11:31:03 +00:00
|
|
|
vWarehouseFk INT,
|
2024-01-25 16:33:54 +00:00
|
|
|
vCompanyFk INT,
|
2024-01-15 11:31:03 +00:00
|
|
|
vShipped DATETIME,
|
2024-01-25 16:33:54 +00:00
|
|
|
vLanded DATE,
|
2024-01-15 11:31:03 +00:00
|
|
|
vIsDeleted BOOLEAN,
|
2024-01-25 16:33:54 +00:00
|
|
|
vHasToBeUnrouted BOOLEAN,
|
|
|
|
vOption VARCHAR(25))
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modifica en el ticket los campos que se le pasan por parámetro
|
|
|
|
* y cambia sus componentes
|
|
|
|
*
|
|
|
|
* @param vTicketFk Id del ticket a modificar
|
|
|
|
* @param vClientFk nuevo cliente
|
|
|
|
* @param vNickname nuevo alias
|
|
|
|
* @param vAgencyModeFk nueva agencia
|
|
|
|
* @param vAddressFk nuevo consignatario
|
|
|
|
* @param vZoneFk nueva zona
|
|
|
|
* @param vWarehouseFk nuevo almacen
|
|
|
|
* @param vCompanyFk nueva empresa
|
|
|
|
* @param vShipped nueva fecha del envio de mercancia
|
|
|
|
* @param vLanded nueva fecha de recepcion de mercancia
|
|
|
|
* @param vIsDeleted si se borra el ticket
|
|
|
|
* @param vHasToBeUnrouted si se le elimina la ruta al ticket
|
|
|
|
* @param vOption opcion para el case del proc ticketComponentUpdateSale
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE vPrice DECIMAL(10,2);
|
|
|
|
DECLARE vBonus DECIMAL(10,2);
|
|
|
|
|
|
|
|
CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE);
|
|
|
|
|
|
|
|
SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus
|
|
|
|
FROM tmp.zoneGetShipped
|
|
|
|
WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1;
|
2024-01-25 16:33:54 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
UPDATE ticket t
|
|
|
|
SET
|
|
|
|
t.clientFk = vClientFk,
|
|
|
|
t.nickname = vNickname,
|
|
|
|
t.agencyModeFk = vAgencyModeFk,
|
|
|
|
t.addressFk = vAddressFk,
|
|
|
|
t.zoneFk = vZoneFk,
|
|
|
|
t.zonePrice = vPrice,
|
|
|
|
t.zoneBonus = vBonus,
|
|
|
|
t.warehouseFk = vWarehouseFk,
|
|
|
|
t.companyFk = vCompanyFk,
|
|
|
|
t.landed = vLanded,
|
|
|
|
t.shipped = vShipped,
|
|
|
|
t.isDeleted = vIsDeleted
|
|
|
|
WHERE
|
|
|
|
t.id = vTicketFk;
|
2024-01-25 16:33:54 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
IF vHasToBeUnrouted THEN
|
|
|
|
UPDATE ticket t SET t.routeFk = NULL
|
|
|
|
WHERE t.id = vTicketFk;
|
|
|
|
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-15 11:31:03 +00:00
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent;
|
|
|
|
CREATE TEMPORARY TABLE tmp.ticketComponent
|
|
|
|
SELECT * FROM tmp.ticketComponentPreview;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-01-25 16:33:54 +00:00
|
|
|
CALL ticketComponentUpdateSale (vOption);
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.sale;
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|