Compare commits

...

10 Commits

Author SHA1 Message Date
Guillermo Bonet 216b81adda Merge pull request 'refactor: refs #7920 Main change' (!3194) from 7920-itemShelving into dev
gitea/salix/pipeline/head There was a failure building this commit Details
Reviewed-on: #3194
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2024-11-15 06:44:16 +00:00
Guillermo Bonet 48ffb80094 Merge branch 'dev' into 7920-itemShelving
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-11-15 06:40:41 +00:00
Guillermo Bonet d387486ea8 refactor: refs #7920 Requested changes
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-11-14 09:59:01 +01:00
Guillermo Bonet 5a134668da refactor: refs #7920 itemShelvingLog
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-11-13 12:04:47 +01:00
Guillermo Bonet 755312b981 refactor: refs #7920 Fix tests
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-11-13 11:51:23 +01:00
Guillermo Bonet 9d5ef3eeb0 Merge branch 'dev' into 7920-itemShelving
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-13 10:16:57 +00:00
Guillermo Bonet b3bf0024e3 refactor: refs #7920 Major changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-13 11:15:31 +01:00
Guillermo Bonet 2273dc636e refactor: refs #7920 Major changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-13 09:56:38 +01:00
Guillermo Bonet 779a75cd78 refactor: refs #7920 Major changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-13 09:03:44 +01:00
Guillermo Bonet c2381f0feb refactor: refs #7920 Main change
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-13 07:42:58 +01:00
50 changed files with 2023 additions and 1898 deletions

View File

@ -73,7 +73,7 @@ module.exports = Self => {
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN itemShelvingSale iss ON iss.saleFk = s.id JOIN itemShelvingSale iss ON iss.saleFk = s.id
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN shelving sh ON sh.id = ish.shelvingFk
LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN parking p ON p.id = sh.parkingFk
LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
LEFT JOIN origin o ON o.id = i.originFk LEFT JOIN origin o ON o.id = i.originFk
@ -114,7 +114,7 @@ module.exports = Self => {
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN itemShelvingSale iss ON iss.saleFk = s.id JOIN itemShelvingSale iss ON iss.saleFk = s.id
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN shelving sh ON sh.id = ish.shelvingFk
LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN parking p ON p.id = sh.parkingFk
LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
LEFT JOIN origin o ON o.id = i.originFk LEFT JOIN origin o ON o.id = i.originFk

File diff suppressed because it is too large Load Diff

View File

@ -1254,9 +1254,9 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`,`buyFk`, `userFk`) INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`,`buyFk`, `userFk`)
VALUES VALUES
(2, 'GVC', 1, 1, 1, 2,1106), (2, 11, 1, 1, 1, 2,1106),
(4, 'HEJ', 1, 1, 1, NULL,1106), (4, 12, 1, 1, 1, NULL,1106),
(1, 'UXN', 2, 12, 12, NULL,1106); (1, 13, 2, 12, 12, NULL,1106);
INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`)
VALUES VALUES
@ -3425,7 +3425,7 @@ INSERT INTO vn.buy
INSERT INTO vn.itemShelving INSERT INTO vn.itemShelving
SET id = 9931, SET id = 9931,
itemFk = 999993, itemFk = 999993,
shelvingFk = 'NCC', shelvingFk = 16,
visible = 10, visible = 10,
`grouping` = 5, `grouping` = 5,
packing = 10; packing = 10;
@ -3752,7 +3752,7 @@ INSERT vn.sale
USE vn; USE vn;
DELETE ish.* FROM vn.itemShelving ish DELETE ish.* FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.warehouse w ON w.id = s.warehouseFk JOIN vn.warehouse w ON w.id = s.warehouseFk
@ -3761,22 +3761,22 @@ DELETE ish.* FROM vn.itemShelving ish
INSERT INTO vn.itemShelving INSERT INTO vn.itemShelving
(itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, isChecked) (itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, isChecked)
VALUES VALUES
(999991, 'NAA', 8, '2023-09-20', 1, 20, NULL, 103, NULL), (999991, 14, 8, '2023-09-20', 1, 20, NULL, 103, NULL),
(999998, 'NAA', 80, '2023-09-20', 10, 30, NULL, 103, NULL), (999998, 14, 80, '2023-09-20', 10, 30, NULL, 103, NULL),
(1000001, 'NAA', 6, '2023-09-20', 3, 50, NULL, 103, NULL), (1000001, 14, 6, '2023-09-20', 3, 50, NULL, 103, NULL),
(1000000, 'NBB', 50, '2023-09-18', 25, 500, NULL, 103, NULL), (1000000, 15, 50, '2023-09-18', 25, 500, NULL, 103, NULL),
(999993, 'NBB', 25, '2023-09-18', NULL, 10, NULL, 103, NULL), (999993, 15, 25, '2023-09-18', NULL, 10, NULL, 103, NULL),
(999999, 'NBB', 30, '2023-09-18', 10, 500, NULL, 103, NULL), (999999, 15, 30, '2023-09-18', 10, 500, NULL, 103, NULL),
(999993, 'NCC', 25, '2023-09-20', 5, 10, NULL, 103, NULL), (999993, 16, 25, '2023-09-20', 5, 10, NULL, 103, NULL),
(999997, 'NCC', 10, '2023-09-20', NULL, 100, NULL, 103, NULL), (999997, 16, 10, '2023-09-20', NULL, 100, NULL, 103, NULL),
(999999, 'NCC', 40, '2023-09-20', 10, 500, NULL, 103, NULL), (999999, 16, 40, '2023-09-20', 10, 500, NULL, 103, NULL),
(999995, 'NDD', 10, '2023-09-19', NULL, 20, NULL, 103, NULL), (999995, 17, 10, '2023-09-19', NULL, 20, NULL, 103, NULL),
(999994, 'NDD', 48, '2023-09-19', 4, 20, NULL, 103, NULL), (999994, 17, 48, '2023-09-19', 4, 20, NULL, 103, NULL),
(1000001, 'NEE', 6, '2023-09-21', 3, 50, NULL, 103, NULL), (1000001, 18, 6, '2023-09-21', 3, 50, NULL, 103, NULL),
(999992, 'NEE', 50, '2023-09-21', NULL, 1, NULL, 103, NULL), (999992, 18, 50, '2023-09-21', NULL, 1, NULL, 103, NULL),
(1000000, 'NEE', 25, '2023-09-21', 25, 500, NULL, 103, NULL), (1000000, 18, 25, '2023-09-21', 25, 500, NULL, 103, NULL),
(999996, 'PAA', 5, '2023-09-27', 1, 5, NULL, 103, NULL), (999996, 19, 5, '2023-09-27', 1, 5, NULL, 103, NULL),
(999997, 'PCC', 10, '2023-09-27', 5, 100, NULL, 103, NULL); (999997, 21, 10, '2023-09-27', 5, 100, NULL, 103, NULL);
-- Previous for Bolas de madera -- Previous for Bolas de madera
INSERT IGNORE INTO vn.sectorCollection INSERT IGNORE INTO vn.sectorCollection

View File

@ -32,7 +32,7 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tVisible CREATE OR REPLACE TEMPORARY TABLE tVisible
SELECT itemFk, SUM(visible) totalVisible SELECT itemFk, SUM(visible) totalVisible
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector sc ON sc.id = p.sectorFk JOIN vn.sector sc ON sc.id = p.sectorFk
WHERE sc.warehouseFk = vWarehouseFk WHERE sc.warehouseFk = vWarehouseFk

View File

@ -9,7 +9,7 @@ BEGIN
SELECT count(*) INTO vItemCount SELECT count(*) INTO vItemCount
FROM vn.sale s FROM vn.sale s
JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
WHERE s.ticketFk = vTicketFk WHERE s.ticketFk = vTicketFk
AND p.sectorFk = vSectorFk; AND p.sectorFk = vSectorFk;

View File

@ -10,7 +10,7 @@ BEGIN
SELECT count(*) INTO vItemCount SELECT count(*) INTO vItemCount
FROM vn.sale s FROM vn.sale s
JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
WHERE s.ticketFk = vTicketFk WHERE s.ticketFk = vTicketFk
AND p.sectorFk = vSectorFk; AND p.sectorFk = vSectorFk;

View File

@ -83,7 +83,7 @@ BEGIN
AND s.semaphore = 1 AND s.semaphore = 1
GROUP BY st.saleFk) st ON st.saleFk = ts.saleFk GROUP BY st.saleFk) st ON st.saleFk = ts.saleFk
JOIN itemShelving ish ON ish.itemFk = ts.itemFk JOIN itemShelving ish ON ish.itemFk = ts.itemFk
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector sc ON sc.id = p.sectorFk JOIN sector sc ON sc.id = p.sectorFk
JOIN sectorType st ON st.id = sc.typeFk JOIN sectorType st ON st.id = sc.typeFk

View File

@ -1,10 +1,15 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_splitByShelving`(vShelvingFk VARCHAR(3), vFromEntryFk INT, vToEntryFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_splitByShelving`(
vShelvingCode VARCHAR(10),
vFromEntryFk INT,
vToEntryFk INT
)
BEGIN BEGIN
/** /**
* Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr<EFBFBD>cula * Divide las compras entre dos entradas de
* acuerdo con lo ubicado en una matricula.
* *
* @param vShelvingFk Identificador de vn.shelving * @param vShelvingCode Código de vn.shelving
* @param vFromEntryFk Entrada origen * @param vFromEntryFk Entrada origen
* @param vToEntryFk Entrada destino * @param vToEntryFk Entrada destino
*/ */
@ -14,7 +19,7 @@ BEGIN
DECLARE vDone BOOLEAN DEFAULT FALSE; DECLARE vDone BOOLEAN DEFAULT FALSE;
DECLARE cur CURSOR FOR DECLARE cur CURSOR FOR
SELECT bb.id buyFk, SELECT bb.id buyFk,
LEAST(bb.stickers, FLOOR(ish.visible / ish.packing)) ishStickers, LEAST(bb.stickers, FLOOR(ish.visible / ish.packing)) ishStickers,
bb.stickers buyStickers bb.stickers buyStickers
FROM itemShelving ish FROM itemShelving ish
@ -23,7 +28,7 @@ BEGIN
WHERE b.entryFk = vFromEntryFk WHERE b.entryFk = vFromEntryFk
ORDER BY b.stickers DESC ORDER BY b.stickers DESC
LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk
WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci WHERE ish.shelvingFk = vShelvingCode COLLATE utf8_general_ci
AND NOT ish.isSplit AND NOT ish.isSplit
GROUP BY ish.id; GROUP BY ish.id;
@ -107,9 +112,10 @@ BEGIN
UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID();
END IF; END IF;
UPDATE itemShelving UPDATE itemShelving ish
SET isSplit = TRUE JOIN shelving sh ON sh.id = ish.shelvingFk
WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci; SET ish.isSplit = TRUE
WHERE sh.code = vShelvingCode COLLATE utf8_general_ci;
END LOOP; END LOOP;
CLOSE cur; CLOSE cur;
END$$ END$$

View File

@ -1,5 +1,9 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyAiming`(vShelvingFk VARCHAR(10), quantity INT, vItemFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyAiming`(
vShelvingCode VARCHAR(10),
vQuantity INT,
vItemFk INT
)
BEGIN BEGIN
SELECT ish.itemFk, SELECT ish.itemFk,
@ -9,21 +13,21 @@ BEGIN
ish.itemShelvingFk, ish.itemShelvingFk,
ish.shelving, ish.shelving,
ish.stock, ish.stock,
LEAST(ish.stock,quantity) as total, LEAST(ish.stock,vQuantity) total,
CONCAT( CONCAT(
CAST(FLOOR(LEAST(ish.stock,quantity) / ish.packing) AS DECIMAL(10,0)), CAST(FLOOR(LEAST(ish.stock, vQuantity) / ish.packing) AS DECIMAL(10,0)),
' x ', ' x ',
ish.packing, ish.packing,
IF ( IF (
LEAST(ish.stock,quantity) MOD ish.packing, LEAST(ish.stock, vQuantity) MOD ish.packing,
CONCAT(' + ',CAST(LEAST(ish.stock,quantity) MOD ish.packing AS DECIMAL(10,0))), CONCAT(' + ',CAST(LEAST(ish.stock, vQuantity) MOD ish.packing AS DECIMAL(10,0))),
'' ''
), ),
' = ', ' = ',
LEAST(ish.stock,quantity) LEAST(ish.stock, vQuantity)
) as proposal ) proposal
FROM vn.itemShelvingPlacementSupplyStock ish FROM itemShelvingPlacementSupplyStock ish
WHERE ish.shelving = vShelvingFk COLLATE utf8_general_ci WHERE ish.shelving = vShelvingCode COLLATE utf8_general_ci
AND ish.itemFk = vItemFk; AND ish.itemFk = vItemFk;
END$$ END$$

View File

@ -1,5 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyGetOrder`(vSector INT ) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyGetOrder`(
vSectorFk INT
)
BEGIN BEGIN
DECLARE vId INT; DECLARE vId INT;
@ -7,31 +9,35 @@ BEGIN
DECLARE vNextParkingFk INT; DECLARE vNextParkingFk INT;
SELECT sh.parkingFk INTO vLastParkingFk SELECT sh.parkingFk INTO vLastParkingFk
FROM vn.itemShelvingPlacementSupply isps FROM itemShelvingPlacementSupply isps
JOIN vn.itemShelving ish ON ish.id = isps.itemShelvingFk JOIN itemShelving ish ON ish.id = isps.itemShelvingFk
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
WHERE isps.userFk = getUser() WHERE isps.userFk = getUser()
ORDER BY isps.created DESC ORDER BY isps.created DESC
LIMIT 1; LIMIT 1;
SET vNextParkingFk = vn.itemShelvingPlacementSupply_ClosestGet(vLastParkingFk); SET vNextParkingFk = itemShelvingPlacementSupply_ClosestGet(vLastParkingFk);
SELECT ipsl.id INTO vId SELECT ipsl.id INTO vId
FROM vn.itemPlacementSupplyList ipsl FROM itemPlacementSupplyList ipsl
JOIN vn.itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk JOIN itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk
WHERE ipsl.saldo > 0 WHERE ipsl.saldo > 0
AND (ipsl.repoUserFk is NULL OR ipsl.repoUserFk = getUser()) AND (ipsl.repoUserFk is NULL OR ipsl.repoUserFk = getUser())
AND ipsl.sectorFk = vSector AND ipsl.sectorFk = vSectorFk
ORDER BY ipsl.repoUserFk DESC, ipsl.priority DESC, (ispss.parkingFk = vNextParkingFk) DESC, ispss.parking DESC, ipsl.created ORDER BY ipsl.repoUserFk DESC,
ipsl.priority DESC,
(ispss.parkingFk = vNextParkingFk) DESC,
ispss.parking DESC,
ipsl.created
LIMIT 1; LIMIT 1;
UPDATE vn.itemPlacementSupply UPDATE itemPlacementSupply
SET repoUserFk = getUser() SET repoUserFk = getUser()
WHERE id = vId; WHERE id = vId;
SELECT * FROM vn.itemPlacementSupplyList SELECT * FROM itemPlacementSupplyList
WHERE id = vId WHERE id = vId
AND sectorFk = vSector; AND sectorFk = vSectorFk;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,5 +1,8 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyStockGetTargetList`(vItemFk INT,vSectorFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyStockGetTargetList`(
vItemFk INT,
vSectorFk INT
)
BEGIN BEGIN
/** /**
* Devuelve la lista de ubicaciones para itemFk en ese sector. Se utiliza en la preparación previa. * Devuelve la lista de ubicaciones para itemFk en ese sector. Se utiliza en la preparación previa.
@ -13,11 +16,11 @@ BEGIN
SUM(ish.visible) stockTotal, SUM(ish.visible) stockTotal,
ish.created, ish.created,
p.pickingOrder p.pickingOrder
FROM vn.itemShelving ish FROM itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN vn.sector sc ON sc.id = p.sectorFk JOIN sector sc ON sc.id = p.sectorFk
JOIN vn.warehouse w ON w.id = sc.warehouseFk JOIN warehouse w ON w.id = sc.warehouseFk
WHERE ish.visible > 0 WHERE ish.visible > 0
AND ish.itemFk = vItemFk AND ish.itemFk = vItemFk
GROUP BY ish.id GROUP BY ish.id

View File

@ -1,14 +1,14 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingLog_get`(vShelvingFk VARCHAR(10) ) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingLog_get`(
vShelvingCode VARCHAR(10)
)
BEGIN BEGIN
/** /**
* Devuelve el log de los item en cada carro * Devuelve el log de los item en cada carro
* *
* @param vShelvingFk Matrícula del carro * @param vShelvingCode Matrícula del carro
* *
*/ */
SELECT isl.itemShelvingFk, SELECT isl.itemShelvingFk,
isl.created, isl.created,
isl.accion, isl.accion,
@ -28,8 +28,9 @@ BEGIN
FROM item FROM item
JOIN itemShelvingLog isl ON item.id = isl.itemFk JOIN itemShelvingLog isl ON item.id = isl.itemFk
JOIN worker ON isl.workerFk = worker.id JOIN worker ON isl.workerFk = worker.id
WHERE shelvingFk = vShelvingFk OR isl.itemFk = vShelvingFk JOIN shelving sh ON sh.id = isl.shelvingFk
ORDER BY isl.created DESC; WHERE sh.code = vShelvingCode COLLATE utf8mb3_unicode_ci
OR isl.itemFk = vShelvingCode -- ?? Respeto porque ya estaba
ORDER BY isl.created DESC;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -20,7 +20,7 @@ BEGIN
LEFT JOIN ( LEFT JOIN (
SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
LEFT JOIN parking pk ON pk.id = sh.parkingFk LEFT JOIN parking pk ON pk.id = sh.parkingFk
WHERE ish.created BETWEEN vFromTimed AND vToTimed WHERE ish.created BETWEEN vFromTimed AND vToTimed
GROUP BY itemFk GROUP BY itemFk

View File

@ -27,7 +27,7 @@ proc: BEGIN
ish.available ish.available
FROM sale s FROM sale s
JOIN itemShelving ish ON ish.itemFk = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector sc ON sc.id = p.sectorFk JOIN sector sc ON sc.id = p.sectorFk
JOIN productionConfig pc JOIN productionConfig pc
@ -61,7 +61,7 @@ proc: BEGIN
FROM sale s FROM sale s
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN shelving sh ON sh.id = ish.shelvingFk
LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN parking p ON p.id = sh.parkingFk
WHERE s.id = vSaleFk; WHERE s.id = vSaleFk;

View File

@ -1,6 +1,6 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_add`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_add`(
vShelvingFk VARCHAR(8), vShelvingCode VARCHAR(10),
vBarcode VARCHAR(22), vBarcode VARCHAR(22),
vQuantity INT, vQuantity INT,
vPackagingFk VARCHAR(10), vPackagingFk VARCHAR(10),
@ -12,7 +12,7 @@ BEGIN
/** /**
* Añade registro o lo actualiza si ya existe. * Añade registro o lo actualiza si ya existe.
* *
* @param vShelvingFk matrícula del carro * @param vShelvingCode matrícula del carro
* @param vBarcode el id del registro * @param vBarcode el id del registro
* @param vQuantity indica la cantidad del producto * @param vQuantity indica la cantidad del producto
* @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra * @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra
@ -23,10 +23,15 @@ BEGIN
**/ **/
DECLARE vItemFk INT; DECLARE vItemFk INT;
DECLARE vBuyFk INT; DECLARE vBuyFk INT;
DECLARE vShelvingFk INT;
SELECT id INTO vBuyFk SELECT id INTO vBuyFk
FROM buy WHERE id = vBarcode; FROM buy WHERE id = vBarcode;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
SELECT barcodeToItem(vBarcode) INTO vItemFk; SELECT barcodeToItem(vBarcode) INTO vItemFk;
IF vBuyFk IS NULL THEN IF vBuyFk IS NULL THEN
@ -40,7 +45,7 @@ BEGIN
END IF; END IF;
IF (SELECT COUNT(*) FROM itemShelving IF (SELECT COUNT(*) FROM itemShelving
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk AND itemFk = vItemFk
AND packing = vPacking AND packing = vPacking
AND buyFk = vBuyFk) THEN AND buyFk = vBuyFk) THEN
@ -48,7 +53,9 @@ BEGIN
UPDATE itemShelving UPDATE itemShelving
SET visible = visible + vQuantity, SET visible = visible + vQuantity,
available = available + vQuantity available = available + vQuantity
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk
AND packing = vPacking;
ELSE ELSE

View File

@ -1,29 +1,38 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addByClaim`(vClaimFk INT, vShelvingFk VARCHAR(3)) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addByClaim`(
vClaimFk INT,
vShelvingCode VARCHAR(10)
)
BEGIN BEGIN
/** /**
* Insert items of claim into itemShelving. * Insert items of claim into itemShelving.
* *
* @param vClaimFk The claim * @param vClaimFk The claim
* @param vShelvingFk The shelving * @param vShelvingCode The shelving code
* @table tmp.buyUltimate * @table tmp.buyUltimate
*/ */
DECLARE vWarehouseFk INT; DECLARE vWarehouseFk INT;
DECLARE vShelvingFk INT;
SELECT t.warehouseFk INTO vWarehouseFk SELECT t.warehouseFk INTO vWarehouseFk
FROM claim c FROM claim c
JOIN ticket t ON t.id = c.ticketFk JOIN ticket t ON t.id = c.ticketFk
WHERE c.id = vClaimFk; WHERE c.id = vClaimFk;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
CALL buy_getUltimate(NULL, vWarehouseFk, util.VN_CURDATE()); CALL buy_getUltimate(NULL, vWarehouseFk, util.VN_CURDATE());
INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible) INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible)
SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity visible
FROM claim c FROM claim c
JOIN claimBeginning cb ON c.id = cb.claimFk JOIN claimBeginning cb ON c.id = cb.claimFk
JOIN sale s ON s.id = cb.saleFk JOIN sale s ON s.id = cb.saleFk
JOIN ticket t ON t.id = s.ticketFk JOIN ticket t ON t.id = s.ticketFk
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk AND bu.warehouseFk = t.warehouseFk JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
AND bu.warehouseFk = t.warehouseFk
JOIN buy b ON b.id = bu.buyFk JOIN buy b ON b.id = bu.buyFk
WHERE c.id = vClaimFk; WHERE c.id = vClaimFk;
END$$ END$$

View File

@ -1,6 +1,6 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(
vShelvingFk VARCHAR(3), vShelvingCode VARCHAR(10),
vList TEXT, vList TEXT,
vIsChecking BOOL, vIsChecking BOOL,
vWarehouseFk INT vWarehouseFk INT
@ -13,7 +13,7 @@ BEGIN
* Cuando es TRUE sólo inserta los elementos de la colección que no están ya en * Cuando es TRUE sólo inserta los elementos de la colección que no están ya en
* ese shelving, actualizando los valores del campo itemShelving.isChecked * ese shelving, actualizando los valores del campo itemShelving.isChecked
* *
* @param vShelvingFk Identificador de shelving * @param vShelvingCode Código de shelving
* @param vList JSON array con esta estructura: '[value1, value2, ...]' * @param vList JSON array con esta estructura: '[value1, value2, ...]'
* @param vIsChecking Define si hay que añadir o comprobar los items * @param vIsChecking Define si hay que añadir o comprobar los items
* @param vWarehouseFk Identificador de warehouse * @param vWarehouseFk Identificador de warehouse
@ -24,6 +24,11 @@ BEGIN
DECLARE vPath VARCHAR(6); DECLARE vPath VARCHAR(6);
DECLARE vItemFk INT; DECLARE vItemFk INT;
DECLARE vIsChecked BOOL; DECLARE vIsChecked BOOL;
DECLARE vShelvingFk INT;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
WHILE vCounter < vListLength DO WHILE vCounter < vListLength DO
SET vPath = CONCAT('$[', vCounter, ']'); SET vPath = CONCAT('$[', vCounter, ']');
@ -34,17 +39,17 @@ BEGIN
SELECT IF(COUNT(*), TRUE, FALSE) INTO vIsChecked SELECT IF(COUNT(*), TRUE, FALSE) INTO vIsChecked
FROM itemShelving FROM itemShelving
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk; AND itemFk = vItemFk;
END IF; END IF;
IF NOT vIsChecking OR NOT vIsChecked THEN IF NOT vIsChecking OR NOT vIsChecked THEN
CALL itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk); CALL itemShelving_add(vShelvingCode, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
END IF; END IF;
UPDATE itemShelving UPDATE itemShelving
SET isChecked = vIsChecked SET isChecked = vIsChecked
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk AND itemFk = vItemFk
AND isChecked IS NULL; AND isChecked IS NULL;

View File

@ -1,10 +1,12 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_get`(IN vSelf VARCHAR(8)) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_get`(
vShelvingCode VARCHAR(10)
)
BEGIN BEGIN
/** /**
* Lista artículos de itemshelving * Lista artículos de itemShelving.
* *
* @param vSelf matrícula del carro * @param vShelvingCode Matrícula del carro
**/ **/
SELECT ish.itemFk item, SELECT ish.itemFk item,
i.name, i.name,
@ -22,9 +24,9 @@ BEGIN
ish.buyFk ish.buyFk
FROM itemShelving ish FROM itemShelving ish
JOIN item i ON i.id = ish.itemFk JOIN item i ON i.id = ish.itemFk
JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci JOIN shelving s ON s.id = ish.shelvingFk
LEFT JOIN parking p ON s.parkingFk = p.id LEFT JOIN parking p ON p.id = s.parkingFk
JOIN hedera.imageConfig ic JOIN hedera.imageConfig ic
WHERE ish.shelvingFk COLLATE utf8_unicode_ci = vSelf; WHERE s.code COLLATE utf8_unicode_ci = vShelvingCode;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,21 +1,31 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getAlternatives`(vShelvingFk VARCHAR(10)) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getAlternatives`(
vShelvingCode VARCHAR(10)
)
BEGIN BEGIN
/** /**
* Devuelve un listado de posibles ubicaciones alternativas a ubicar los item de la matricula * Devuelve un listado de posibles ubicaciones alternativas a ubicar
* del carro que se le ha pasado. * los item de la matricula del carro que se le ha pasado.
* *
* @param vShelvingFk matricula del carro * @param vShelvingCode Matricula del carro
*/ */
SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder DECLARE vShelvingFk INT;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
SELECT is2.id,is2.shelvingFk, p.code, is2.itemFk , is2.visible, p.pickingOrder
FROM itemShelving is2 FROM itemShelving is2
JOIN shelving sh ON sh.code = is2.shelvingFk JOIN shelving sh ON sh.id = is2.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk JOIN sector s ON s.id = p.sectorFk
LEFT JOIN operator o ON o.sectorFk = s.id AND o.workerFk = account.myUser_getId() LEFT JOIN operator o ON o.sectorFk = s.id
AND o.workerFk = account.myUser_getId()
JOIN warehouse wh ON wh.id = s.warehouseFk JOIN warehouse wh ON wh.id = s.warehouseFk
JOIN itemShelving is3 ON is3.itemFk = is2.itemFk AND is3.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci JOIN itemShelving is3 ON is3.itemFk = is2.itemFk
WHERE is2.shelvingFk <> vShelvingFk COLLATE utf8_unicode_ci AND is3.shelvingFk = vShelvingFk
WHERE is2.shelvingFk <> vShelvingFk
GROUP BY is2.id GROUP BY is2.id
ORDER BY p.pickingOrder DESC; ORDER BY p.pickingOrder DESC;
END$$ END$$

View File

@ -16,7 +16,7 @@ BEGIN
ish.itemFk itemFk, ish.itemFk itemFk,
sh.priority sh.priority
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.`code` = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking pk ON pk.id = sh.parkingFk JOIN vn.parking pk ON pk.id = sh.parkingFk
WHERE ish.itemFk = vItemFk WHERE ish.itemFk = vItemFk
ORDER BY sh.priority DESC, created ASC; ORDER BY sh.priority DESC, created ASC;

View File

@ -1,14 +1,14 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getItemDetails`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getItemDetails`(
vBarcodeItem INT, vBarcodeItem INT,
vShelvingFK VARCHAR(10) vShelvingCode VARCHAR(10)
) )
BEGIN BEGIN
/** /**
* Obtiene el precio y visible de un item * Obtiene el precio y visible de un item
* *
* @param vBarcodeItem barcode de artículo * @param vBarcodeItem barcode de artículo
* @param vShelvingFK Ubicación actual del artículo * @param vShelvingCode Ubicación actual del artículo
*/ */
DECLARE vIsItem BOOL; DECLARE vIsItem BOOL;
DECLARE vBuyFk INT; DECLARE vBuyFk INT;
@ -38,18 +38,19 @@ BEGIN
WITH visible AS( WITH visible AS(
SELECT itemFk, SELECT itemFk,
IFNULL(buyingValue, 0) + IFNULL(buyingValue, 0) +
IFNULL(freightValue, 0) + IFNULL(freightValue, 0) +
IFNULL(comissionValue, 0) + IFNULL(comissionValue, 0) +
IFNULL(packageValue, 0) itemCost IFNULL(packageValue, 0) itemCost
FROM vn.buy b FROM vn.buy b
WHERE b.id = vBuyFk WHERE b.id = vBuyFk
) SELECT v.itemFk, ) SELECT v.itemFk,
vShelvingFK, vShelvingCode,
v.itemCost, v.itemCost,
SUM(ish.visible) visible SUM(ish.visible) visible
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.id = ish.shelvingFK
JOIN visible v JOIN visible v
WHERE ish.shelvingFK = vShelvingFK COLLATE utf8mb3_general_ci WHERE sh.code = vShelvingCode COLLATE utf8mb3_general_ci
AND ish.itemFk = v.itemFk; AND ish.itemFk = v.itemFk;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,14 +1,20 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getSaleDate`(vShelvingFk VARCHAR(3)) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_getSaleDate`(
vShelvingCode VARCHAR(10)
)
BEGIN BEGIN
/**
/* Devuelve la mínima fecha en que se necesita cada producto en esa matrícula. * Devuelve la mínima fecha en que se necesita cada producto en esa matrícula.
* *
* @param vShelvingFk Matrícula del carro o pallet * @param vShelvingCode Matrícula del carro o pallet
*/ */
DECLARE vWarehouseFk INT; DECLARE vWarehouseFk INT;
DECLARE vStockScopeDays INT; DECLARE vStockScopeDays INT;
DECLARE vShelvingFk INT;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
SELECT s.warehouseFk, stockScopeDays SELECT s.warehouseFk, stockScopeDays
INTO vWarehouseFk, vStockScopeDays INTO vWarehouseFk, vStockScopeDays
@ -30,7 +36,7 @@ BEGIN
ENGINE = MEMORY ENGINE = MEMORY
SELECT itemFk, SUM(visible) visible SELECT itemFk, SUM(visible) visible
FROM itemShelving FROM itemShelving
WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci WHERE shelvingFk = vShelvingFk
GROUP BY itemFk; GROUP BY itemFk;
CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay
@ -52,7 +58,7 @@ BEGIN
SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE() SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE()
FROM itemShelving ish FROM itemShelving ish
JOIN tmp.tItems i ON i.itemFk = ish.itemFk JOIN tmp.tItems i ON i.itemFk = ish.itemFk
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON sh.parkingFk = p.id JOIN parking p ON sh.parkingFk = p.id
JOIN sector s ON s.id = p.sectorFk JOIN sector s ON s.id = p.sectorFk
WHERE s.isReserve WHERE s.isReserve
@ -110,7 +116,7 @@ BEGIN
UPDATE tmp.tStockByDay sbd UPDATE tmp.tStockByDay sbd
JOIN (SELECT ish.itemFK, SUM(ish.visible) amount JOIN (SELECT ish.itemFK, SUM(ish.visible) amount
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk JOIN sector s ON s.id = p.sectorFk
WHERE s.warehouseFk = vWarehouseFk WHERE s.warehouseFk = vWarehouseFk
@ -150,10 +156,10 @@ BEGIN
p.sectorFk, p.sectorFk,
ish.shelvingFk ish.shelvingFk
FROM itemShelving ish FROM itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
LEFT JOIN parking p ON p.id = parkingFk LEFT JOIN parking p ON p.id = parkingFk
LEFT JOIN vn.sector s ON s.id = p.sectorFk LEFT JOIN vn.sector s ON s.id = p.sectorFk
WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci WHERE ish.shelvingFk = vShelvingFk
) sub4 ON sub4.itemFk = ts.itemFk ) sub4 ON sub4.itemFk = ts.itemFk
LEFT JOIN sector s ON s.id = sub4.sectorFk LEFT JOIN sector s ON s.id = sub4.sectorFk
LEFT JOIN item i ON i.id = ts.itemFk LEFT JOIN item i ON i.id = ts.itemFk

View File

@ -42,7 +42,7 @@ BEGIN
JOIN item i ON i.id = ish.itemFk JOIN item i ON i.id = ish.itemFk
JOIN itemType it ON it.id = i.typeFk JOIN itemType it ON it.id = i.typeFk
JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
LEFT JOIN ( LEFT JOIN (
SELECT s.itemFk, sum(s.quantity) notPrepared SELECT s.itemFk, sum(s.quantity) notPrepared

View File

@ -1,6 +1,6 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_selfConsumption`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_selfConsumption`(
vShelvingFk VARCHAR(10) COLLATE utf8_general_ci, vShelvingCode VARCHAR(10) COLLATE utf8_general_ci,
vItemFk INT, vItemFk INT,
vQuantity INT vQuantity INT
) )
@ -9,9 +9,9 @@ BEGIN
* Leave the indicated amount on the shelve * Leave the indicated amount on the shelve
* and create a ticket with the difference. * and create a ticket with the difference.
* *
* @param vShelvingFk id of the shelve where the item is located. * @param vShelvingCode Code of the shelve where the item is located
* @param vItemFk article of which the self-consumption ticket is to be created. * @param vItemFk Item of which the self-consumption ticket is to be created
* @param vQuantity amount that will stay on the shelve * @param vQuantity Amount that will stay on the shelve
*/ */
DECLARE vVisible INT; DECLARE vVisible INT;
DECLARE vClientFk INT; DECLARE vClientFk INT;
@ -21,6 +21,11 @@ BEGIN
DECLARE vAgencyModeFk INT; DECLARE vAgencyModeFk INT;
DECLARE vItemShelvingFk INT; DECLARE vItemShelvingFk INT;
DECLARE vAddressFk INT; DECLARE vAddressFk INT;
DECLARE vShelvingFk INT;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code = vShelvingCode;
SELECT c.id, SELECT c.id,
pc.clientSelfConsumptionFk, pc.clientSelfConsumptionFk,
@ -37,7 +42,7 @@ BEGIN
JOIN parking p ON p.sectorFk = s.id JOIN parking p ON p.sectorFk = s.id
JOIN shelving s2 ON s2.parkingFk = p.id JOIN shelving s2 ON s2.parkingFk = p.id
JOIN productionConfig pc JOIN productionConfig pc
WHERE s2.code = vShelvingFk; WHERE s2.id = vShelvingFk;
IF vClientFk IS NULL THEN IF vClientFk IS NULL THEN
CALL util.throw('The company does not have a customer assigned'); CALL util.throw('The company does not have a customer assigned');
@ -47,7 +52,7 @@ BEGIN
CALL util.throw('The shelf cannot have NULL or negative quantities'); CALL util.throw('The shelf cannot have NULL or negative quantities');
END IF; END IF;
IF vShelvingFk IS NULL THEN IF vShelvingCode IS NULL THEN
CALL util.throw('The shelf is necessary'); CALL util.throw('The shelf is necessary');
END IF; END IF;

View File

@ -1,7 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_transfer`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_transfer`(
vItemShelvingFk INT, vItemShelvingFk INT,
vShelvingFk VARCHAR(10) vShelvingCode VARCHAR(10)
) )
BEGIN BEGIN
/** /**
@ -9,9 +9,14 @@ BEGIN
* fusionando si coincide el packing y la fecha. * fusionando si coincide el packing y la fecha.
* *
* @param vItemShelvingFk Identificador de itemShelving * @param vItemShelvingFk Identificador de itemShelving
* @param vShelvingFk Identificador de shelving * @param vShelvingCode Código de shelving
*/ */
DECLARE vNewItemShelvingFk INT; DECLARE vNewItemShelvingFk INT;
DECLARE vShelvingFk INT;
SELECT id INTO vShelvingFk
FROM shelving
WHERE code COLLATE utf8_unicode_ci = vShelvingCode;
SELECT MAX(ish.id) INTO vNewItemShelvingFk SELECT MAX(ish.id) INTO vNewItemShelvingFk
FROM itemShelving ish FROM itemShelving ish
@ -26,7 +31,7 @@ BEGIN
AND ish2.packing = ish.packing AND ish2.packing = ish.packing
AND DATE(ish2.created) = DATE(ish.created) AND DATE(ish2.created) = DATE(ish.created)
AND ish2.buyFk = ish.buyFk AND ish2.buyFk = ish.buyFk
WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci; WHERE ish.shelvingFk = vShelvingFk;
IF vNewItemShelvingFk THEN IF vNewItemShelvingFk THEN
UPDATE itemShelving ish UPDATE itemShelving ish
@ -38,9 +43,7 @@ BEGIN
DELETE FROM itemShelving DELETE FROM itemShelving
WHERE id = vItemShelvingFk; WHERE id = vItemShelvingFk;
ELSE ELSE
IF (SELECT EXISTS(SELECT id FROM shelving IF (SELECT EXISTS(SELECT id FROM shelving WHERE id = vShelvingFk)) THEN
WHERE code = vShelvingFk COLLATE utf8_unicode_ci)) THEN
UPDATE itemShelving UPDATE itemShelving
SET shelvingFk = vShelvingFk SET shelvingFk = vShelvingFk
WHERE id = vItemShelvingFk; WHERE id = vItemShelvingFk;

View File

@ -1,7 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_devalueA2`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_devalueA2`(
vSelf INT, vSelf INT,
vShelvingFK VARCHAR(10), vShelvingCode VARCHAR(10) COLLATE utf8mb3_general_ci,
vBuyingValue DECIMAL(10,4), vBuyingValue DECIMAL(10,4),
vQuantity INT vQuantity INT
) )
@ -12,7 +12,7 @@ BEGIN
* de almacén y shelvings correspondientes * de almacén y shelvings correspondientes
* *
* @param vSelf Id de artículo a devaluar * @param vSelf Id de artículo a devaluar
* @param vShelvingFK Ubicación actual del artículo * @param vShelvingCode Código de shelving / ubicación
* @param vBuyingValue Nuevo precio de coste * @param vBuyingValue Nuevo precio de coste
* @param vQuantity Cantidad del ítem a pasar a A2 * @param vQuantity Cantidad del ítem a pasar a A2
*/ */
@ -109,10 +109,11 @@ BEGIN
CALL util.throw ('The item has not a buy'); CALL util.throw ('The item has not a buy');
END IF; END IF;
SELECT id,visible INTO vTargetItemShelvingFk, vCurrentVisible SELECT ish.id, ish.visible INTO vTargetItemShelvingFk, vCurrentVisible
FROM itemShelving FROM itemShelving ish
WHERE shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci JOIN shelving sh ON sh.id = ish.shelvingFk
AND itemFk = vSelf WHERE sh.code = vShelvingCode
AND ish.itemFk = vSelf
LIMIT 1; LIMIT 1;
IF vCurrentVisible IS NULL THEN IF vCurrentVisible IS NULL THEN
@ -388,16 +389,17 @@ BEGIN
userFk, userFk,
isChecked) isChecked)
SELECT vItemA2Fk, SELECT vItemA2Fk,
shelvingFk, ish.shelvingFk,
vQuantity , vQuantity ,
`grouping`, ish.`grouping`,
packing, ish.packing,
packagingFk, ish.packagingFk,
account.myUser_getId(), account.myUser_getId(),
isChecked ish.isChecked
FROM itemShelving FROM itemShelving ish
WHERE itemFK = vSelf JOIN shelving sh ON sh.id = ish.shelvingFk
AND shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci WHERE ish.itemFK = vSelf
AND sh.code = vShelvingCode
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
visible = vQuantity + VALUES(visible); visible = vQuantity + VALUES(visible);

View File

@ -217,7 +217,7 @@ proc: BEGIN
st.code = 'previousPrepared' isPreviousPrepared, st.code = 'previousPrepared' isPreviousPrepared,
sc.itemPackingTypeFk sc.itemPackingTypeFk
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector sc ON sc.id = p.sectorFk JOIN sector sc ON sc.id = p.sectorFk
JOIN sectorType st ON st.id = sc.typeFk JOIN sectorType st ON st.id = sc.typeFk

View File

@ -27,7 +27,7 @@ BEGIN
DECLARE vQuantity INT; DECLARE vQuantity INT;
DECLARE vRemainder INT DEFAULT 0; DECLARE vRemainder INT DEFAULT 0;
DECLARE vRemainderSaleFk INT; DECLARE vRemainderSaleFk INT;
DECLARE vShelving VARCHAR(10); DECLARE vShelvingFk VARCHAR(10);
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
SELECT s.quantity, SELECT s.quantity,
@ -74,7 +74,7 @@ w1: WHILE vQuantity >= vPacking DO
p.pickingOrder, p.pickingOrder,
ish.created ish.created
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
LEFT JOIN itemShelvingSale iss LEFT JOIN itemShelvingSale iss
ON iss.itemShelvingFk = ish.id ON iss.itemShelvingFk = ish.id
@ -262,9 +262,9 @@ w1: WHILE vQuantity >= vPacking DO
CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE); CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE);
SELECT shelvingFk, p.code SELECT shelvingFk, p.code
INTO vShelving, vParkingCode INTO vShelvingFk, vParkingCode
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
WHERE ish.id = vItemShelvingFk; WHERE ish.id = vItemShelvingFk;
@ -273,7 +273,7 @@ w1: WHILE vQuantity >= vPacking DO
itemFk = vItemFk, itemFk = vItemFk,
quantity = vPacking, quantity = vPacking,
longName = vConcept, longName = vConcept,
shelvingFk = vShelving, shelvingFk = vShelvingFk,
parkingCode = vParkingCode, parkingCode = vParkingCode,
phone = RIGHT(phone,vMaxPhoneLength), phone = RIGHT(phone,vMaxPhoneLength),
street = RIGHT(street, vMAxStreetLength) street = RIGHT(street, vMAxStreetLength)

View File

@ -41,7 +41,7 @@ BEGIN
AND iss.created >= vDated AND iss.created >= vDated
GROUP BY iss.itemShelvingFk, s.itemFk) tISS GROUP BY iss.itemShelvingFk, s.itemFk) tISS
ON tISS.itemFk = ish.itemFk AND tISS.itemShelvingFk = ish.id ON tISS.itemFk = ish.itemFk AND tISS.itemShelvingFk = ish.id
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk
JOIN agencyMode am ON am.id = pb.agencyModeFk JOIN agencyMode am ON am.id = pb.agencyModeFk

View File

@ -87,7 +87,7 @@ BEGIN
SUM(ish.visible) visible, SUM(ish.visible) visible,
s.warehouseFk warehouseFk s.warehouseFk warehouseFk
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk JOIN sector s ON s.id = p.sectorFk
GROUP BY ish.itemFk, s.warehouseFk; GROUP BY ish.itemFk, s.warehouseFk;

View File

@ -1,11 +1,13 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelvingChange`(IN `vShelvingO` VARCHAR(8), IN `vShelvingD` VARCHAR(8)) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelvingChange`(
`vShelvingO` VARCHAR(10),
`vShelvingD` VARCHAR(10)
)
BEGIN BEGIN
UPDATE itemShelving ish
UPDATE vn.itemShelving JOIN shelving sh1 ON sh1.code = vShelvingD COLLATE utf8_unicode_ci
SET shelvingFk = vShelvingD COLLATE utf8_unicode_ci JOIN shelving sh2 ON sh2.code = vShelvingO COLLATE utf8_unicode_ci
WHERE shelvingFk = vShelvingO COLLATE utf8_unicode_ci; SET ish.shelvingFk = sh1.id
WHERE ish.shelvingFk = sh2.id;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,8 +1,10 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelvingParking_get`(vShelvingFk VARCHAR(10), vWarehouseFk INT, vDayRange INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelvingParking_get`(
BEGIN vShelvingCode VARCHAR(10),
vWarehouseFk INT,
vDayRange INT
)
BEGIN
SELECT s.itemFk, SELECT s.itemFk,
s.concept, s.concept,
CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir, CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir,
@ -10,14 +12,15 @@ SELECT s.itemFk,
FROM vn.sale s FROM vn.sale s
LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk AND ist.warehouseFk = vWarehouseFk LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk
JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk AND ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci AND ist.warehouseFk = vWarehouseFk
JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk
JOIN shelving sh ON sh.id = ish.shelvingFk
AND sh.code = vShelvingCode COLLATE utf8_general_ci
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE()))
AND iss.saleFk IS NULL AND iss.saleFk IS NULL
AND t.warehouseFk = vWarehouseFk AND t.warehouseFk = vWarehouseFk
GROUP BY s.itemFk GROUP BY s.itemFk
HAVING sinServir > aparcado; HAVING sinServir > aparcado;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -12,12 +12,12 @@ BEGIN
DELETE ish.* DELETE ish.*
FROM itemShelving ish FROM itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
WHERE sh.parkingFk IS NULL WHERE sh.parkingFk IS NULL
AND ish.created < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); AND ish.created < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
UPDATE shelving sh UPDATE shelving sh
LEFT JOIN itemShelving its ON its.shelvingFk = sh.`code` LEFT JOIN itemShelving its ON its.shelvingFk = sh.id
SET isPrinted = 0, SET isPrinted = 0,
parkingFk = NULL parkingFk = NULL
WHERE its.id IS NULL WHERE its.id IS NULL
@ -27,11 +27,11 @@ UPDATE shelving sh
OR OR
sh.parked < util.VN_CURDATE() - INTERVAL 2 WEEK sh.parked < util.VN_CURDATE() - INTERVAL 2 WEEK
) )
AND IF(code REGEXP '^[A-Za-z]{2}[0-9]', LEFT (code, 2) NOT IN ( AND IF(code REGEXP '^[A-Za-z]{2}[0-9]', LEFT (code, 2) NOT IN (
SELECT DISTINCT LEFT(its.shelvingFk, 2) SELECT DISTINCT LEFT(sh.code, 2)
FROM itemShelving its FROM itemShelving its
WHERE its.shelvingFk REGEXP '^[A-Za-z]{2}[0-9]' JOIN shelving sh ON sh.id = its.shelvingFk
WHERE sh.code REGEXP '^[A-Za-z]{2}[0-9]'
), TRUE); ), TRUE);
END$$ END$$

View File

@ -25,7 +25,7 @@ BEGIN
LEFT JOIN ( LEFT JOIN (
SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.sector s ON s.id = p.sectorFk
WHERE s.code = 'FUENTES_PICASSE' WHERE s.code = 'FUENTES_PICASSE'
@ -68,7 +68,7 @@ BEGIN
sh.isSpam sh.isSpam
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.item i ON i.id = ish.itemFk JOIN vn.item i ON i.id = ish.itemFk
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.warehouse w ON w.id = s.warehouseFk JOIN vn.warehouse w ON w.id = s.warehouseFk

View File

@ -9,7 +9,7 @@ BEGIN
JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
JOIN vn.itemShelving ish ON ish.id = iss.itemShelvingFk JOIN vn.itemShelving ish ON ish.id = iss.itemShelvingFk
JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
WHERE p.sectorFk = vSectorFk WHERE p.sectorFk = vSectorFk
) sub ON sub.id = td.ticketFk ) sub ON sub.id = td.ticketFk

View File

@ -27,7 +27,7 @@ BEGIN
SUM(ish.visible) visible, SUM(ish.visible) visible,
s.warehouseFk warehouseFk s.warehouseFk warehouseFk
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk JOIN sector s ON s.id = p.sectorFk
GROUP BY ish.itemFk, GROUP BY ish.itemFk,

View File

@ -28,7 +28,7 @@ BEGIN
SUM(ish.visible) visible, SUM(ish.visible) visible,
s.warehouseFk warehouseFk s.warehouseFk warehouseFk
FROM itemShelving ish FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.id = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk JOIN sector s ON s.id = p.sectorFk
GROUP BY ish.itemFk, GROUP BY ish.itemFk,

View File

@ -15,7 +15,7 @@ FROM (
( (
( (
`vn`.`itemShelving` `ish` `vn`.`itemShelving` `ish`
JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) JOIN `vn`.`shelving` `sh` ON(`sh`.`id` = `ish`.`shelvingFk`)
) )
JOIN `vn`.`item` `i` ON(`i`.`id` = `ish`.`itemFk`) JOIN `vn`.`item` `i` ON(`i`.`id` = `ish`.`itemFk`)
) )

View File

@ -18,7 +18,7 @@ FROM (
( (
( (
`vn`.`itemShelving` `ish` `vn`.`itemShelving` `ish`
JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) JOIN `vn`.`shelving` `sh` ON(`sh`.`id` = `ish`.`shelvingFk`)
) )
LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`)
) )

View File

@ -13,7 +13,7 @@ FROM (
`vn`.`itemShelvingSale` `iss` `vn`.`itemShelvingSale` `iss`
JOIN `vn`.`itemShelving` `ish` ON(`ish`.`id` = `iss`.`itemShelvingFk`) JOIN `vn`.`itemShelving` `ish` ON(`ish`.`id` = `iss`.`itemShelvingFk`)
) )
JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) JOIN `vn`.`shelving` `sh` ON(`sh`.`id` = `ish`.`shelvingFk`)
) )
JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`)
) )

View File

@ -21,7 +21,7 @@ FROM (
( (
( (
`vn`.`itemShelving` `ish` `vn`.`itemShelving` `ish`
LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`id` = `ish`.`shelvingFk`)
) )
LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`)
) )

View File

@ -19,7 +19,7 @@ FROM (
( (
( (
`vn`.`itemShelving` `ish` `vn`.`itemShelving` `ish`
JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) JOIN `vn`.`shelving` `sh` ON(`sh`.`id` = `ish`.`shelvingFk`)
) )
JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`)
) )

View File

@ -0,0 +1,20 @@
CREATE OR REPLACE TEMPORARY TABLE tItemShelving
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT ish.id, s.id shelvingFk
FROM shelving s
JOIN itemShelving ish ON ish.shelvingFk = s.code COLLATE utf8mb3_unicode_ci;
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2,
MODIFY COLUMN shelvingFk int(11) NOT NULL;
UPDATE itemShelving ish
JOIN tItemShelving tish ON tish.id = ish.id
SET ish.shelvingFk = tish.shelvingFk;
DROP TEMPORARY TABLE tItemShelving;
ALTER TABLE vn.itemShelving
ADD CONSTRAINT itemShelving_shelving_FK FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(id)
ON DELETE RESTRICT
ON UPDATE CASCADE;

View File

@ -0,0 +1,14 @@
CREATE OR REPLACE TEMPORARY TABLE tItemShelvingLog
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT ishl.id, s.id shelvingFk
FROM shelving s
JOIN itemShelvingLog ishl ON ishl.shelvingFk = s.code COLLATE utf8mb3_unicode_ci;
ALTER TABLE vn.itemShelvingLog MODIFY COLUMN shelvingFk int(11) NOT NULL;
UPDATE itemShelvingLog ishl
JOIN tItemShelvingLog tishl ON tishl.id = ishl.id
SET ishl.shelvingFk = tishl.shelvingFk;
DROP TEMPORARY TABLE tItemShelvingLog;

View File

@ -41,7 +41,7 @@ module.exports = Self => {
u.name u.name
FROM itemShelvingSale iss FROM itemShelvingSale iss
LEFT JOIN itemShelving ish ON iss.itemShelvingFk = ish.id LEFT JOIN itemShelving ish ON iss.itemShelvingFk = ish.id
LEFT JOIN shelving s ON ish.shelvingFk = s.code LEFT JOIN shelving s ON ish.shelvingFk = s.id
LEFT JOIN parking p ON s.parkingFk = p.id LEFT JOIN parking p ON s.parkingFk = p.id
LEFT JOIN account.user u ON u.id = iss.userFk` LEFT JOIN account.user u ON u.id = iss.userFk`
); );

View File

@ -3,7 +3,7 @@ module.exports = Self => {
description: 'Returns a list of items and possible alternative locations', description: 'Returns a list of items and possible alternative locations',
accessType: 'READ', accessType: 'READ',
accepts: [{ accepts: [{
arg: 'shelvingFk', arg: 'shelvingCode',
type: 'string', type: 'string',
required: true, required: true,
}], }],
@ -17,13 +17,21 @@ module.exports = Self => {
} }
}); });
Self.getAlternative = async(shelvingFk, options) => { Self.getAlternative = async(shelvingCode, options) => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const shelving = await models.Shelving.findOne({
where: {
code: shelvingCode
}
});
if (!shelving) return [];
const {id: shelvingFk} = shelving;
const filterItemShelvings = { const filterItemShelvings = {
fields: ['id', 'visible', 'itemFk', 'shelvingFk'], fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
where: {shelvingFk}, where: {shelvingFk},
@ -42,7 +50,7 @@ module.exports = Self => {
if (itemShelvings) { if (itemShelvings) {
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)', const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
[shelvingFk], myOptions [shelvingCode], myOptions
); );
return itemShelvings.map(itemShelving => { return itemShelvings.map(itemShelving => {
const item = itemShelving.item(); const item = itemShelving.item();

View File

@ -45,19 +45,19 @@ module.exports = Self => {
WITH tItemShelving AS( WITH tItemShelving AS(
SELECT is2.itemFk, is2.created, p.sectorFK, is2.id SELECT is2.itemFk, is2.created, p.sectorFK, is2.id
FROM vn.itemShelving is2 FROM vn.itemShelving is2
JOIN vn.shelving sh ON sh.code = is2.shelvingFk JOIN vn.shelving sh ON sh.id = is2.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.productionConfig pc JOIN vn.productionConfig pc
WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode WHERE sh.code = ? AND s.code = pc.sectorFromCode
), tItemInSector AS ( ), tItemInSector AS (
SELECT is2.itemFk, is2.created, is2.shelvingFk SELECT is2.itemFk, is2.created, is2.shelvingFk
FROM vn.itemShelving is2 FROM vn.itemShelving is2
JOIN vn.shelving sh ON sh.code = is2.shelvingFk JOIN vn.shelving sh ON sh.id = is2.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.sector s ON s.id = p.sectorFk
JOIN vn.productionConfig pc JOIN vn.productionConfig pc
WHERE is2.shelvingFk <> ? WHERE sh.code <> ?
AND s.code = pc.sectorFromCode) AND s.code = pc.sectorFromCode)
SELECT ti.itemFK, tis.shelvingFk SELECT ti.itemFK, tis.shelvingFk
FROM tItemShelving ti FROM tItemShelving ti

View File

@ -5,7 +5,7 @@ describe('itemShelving updateFromSale()', () => {
const tx = await models.ItemBarcode.beginTransaction({}); const tx = await models.ItemBarcode.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
const saleFk = 2; const saleFk = 2;
const filter = {where: {itemFk: 4, shelvingFk: 'HEJ'} const filter = {where: {itemFk: 4, shelvingFk: 12}
}; };
try { try {
const {visible: visibleBefore} = await models.ItemShelving.findOne(filter, options); const {visible: visibleBefore} = await models.ItemShelving.findOne(filter, options);

View File

@ -18,22 +18,31 @@ describe('ItemShelving upsertItem()', () => {
}); });
it('should add two new records', async() => { it('should add two new records', async() => {
const shelvingFk = 'GVC'; const shelvingCode = 'GVC';
const items = [1, 1, 1, 2]; const items = [1, 1, 1, 2];
const {id: shelvingFk} = await models.Shelving.findOne({
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); where: {
code: shelvingCode
}
});
await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
expect(itemShelvings.length).toEqual(2); expect(itemShelvings.length).toEqual(2);
}); });
it('should update the visible items', async() => { it('should update the visible items', async() => {
const shelvingFk = 'GVC'; const shelvingCode = 'GVC';
const items = [2, 2]; const items = [2, 2];
const {id: shelvingFk} = await models.Shelving.findOne({
where: {
code: shelvingCode
}
});
const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({ const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]} where: {shelvingFk, itemFk: items[0]}
}, options); }, options);
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({ const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]} where: {shelvingFk, itemFk: items[0]}

View File

@ -57,8 +57,7 @@
"shelving": { "shelving": {
"type": "belongsTo", "type": "belongsTo",
"model": "Shelving", "model": "Shelving",
"foreignKey": "shelvingFk", "foreignKey": "shelvingFk"
"primaryKey": "code"
} }
} }
} }