update fixtures
This commit is contained in:
parent
65bf807195
commit
d2904bd065
|
@ -0,0 +1,32 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `logAddWithUser`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `logAddWithUser`(vOriginFk INT, vUserId INT, vActionCode VARCHAR(45), vEntity VARCHAR(45), vDescription TEXT)
|
||||
BEGIN
|
||||
/**
|
||||
* Guarda las acciones realizadas por el usuario
|
||||
*
|
||||
* @param vOriginFk Id del registro de origen.
|
||||
* @param vUserId Id del usuario.
|
||||
* @param vActionCode Código de la acción {insert | delete | update}.
|
||||
* @param vEntity Nombre que hace referencia a la tabla.
|
||||
* @param descripcion Descripción de la acción realizada por el usuario.
|
||||
*/
|
||||
DECLARE vTableName VARCHAR(45);
|
||||
|
||||
SET vTableName = CONCAT(vEntity, 'Log');
|
||||
|
||||
SET @qryLog := CONCAT(
|
||||
'INSERT INTO ', vTableName, ' (originFk, userFk, action, description)',
|
||||
' VALUES (', vOriginFk, ', ', vUserId, ', "', vActionCode, '", "', vDescription, '")'
|
||||
);
|
||||
|
||||
PREPARE stmt FROM @qryLog;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCreateWithUser`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithUser`(
|
||||
vClientId INT
|
||||
,vShipped DATE
|
||||
,vWarehouseId INT
|
||||
,vCompanyFk INT
|
||||
,vAddressFk INT
|
||||
,vAgencyType INT
|
||||
,vRouteFk INT
|
||||
,vlanded DATE
|
||||
,OUT vNewTicket INT)
|
||||
BEGIN
|
||||
|
||||
DECLARE vClientOrnamentales INT DEFAULT 5270;
|
||||
DECLARE vCompanyOrn INT DEFAULT 1381;
|
||||
DECLARE vProvinceName VARCHAR(255);
|
||||
|
||||
SELECT p.name INTO vProvinceName
|
||||
FROM vn.client c
|
||||
JOIN province p ON p.id = c.provinceFk
|
||||
WHERE c.id = vClientId;
|
||||
|
||||
IF vProvinceName IN ('SANTA CRUZ DE TENERIFE', 'LAS PALMAS DE GRAN CANARIA') AND vClientId <> vClientOrnamentales THEN
|
||||
SET vCompanyFk = vCompanyOrn;
|
||||
END IF;
|
||||
|
||||
IF NOT vAddressFk THEN
|
||||
SELECT id INTO vAddressFk
|
||||
FROM address
|
||||
WHERE clientFk = vClientId AND isDefaultAddress;
|
||||
END IF;
|
||||
|
||||
INSERT INTO vn2008.Tickets (
|
||||
Id_Cliente,
|
||||
Fecha,
|
||||
Id_Consigna,
|
||||
Id_Agencia,
|
||||
Alias,
|
||||
warehouse_id,
|
||||
Id_Ruta,
|
||||
empresa_id,
|
||||
landing
|
||||
)
|
||||
SELECT
|
||||
vClientId,
|
||||
vShipped,
|
||||
a.id,
|
||||
IF(vAgencyType, vAgencyType, a.agencyModeFk),
|
||||
a.nickname,
|
||||
vWarehouseId,
|
||||
IF(vRouteFk,vRouteFk,NULL),
|
||||
vCompanyFk,
|
||||
vlanded
|
||||
FROM address a
|
||||
JOIN agencyMode am ON am.id = a.agencyModeFk
|
||||
WHERE a.id = vAddressFk;
|
||||
|
||||
SET vNewTicket = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
|
||||
SELECT vNewTicket, ao.observationTypeFk, ao.description
|
||||
FROM addressObservation ao
|
||||
JOIN address a ON a.id = ao.addressFk
|
||||
WHERE a.id = vAddressFk;
|
||||
|
||||
CALL logAddWithUser(vNewTicket, vUserId, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket));
|
||||
|
||||
IF (SELECT isCreatedAsServed FROM vn.client WHERE id = vClientId ) <> FALSE THEN
|
||||
INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
|
||||
SELECT id, vNewTicket, getWorker()
|
||||
FROM state
|
||||
WHERE `code` = 'DELIVERED';
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
Loading…
Reference in New Issue