From 9ad703f625b0d9e04d892ab62305dfd0b50152ff Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 24 Jan 2019 07:39:23 +0100 Subject: [PATCH] update structure cau 9511 and fix test --- .../methods/client/specs/listWorkers.spec.js | 2 +- .../1.2-CHECK/16-expeditionsBeforeInsert.sql | 30 +++++++++++++++++++ .../1.2-CHECK/17-expeditionsBeforeUpdate.sql | 19 ++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 services/db/install/changes/1.2-CHECK/16-expeditionsBeforeInsert.sql create mode 100644 services/db/install/changes/1.2-CHECK/17-expeditionsBeforeUpdate.sql diff --git a/modules/client/back/methods/client/specs/listWorkers.spec.js b/modules/client/back/methods/client/specs/listWorkers.spec.js index d14903a18..309ba6a51 100644 --- a/modules/client/back/methods/client/specs/listWorkers.spec.js +++ b/modules/client/back/methods/client/specs/listWorkers.spec.js @@ -6,7 +6,7 @@ describe('Client listWorkers', () => { .then(result => { let amountOfEmployees = Object.keys(result).length; - expect(amountOfEmployees).toEqual(41); + expect(amountOfEmployees).toEqual(43); done(); }) .catch(done.fail); diff --git a/services/db/install/changes/1.2-CHECK/16-expeditionsBeforeInsert.sql b/services/db/install/changes/1.2-CHECK/16-expeditionsBeforeInsert.sql new file mode 100644 index 000000000..0da83cfd0 --- /dev/null +++ b/services/db/install/changes/1.2-CHECK/16-expeditionsBeforeInsert.sql @@ -0,0 +1,30 @@ +DROP TRIGGER IF EXISTS `vn2008`.`expeditionsBeforeInsert`; + +DELIMITER $$ +USE `vn2008`$$ +CREATE DEFINER=`root`@`%` TRIGGER `expeditionsBeforeInsert` +BEFORE INSERT ON `expeditions` FOR EACH ROW +-- Edit trigger body code below this line. Do not edit lines above this one +BEGIN + DECLARE intcounter INT; + DECLARE vShipFk INT; + + IF NEW.EsBulto > 0 THEN + + UPDATE Tickets SET Bultos = nz(Bultos) + 1 WHERE Id_Ticket = NEW.ticket_id; + SELECT IFNULL(MAX(counter),0) +1 INTO intcounter FROM expeditions e + INNER JOIN Tickets t1 ON e.ticket_id = t1.Id_Ticket + LEFT JOIN vn.ticketState ts ON ts.ticket = t1.Id_Ticket + INNER JOIN Tickets t2 ON t2.Id_Consigna = t1.Id_Consigna AND DATE(t2.Fecha) = DATE(t1.Fecha) AND t1.warehouse_id = t2.warehouse_id + WHERE t2.Id_Ticket = NEW.ticket_id AND ts.alertLevel < 3 AND t1.empresa_id = t2.empresa_id AND t1.Id_Agencia = t2.Id_Agencia; + SET NEW.`counter` = intcounter; + END IF; + SET NEW.workerFk=get_Trabajador(); + + -- JGF 14/01/19 si existe un polizon queda anulado + SELECT shipFk INTO vShipFk FROM vn.stowaway WHERE id = NEW.ticket_id; + IF vShipFk THEN + CALL vn.stowawayUnBoarding(vShipFk, NEW.ticket_id); + END IF; +END$$ +DELIMITER ; diff --git a/services/db/install/changes/1.2-CHECK/17-expeditionsBeforeUpdate.sql b/services/db/install/changes/1.2-CHECK/17-expeditionsBeforeUpdate.sql new file mode 100644 index 000000000..a6b0b80c1 --- /dev/null +++ b/services/db/install/changes/1.2-CHECK/17-expeditionsBeforeUpdate.sql @@ -0,0 +1,19 @@ +DROP TRIGGER IF EXISTS `vn2008`.`expeditionsBeforeUpdate`; + +DELIMITER $$ +USE `vn2008`$$ +CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`expeditionsBeforeUpdate` +BEFORE UPDATE ON `vn2008`.`expeditions` +FOR EACH ROW +-- Edit trigger body code below this line. Do not edit lines above this one +BEGIN + IF NEW.counter <> OLD.counter THEN + IF (SELECT COUNT(*) FROM expeditions e + INNER JOIN Tickets t1 ON e.ticket_id = t1.Id_Ticket + INNER JOIN Tickets t2 ON t2.Id_Consigna = t1.Id_Consigna AND DATE(t2.Fecha) = DATE(t1.Fecha) + WHERE t1.Id_Ticket = NEW.ticket_id AND counter = NEW.counter) > 0 THEN + SET NEW.expeditions_id = NULL; + END IF; + END IF; +END$$ +DELIMITER ;