feat: refs #4948 Version expedition_doSelfConsumptionPackaging
gitea/salix/pipeline/pr-dev Build queued... Details

This commit is contained in:
Guillermo Bonet 2024-11-07 12:21:51 +01:00
parent 9c2f3903a2
commit c9f8788ef4
1 changed files with 18 additions and 13 deletions

View File

@ -1,8 +1,8 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_doSelfConsumptionPackaging`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_doSelfConsumptionPackaging`(
vSelf DATE, vSelf INT
) )
BEGIN proc: BEGIN
/** /**
* Comprueba si existe un ticket de autoconsumo ese mismo día * Comprueba si existe un ticket de autoconsumo ese mismo día
* si no lo está lo crea, y añade la caja utilizada. * si no lo está lo crea, y añade la caja utilizada.
@ -15,7 +15,8 @@ BEGIN
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE vItemFk INT; DECLARE vItemFk INT;
DECLARE vItemName VARCHAR(50); DECLARE vItemName VARCHAR(50);
DECLARE vExists BOOL; DECLARE vWarehouseFk INT;
DECLARE vSaleFk INT;
SET vCurdate = util.VN_CURDATE(); SET vCurdate = util.VN_CURDATE();
@ -27,8 +28,8 @@ BEGIN
CALL util.throw('Some config parameters are not set'); CALL util.throw('Some config parameters are not set');
END IF; END IF;
SELECT i.id, t.warehouseFk, i.name SELECT i.id, i.name, t.warehouseFk
INTO vItemFk, vWarehouseFk, vItemName INTO vItemFk, vItemName, vWarehouseFk
FROM expedition e FROM expedition e
JOIN packaging p ON p.id = e.packagingFk JOIN packaging p ON p.id = e.packagingFk
JOIN item i ON i.id = p.itemFk JOIN item i ON i.id = p.itemFk
@ -47,17 +48,21 @@ BEGIN
SELECT vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk; SELECT vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk;
SET vTicketFk = LAST_INSERT_ID(); SET vTicketFk = LAST_INSERT_ID();
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
SELECT vItemFk, vTicketFk, vItemName, 1;
ELSE ELSE
SELECT id INTO vExists SELECT id INTO vSaleFk
FROM sale FROM sale
WHERE itemFk = vItemFk WHERE itemFk = vItemFk
AND ticketFk = vTicketFk; AND ticketFk = vTicketFk;
-- Comprobar si existe o no y si existe, sumar +1 la quantity, si no, lo creamos
IF vSaleFk NOT IS NULL THEN
UPDATE sale
SET quantity = quantity + 1
WHERE id = vSaleFk;
LEAVE proc;
END IF;
END IF; END IF;
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
SELECT vItemFk, vTicketFk, vItemName, 1;
END$$ END$$
DELIMITER ; DELIMITER ;