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

This commit is contained in:
Robert Ferrús 2024-08-06 07:20:30 +02:00
parent bb36667616
commit 5f63017853
3 changed files with 39 additions and 34 deletions

View File

@ -15,7 +15,7 @@ BEGIN
DELETE FROM bs.ventas_contables
WHERE year = vYear
AND month = vMonth;
AND month = vMonth;
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
CREATE TEMPORARY TABLE tmp.ticket_list

View File

@ -34,14 +34,14 @@ BEGIN
read_loop: LOOP
SET vDone = FALSE;
FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers;
IF vDone THEN
LEAVE read_loop;
END IF;
IF vIshStickers = vBuyStickers THEN
IF vIshStickers = vBuyStickers THEN
UPDATE buy
SET entryFk = vToEntryFk
WHERE id = vBuyFk;

View File

@ -17,10 +17,11 @@ BEGIN
RESIGNAL;
END;
START TRANSACTION;
-- Clonar la entrada
CALL entry_clone(vOriginalEntry,vNewEntryFk);
START TRANSACTION;
-- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel.
INSERT INTO travel(
shipped,
@ -68,36 +69,38 @@ BEGIN
WHERE e.id = vOriginalEntry;
-- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones
CREATE OR REPLACE TEMPORARY TABLE tBuy
ENGINE = MEMORY
SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold
FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity
FROM buy b
WHERE b.entryFk = vOriginalEntry
GROUP BY b.itemFk
) tBuy
LEFT JOIN (
SELECT ish.itemFk, SUM(visible) visible
FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk
WHERE s.warehouseFk = vWarehouseFk
AND sh.parked = util.VN_CURDATE()
GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk
LEFT JOIN (
SELECT s.itemFk, SUM(s.quantity) sold
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN itemShelvingSale iss ON iss.saleFk = s.id
JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk
JOIN shelving s2 ON s2.code = is2.shelvingFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND s2.parked = util.VN_CURDATE()
GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk
WHERE visible = tBuy.totalQuantity
OR iss.itemFk IS NULL;
UPDATE buy b
JOIN (
SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold
FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity
FROM buy b
WHERE b.entryFk = vOriginalEntry
GROUP BY b.itemFk
) tBuy
LEFT JOIN (
SELECT ish.itemFk, SUM(visible) visible
FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk
WHERE s.warehouseFk = vWarehouseFk
AND sh.parked = util.VN_CURDATE()
GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk
LEFT JOIN (
SELECT s.itemFk, SUM(s.quantity) sold
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN itemShelvingSale iss ON iss.saleFk = s.id
JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk
JOIN shelving s2 ON s2.code = is2.shelvingFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND s2.parked = util.VN_CURDATE()
GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk
WHERE visible = tBuy.totalQuantity
OR iss.itemFk IS NULL
) sub ON sub.itemFk = b.itemFk
JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk
SET b.quantity = sub.totalQuantity - sub.visible - sub.sold
WHERE b.entryFk = vNewEntryFk;
@ -107,10 +110,12 @@ BEGIN
WHERE b.entryFk = vNewEntryFk
AND b.quantity = 0;
COMMIT;
SET vNewEntry = vNewEntryFk;
CALL cache.visible_refresh(@c,TRUE,7);
CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE());
COMMIT;
END$$
DELIMITER ;