diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index cc207b572..faa00477e 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -23,7 +23,7 @@ BEGIN DECLARE vConcept VARCHAR(50); DECLARE vItemName VARCHAR(50); DECLARE vHasThrow BOOLEAN DEFAULT FALSE; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; @@ -48,21 +48,14 @@ BEGIN IF vAvailable < vQuantity THEN SET vHasThrow = TRUE; - SELECT vAvailable, vQuantity; ELSE - START TRANSACTION; - SELECT `name`, CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) INTO vItemName, vConcept FROM item WHERE id = vItemFk; - INSERT INTO ticketLog - SET originFk = vTicketFk, - userFk = getUser(), - `action` = 'update', - `description` = CONCAT('Añadido articulo ', vItemName, ' cantidad:', vQuantity); + START TRANSACTION; INSERT INTO sale SET itemFk = vItemFk, @@ -84,12 +77,13 @@ BEGIN IF vHasThrow THEN CALL util.throw("No hay disponibilidad para el artículo seleccionado"); ELSE - IF vSaleGroupFk THEN - INSERT INTO saleGroupDetail - SET saleFk = vSaleFk, - saleGroupFk = vSaleGroupFk; - COMMIT; + IF vSaleGroupFk THEN + INSERT INTO saleGroupDetail + SET saleFk = vSaleFk, + saleGroupFk = vSaleGroupFk; END IF; - END IF ; + COMMIT; + END IF; + END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/collection_getAssigned.sql b/db/routines/vn/procedures/collection_getAssigned.sql index 63805e701..575032e2e 100644 --- a/db/routines/vn/procedures/collection_getAssigned.sql +++ b/db/routines/vn/procedures/collection_getAssigned.sql @@ -1,11 +1,14 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getAssigned`( vUserFk INT, - OUT vCollectionFk INT) -proc:BEGIN -/* Comprueba si existen colecciones libres que se ajustan al perfil del usuario + OUT vCollectionFk INT +) +BEGIN +/** + * Comprueba si existen colecciones libres que se ajustan al perfil del usuario * y le asigna la más antigua. * Añade un registro al semillero de colecciones y hace la reserva para la colección + * * @param vUserFk Id de usuario * @param vCollectionFk Id de colección */ @@ -28,17 +31,16 @@ proc:BEGIN CALL collection_get(vUserFk); SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, - collection_assign_lockname + pc.collection_assign_lockname INTO vHasTooMuchCollections, vLockName - FROM tCollection - JOIN productionConfig pc ; + FROM tCollection tc + JOIN productionConfig pc; DROP TEMPORARY TABLE tCollection; IF vHasTooMuchCollections THEN CALL util.throw('Hay colecciones pendientes'); - LEAVE proc; END IF; SELECT warehouseFk, itemPackingTypeFk diff --git a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql index 9bc549235..7f9cc6616 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql @@ -26,7 +26,7 @@ BEGIN JOIN vn.saleTracking st ON st.saleFk = sa.saleFk JOIN vn.`state` s ON s.id = st.stateFk WHERE st.isChecked - AND s.semaphore = 1 + AND s.`code` IN ('PREVIOUS_PREPARATION', 'OK PREVIOUS', 'OK STOWAWAY') GROUP BY sa.saleFk ) SELECT s.saleFk FROM sales s diff --git a/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql b/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql new file mode 100644 index 000000000..7001ee4b8 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_moveReserv`( + vItemShelvingFk INT(10), + vItemFk INT(10) +) +BEGIN +/** + * Elimina reservas de un itemShelvingSale e intenta reservar en otra ubicación + * + * @param vItemShelvingFk Id itemShelving + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT id INTO vItemShelvingFk + FROM itemShelving + WHERE id = vItemShelvingFk + AND FALSE + FOR UPDATE; + + UPDATE itemShelving + SET visible = 0, + available = 0 + WHERE id = vItemShelvingFk + AND itemFk = vItemFk; + + INSERT INTO itemShelvingSaleReserv (saleFk) + SELECT DISTINCT iss.saleFk + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + + DELETE iss + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + COMMIT; + + CALL itemShelvingSale_doReserve(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql b/db/routines/vn/procedures/itemShelvingSale_setPicked.sql similarity index 91% rename from db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql rename to db/routines/vn/procedures/itemShelvingSale_setPicked.sql index 911034ed1..c1e58a9d1 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setPicked.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setSaleGroup`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setPicked`( vSaleGroupFk INT(10) ) BEGIN diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 13b8a16ad..6f008ab33 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -46,10 +46,8 @@ BEGIN CALL util.throw('La cantidad no puede distinta a la reserva'); END IF; - START TRANSACTION; - UPDATE itemShelvingSale SET isPicked = TRUE, quantity = vQuantity @@ -62,41 +60,10 @@ BEGIN FOR UPDATE; UPDATE itemShelving - SET visible = IF(vIsItemShelvingSaleEmpty, 0, GREATEST(0, visible - vQuantity)) + SET visible = GREATEST(0, visible - vQuantity) WHERE id = vItemShelvingFk; - COMMIT; - IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - - UPDATE itemShelving - SET visible = 0, - available = 0 - WHERE id = vItemShelvingFk - AND itemFk = vItemFk; - - CALL itemShelvingSale_addBySale(vSaleFk); - - START TRANSACTION; - - INSERT INTO itemShelvingSaleReserv (saleFk) - SELECT DISTINCT iss.saleFk - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND ish.itemFk = vItemFk - AND NOT iss.isPicked; - - DELETE iss - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND ish.itemFk = vItemFk - AND NOT iss.isPicked; - COMMIT; - - CALL itemShelvingSale_doReserve(); - END IF; SELECT SUM(IF(isPicked, 0, quantity)), SUM(quantity) INTO vRemainingQuantity, vTotalQuantity @@ -104,8 +71,6 @@ BEGIN WHERE saleFk = vSaleFk; IF vRemainingQuantity = 0 THEN - START TRANSACTION; - CALL saleTracking_new( vSaleFk, TRUE, @@ -119,8 +84,12 @@ BEGIN SET s.quantity = vTotalQuantity, isPicked = TRUE WHERE s.id = vSaleFk; - - COMMIT; + END IF; + + COMMIT; + + IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN + CALL itemShelvingSale_moveReserv(vItemShelvingFk, vQuantity); END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingTransfer.sql b/db/routines/vn/procedures/itemShelving_transfer.sql similarity index 95% rename from db/routines/vn/procedures/itemShelvingTransfer.sql rename to db/routines/vn/procedures/itemShelving_transfer.sql index 07012a654..47a9a7cf0 100644 --- a/db/routines/vn/procedures/itemShelvingTransfer.sql +++ b/db/routines/vn/procedures/itemShelving_transfer.sql @@ -1,7 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingTransfer`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_transfer`( vItemShelvingFk INT, - vShelvingFk VARCHAR(3)) + vShelvingFk VARCHAR(10) +) BEGIN /** * Transfiere producto de una ubicación a otra, fusionando si coincide el diff --git a/db/routines/vn/procedures/sectorCollection_getPartial.sql b/db/routines/vn/procedures/sectorCollection_getMyPartial.sql similarity index 95% rename from db/routines/vn/procedures/sectorCollection_getPartial.sql rename to db/routines/vn/procedures/sectorCollection_getMyPartial.sql index 2f59f591a..23e21d2f3 100644 --- a/db/routines/vn/procedures/sectorCollection_getPartial.sql +++ b/db/routines/vn/procedures/sectorCollection_getMyPartial.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_getPartial`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_getMyPartial`() BEGIN /** * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas diff --git a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql index 0de49e90c..acb460190 100644 --- a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql +++ b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql @@ -2,28 +2,24 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION vn.sectorCollection_hasSalesReserved(vSelf INT) RETURNS tinyint(1) DETERMINISTIC BEGIN - /** -* Devuelve si sectorCollection tiene reservas -* @param vSelf Id de sectorCollection -* -* returns BOOLEAN -*/ - + * Devuelve si sectorCollection tiene reservas + * @param vSelf Id de sectorCollection + * + * returns BOOLEAN + */ DECLARE vHasSalesReserved BOOLEAN; - - SELECT DISTINCT COUNT(*)>0 INTO vHasSalesReserved - FROM vn.sectorCollection sc - JOIN vn.sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk - JOIN vn.saleGroup sg ON sg.id = scsg.saleGroupFk - JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id - JOIN vn.sale s ON s.id = sgd.saleFk - JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id - JOIN vn.saleTracking st ON st.saleFk = s.id + SELECT DISTINCT COUNT(*) INTO vHasSalesReserved + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk + JOIN saleGroup sg ON sg.id = scsg.saleGroupFk + JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id + JOIN sale s ON s.id = sgd.saleFk + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN saleTracking st ON st.saleFk = s.id WHERE sc.id = vSelf; RETURN vHasSalesReserved; - END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_afterInsert.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql deleted file mode 100644 index 819e3e790..000000000 --- a/db/routines/vn/triggers/itemShelving_afterInsert.sql +++ /dev/null @@ -1,29 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` - AFTER INSERT ON `itemShelving` - FOR EACH ROW -BEGIN - INSERT INTO vn.itemShelvingLog( - itemShelvingFk, - workerFk, - accion, - itemFk, - shelvingFk, - visible, - `grouping`, - packing, - available - ) - VALUES ( - NEW.id, - NEW.userFk, - 'CREA REGISTRO', - NEW.itemFk, - NEW.shelvingFk, - NEW.visible, - NEW.`grouping`, - NEW.packing, - NEW.available - ); -END$$ -DELIMITER ; \ No newline at end of file