Merge pull request 'feat: #7109 inventoryType' (!2409) from 7109-inventoryType into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2409
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Javi Gallego 2024-05-06 12:00:14 +00:00
commit 69766bbfeb
1 changed files with 16 additions and 15 deletions

View File

@ -21,7 +21,7 @@ BEGIN
SELECT id SELECT id
FROM warehouse FROM warehouse
WHERE isInventory; WHERE isInventory;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN BEGIN
ROLLBACK; ROLLBACK;
@ -38,18 +38,18 @@ BEGIN
INTO vMaxRecentInventories, INTO vMaxRecentInventories,
vWarehouseOutFkInventory, vWarehouseOutFkInventory,
vAgencyModeFkInventory vAgencyModeFkInventory
FROM inventoryConfig FROM inventoryConfig
LIMIT 1; LIMIT 1;
IF vDateLastInventory IS NULL IF vDateLastInventory IS NULL
OR vInventorySupplierFk IS NULL OR vInventorySupplierFk IS NULL
OR vMaxRecentInventories IS NULL OR vMaxRecentInventories IS NULL
OR vInventoryDate IS NULL OR vInventoryDate IS NULL
OR vWarehouseOutFkInventory IS NULL OR vWarehouseOutFkInventory IS NULL
OR vAgencyModeFkInventory IS NULL THEN OR vAgencyModeFkInventory IS NULL THEN
CALL util.throw('Some config parameters are not set'); CALL util.throw('Some config parameters are not set');
END IF; END IF;
START TRANSACTION; START TRANSACTION;
OPEN cWarehouses; OPEN cWarehouses;
@ -77,7 +77,7 @@ BEGIN
LIMIT 1; LIMIT 1;
IF vTravelFk IS NULL THEN IF vTravelFk IS NULL THEN
INSERT INTO travel INSERT INTO travel
SET warehouseOutFk = vWarehouseOutFkInventory, SET warehouseOutFk = vWarehouseOutFkInventory,
warehouseInFk = vWarehouseFk, warehouseInFk = vWarehouseFk,
shipped = vInventoryDate, shipped = vInventoryDate,
@ -94,15 +94,16 @@ BEGIN
SELECT id INTO vEntryFk SELECT id INTO vEntryFk
FROM entry FROM entry
WHERE supplierFk = vInventorySupplierFk WHERE supplierFk = vInventorySupplierFk
AND travelFk = vTravelFk; AND travelFk = vTravelFk
AND typeFk = 'inventory';
IF vEntryFk IS NULL THEN IF vEntryFk IS NULL THEN
INSERT INTO entry INSERT INTO entry
SET supplierFk = vInventorySupplierFk, SET supplierFk = vInventorySupplierFk,
isConfirmed = TRUE, isConfirmed = TRUE,
isOrdered = TRUE, isOrdered = TRUE,
travelFk = vTravelFk; travelFk = vTravelFk,
typeFk = 'inventory';
SELECT LAST_INSERT_ID() INTO vEntryFk; SELECT LAST_INSERT_ID() INTO vEntryFk;
ELSE ELSE
DELETE FROM buy WHERE entryFk = vEntryFk; DELETE FROM buy WHERE entryFk = vEntryFk;
@ -224,15 +225,15 @@ BEGIN
JOIN tInventory i2 ON i2.itemFk = i.id JOIN tInventory i2 ON i2.itemFk = i.id
SET i.lastUsed = NOW() SET i.lastUsed = NOW()
WHERE i2.quantity; WHERE i2.quantity;
DROP TEMPORARY TABLE tInventory; DROP TEMPORARY TABLE tInventory;
END LOOP; END LOOP;
CLOSE cWarehouses; CLOSE cWarehouses;
UPDATE config SET inventoried = vInventoryDate; UPDATE config SET inventoried = vInventoryDate;
CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete
(INDEX(entryId)) ENGINE = MEMORY (INDEX(entryId)) ENGINE = MEMORY
SELECT e.id entryId, SELECT e.id entryId,
@ -252,7 +253,7 @@ BEGIN
WHERE e.supplierFk = vInventorySupplierFk WHERE e.supplierFk = vInventorySupplierFk
AND t.shipped IN (sub.shipped); AND t.shipped IN (sub.shipped);
DELETE e DELETE e
FROM `entry` e FROM `entry` e
JOIN tEntryToDelete tmp ON tmp.entryId = e.id; JOIN tEntryToDelete tmp ON tmp.entryId = e.id;