diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index e3f4eb8d2..18a3e8ab2 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -3,7 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_addWithR vItemFk INT, vQuantity INT, vTicketFk INT, - vSaleGroupFk INT + vSaleGroupFk INT, + vSectorFk INT ) BEGIN /** @@ -67,7 +68,7 @@ BEGIN SELECT LAST_INSERT_ID() INTO vSaleFk; CALL sale_calculateComponent(vSaleFk, NULL); - CALL itemShelvingSale_addBySale(vSaleFk); + CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN SET vHasThrow = TRUE; diff --git a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql index 7f9cc6616..a6f9b3e8c 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql @@ -44,7 +44,7 @@ BEGIN LEAVE l; END IF; - CALL itemShelvingSale_addBySale(vSaleFk); + CALL itemShelvingSale_addBySale(vSaleFk, NULL); END LOOP; CLOSE vSales; END$$ diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 909ce5155..96c49b788 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -1,6 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( - vSaleFk INT + vSaleFk INT, + vSectorFk INT ) proc: BEGIN /** @@ -8,6 +9,7 @@ proc: BEGIN * * @param vSaleFk Id de sale * @param vItemShelvingSaleFk Id de reserva + * @param vSectorFk Id del sector del operator */ DECLARE vLastPickingOrder INT; DECLARE vDone INT DEFAULT FALSE; @@ -30,6 +32,7 @@ proc: BEGIN JOIN productionConfig pc WHERE s.id = vSaleFk AND NOT sc.isHideForPickers + AND (sc.id = vSectorFk OR vSectorFk IS NULL) ORDER BY s.id, p.pickingOrder >= vLastPickingOrder, sh.priority DESC, diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql index 442abcf5d..c359c7c8d 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql @@ -10,6 +10,7 @@ BEGIN */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vSaleFk INT; + DECLARE vSectorFk INT; DECLARE vSales CURSOR FOR SELECT s.id FROM sectorCollectionSaleGroup sc @@ -25,6 +26,10 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + SELECT sectorFk INTO vSectorFk + FROM operator + WHERE workerFk = account.myUser_getId(); + OPEN vSales; l: LOOP SET vDone = FALSE; @@ -34,7 +39,7 @@ BEGIN LEAVE l; END IF; - CALL itemShelvingSale_addBySale(vSaleFk); + CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); END LOOP; CLOSE vSales; END$$ diff --git a/db/routines/vn/procedures/itemShelvingSale_doReserve.sql b/db/routines/vn/procedures/itemShelvingSale_doReserve.sql index 629e303b3..810900434 100644 --- a/db/routines/vn/procedures/itemShelvingSale_doReserve.sql +++ b/db/routines/vn/procedures/itemShelvingSale_doReserve.sql @@ -6,6 +6,7 @@ proc: BEGIN */ DECLARE vDone BOOL; DECLARE vSaleFk INT; + DECLARE vSectorFk INT; DECLARE vSales CURSOR FOR SELECT DISTINCT saleFk FROM tSale; @@ -26,24 +27,25 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tSale ENGINE = MEMORY - SELECT id, saleFk FROM itemShelvingSaleReserve; + SELECT id, saleFk, sectorFk FROM itemShelvingSaleReserve; OPEN vSales; myLoop: LOOP SET vDone = FALSE; - FETCH vSales INTO vSaleFk; + FETCH vSales INTO vSaleFk, vSectorFk; IF vDone THEN LEAVE myLoop; END IF; - CALL itemShelvingSale_addBySale (vSaleFk); + CALL itemShelvingSale_addBySale (vSaleFk, vSectorFk); END LOOP; CLOSE vSales; - DELETE iss FROM itemShelvingSaleReserve iss JOIN tSale s ON s.id = iss.id; + DELETE iss FROM itemShelvingSaleReserve iss + JOIN tSale s ON s.id = iss.id AND s.sectorFk = iss.sectorFk; DROP TEMPORARY TABLE tSale; diff --git a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql index 85230a386..2b9f927e4 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql @@ -1,13 +1,16 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`( vItemShelvingFk INT(10), - vItemFk INT(10) + vItemFk INT(10), + vSectorFk INT ) BEGIN /** * Elimina reservas de un itemShelving e intenta reservar en otra ubicación * * @param vItemShelvingFk Id itemShelving + * @param vItemFk Id del artículo + * @param vSectorFk Id del sector */ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -28,7 +31,7 @@ BEGIN WHERE id = vItemShelvingFk AND itemFk = vItemFk; - INSERT INTO itemShelvingSaleReserve (saleFk) + INSERT INTO itemShelvingSaleReserve (saleFk, vSectorFk) SELECT DISTINCT iss.saleFk FROM itemShelvingSale iss JOIN itemShelving ish ON ish.id = iss.itemShelvingFk diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 85f56ee68..b65c5df7f 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -2,7 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setQuantity`( vItemShelvingSaleFk INT(10), vQuantity DECIMAL(10,0), - vIsItemShelvingSaleEmpty BOOLEAN + vIsItemShelvingSaleEmpty BOOLEAN, + vSectorFk INT ) BEGIN /** @@ -14,6 +15,7 @@ BEGIN * @param vQuantity Cantidad real que se ha cogido de la ubicación * @param vIsItemShelvingSaleEmpty determina si la ubicación itemShelvingSale se ha * quedado vacio tras el movimiento + * @param vSectorFk Id del sector */ DECLARE vSaleFk INT; DECLARE vItemShelvingFk INT; @@ -72,7 +74,7 @@ BEGIN SET visible = GREATEST(0, visible - vQuantity) WHERE id = vItemShelvingFk; - SELECT SUM(IF(isPicked, 0, quantity)), SUM(quantity) + SELECT SUM(IF(isPicked OR id = vItemShelvingSaleFk, 0, quantity)), SUM(quantity) INTO vRemainingQuantity, vTotalQuantity FROM itemShelvingSale WHERE saleFk = vSaleFk; @@ -96,9 +98,9 @@ BEGIN COMMIT; IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - INSERT INTO itemShelvingSaleReserve (saleFk) + INSERT INTO itemShelvingSaleReserve (saleFk, vSectorFk) SELECT vSaleFk; - CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk); + CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk, vSectorFk); END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/versions/11158-redRaphis/00-firstScript.sql b/db/versions/11158-redRaphis/00-firstScript.sql new file mode 100644 index 000000000..7fe41b32b --- /dev/null +++ b/db/versions/11158-redRaphis/00-firstScript.sql @@ -0,0 +1,11 @@ +-- Place your SQL code here + +ALTER TABLE IF EXISTS vn.itemShelvingSaleReserve +ADD IF NOT EXISTS sectorFk int(11) NULL; + +ALTER TABLE IF EXISTS vn.itemShelvingSaleReserve +DROP FOREIGN KEY IF EXISTS itemShelvingSaleReserve_sector_FK; + +ALTER TABLE IF EXISTS vn.itemShelvingSaleReserve +ADD CONSTRAINT itemShelvingSaleReserve_sector_FK FOREIGN KEY (id) +REFERENCES vn.sector(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/modules/item/back/methods/item-shelving-sale/itemShelvingSaleSetQuantity.js b/modules/item/back/methods/item-shelving-sale/itemShelvingSaleSetQuantity.js index 90e66c066..add2aa404 100644 --- a/modules/item/back/methods/item-shelving-sale/itemShelvingSaleSetQuantity.js +++ b/modules/item/back/methods/item-shelving-sale/itemShelvingSaleSetQuantity.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('itemShelvingSaleSetQuantity', { - description: 'Set quanitity of a sale in itemShelvingSale', + description: 'Set quantity of a sale in itemShelvingSale', accessType: 'WRITE', accepts: [ { @@ -20,6 +20,12 @@ module.exports = Self => { type: 'boolean', required: true, description: 'True if the shelvingFk is empty ', + }, + { + arg: 'sectorFk', + type: 'number', + required: true, + description: 'Sector Id', } ], http: { @@ -28,14 +34,14 @@ module.exports = Self => { } }); - Self.itemShelvingSaleSetQuantity = async(ctx, id, quantity, isItemShelvingSaleEmpty, options) => { + Self.itemShelvingSaleSetQuantity = async(ctx, id, quantity, isItemShelvingSaleEmpty, sectorFk, options) => { const myOptions = {userId: ctx.req.accessToken.userId}; if (typeof options == 'object') Object.assign(myOptions, options); - await Self.rawSql(`CALL vn.itemShelvingSale_setQuantity(?, ?, ? )`, - [id, quantity, isItemShelvingSaleEmpty], + await Self.rawSql(`CALL vn.itemShelvingSale_setQuantity(?, ?, ?, ?)`, + [id, quantity, isItemShelvingSaleEmpty, sectorFk], myOptions); }; };