feat: refs #6822 change request
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Robert Ferrús 2024-11-28 08:13:53 +01:00
parent 7b8d4c6a2c
commit 4b474834cf
2 changed files with 59 additions and 43 deletions

View File

@ -1,10 +1,14 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT, OUT newEntryFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(
vSelf INT,
OUT newEntryFk INT
)
BEGIN BEGIN
/** /**
* clones an entry. * clones an entry.
* *
* @param vSelf The entry id * @param vSelf The entry id
* @param newEntryFk Output parameter of the new created input
*/ */
DECLARE vNewEntryFk INT; DECLARE vNewEntryFk INT;

View File

@ -1,10 +1,14 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(
vOriginalEntry INT,
OUT vNewEntry INT
)
BEGIN BEGIN
/** /**
* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén * Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén
* *
* @param vOriginalEntry entrada que se quiera adelantar * @param vOriginalEntry entrada que se quiera adelantar
* @param vNewEntry nueva entrada creada
*/ */
DECLARE vNewEntryFk INT; DECLARE vNewEntryFk INT;
DECLARE vTravelFk INT; DECLARE vTravelFk INT;
@ -15,9 +19,9 @@ BEGIN
ROLLBACK; ROLLBACK;
RESIGNAL; RESIGNAL;
END; END;
-- Clonar la entrada -- Clonar la entrada
CALL entry_clone(vOriginalEntry,vNewEntryFk); CALL entry_clone(vOriginalEntry, vNewEntryFk);
START TRANSACTION; START TRANSACTION;
@ -33,7 +37,7 @@ BEGIN
SELECT util.VN_CURDATE(), SELECT util.VN_CURDATE(),
util.VN_CURDATE() + INTERVAL 1 DAY, util.VN_CURDATE() + INTERVAL 1 DAY,
t.warehouseInFk, t.warehouseInFk,
t.warehouseInFk, t.warehouseOutFk,
t.`ref`, t.`ref`,
t.isReceived, t.isReceived,
t.agencyModeFk t.agencyModeFk
@ -53,15 +57,15 @@ BEGIN
WHERE b.entryFk = vNewEntryFk; WHERE b.entryFk = vNewEntryFk;
-- Eliminar duplicados -- Eliminar duplicados
DELETE b.* DELETE b
FROM buy b FROM buy b
LEFT JOIN (SELECT b.id, b.itemFk LEFT JOIN (SELECT b.id, b.itemFk
FROM buy b FROM buy b
WHERE b.entryFk = vNewEntryFk WHERE b.entryFk = vNewEntryFk
GROUP BY b.itemFk) tBuy ON tBuy.id = b.id GROUP BY b.itemFk) tBuy ON tBuy.id = b.id
WHERE b.entryFk = vNewEntryFk WHERE b.entryFk = vNewEntryFk
AND tBuy.id IS NULL; AND tBuy.id IS NULL;
SELECT t.warehouseInFk INTO vWarehouseFk SELECT t.warehouseInFk INTO vWarehouseFk
FROM travel t FROM travel t
JOIN entry e ON e.travelFk = t.id JOIN entry e ON e.travelFk = t.id
@ -69,42 +73,50 @@ BEGIN
-- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones
CREATE OR REPLACE TEMPORARY TABLE tBuy CREATE OR REPLACE TEMPORARY TABLE tBuy
ENGINE = MEMORY WITH tBuy AS (
SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold SELECT b.itemFk, SUM(b.quantity) totalQuantity
FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity FROM buy b
FROM buy b WHERE b.entryFk = vOriginalEntry
WHERE b.entryFk = vOriginalEntry GROUP BY b.itemFk
GROUP BY b.itemFk ),
) tBuy itemShelvings AS (
LEFT JOIN ( SELECT ish.itemFk, SUM(visible) visible
SELECT ish.itemFk, SUM(visible) visible FROM itemShelving ish
FROM itemShelving ish JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN shelving sh ON sh.code = 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 AND sh.parked = util.VN_CURDATE()
AND sh.parked = util.VN_CURDATE() GROUP BY ish.itemFk
GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk ),
LEFT JOIN ( sales AS (
SELECT s.itemFk, SUM(s.quantity) sold SELECT s.itemFk, SUM(s.quantity) sold
FROM ticket t FROM ticket t
JOIN sale s ON s.ticketFk = t.id JOIN sale s ON s.ticketFk = t.id
JOIN itemShelvingSale iss ON iss.saleFk = s.id JOIN itemShelvingSale iss ON iss.saleFk = s.id
JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk
JOIN shelving s2 ON s2.code = is2.shelvingFk JOIN shelving s2 ON s2.code = is2.shelvingFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND s2.parked = util.VN_CURDATE() AND s2.parked = util.VN_CURDATE()
GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk GROUP BY s.itemFk
WHERE visible = tBuy.totalQuantity )
SELECT tmp.itemFk,
IFNULL(iss.visible, 0) visible,
tmp.totalQuantity,
IFNULL(s.sold, 0) sold
FROM tBuy tmp
LEFT JOIN itemShelvings iss ON tmp.itemFk = iss.itemFk
LEFT JOIN sales s ON s.itemFk = tmp.itemFk
WHERE visible = tmp.totalQuantity
OR iss.itemFk IS NULL; OR iss.itemFk IS NULL;
UPDATE buy b UPDATE buy b
JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk JOIN tBuy tmp ON tmp.itemFk = b.itemFk
SET b.quantity = sub.totalQuantity - sub.visible - sub.sold SET b.quantity = tmp.totalQuantity - tmp.visible - tmp.sold
WHERE b.entryFk = vNewEntryFk; WHERE b.entryFk = vNewEntryFk;
-- Limpia la nueva entrada -- Limpia la nueva entrada
DELETE b.* DELETE b
FROM buy b FROM buy b
WHERE b.entryFk = vNewEntryFk WHERE b.entryFk = vNewEntryFk
AND b.quantity = 0; AND b.quantity = 0;
@ -113,7 +125,7 @@ BEGIN
SET vNewEntry = vNewEntryFk; SET vNewEntry = vNewEntryFk;
CALL cache.visible_refresh(@c,TRUE,7); CALL cache.visible_refresh(@c,TRUE,vWarehouseFk);
CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE());
END$$ END$$
DELIMITER ; DELIMITER ;