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 $$
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
* si no lo está lo crea, y añade la caja utilizada.
@ -15,7 +15,8 @@ BEGIN
DECLARE vTicketFk INT;
DECLARE vItemFk INT;
DECLARE vItemName VARCHAR(50);
DECLARE vExists BOOL;
DECLARE vWarehouseFk INT;
DECLARE vSaleFk INT;
SET vCurdate = util.VN_CURDATE();
@ -27,8 +28,8 @@ BEGIN
CALL util.throw('Some config parameters are not set');
END IF;
SELECT i.id, t.warehouseFk, i.name
INTO vItemFk, vWarehouseFk, vItemName
SELECT i.id, i.name, t.warehouseFk
INTO vItemFk, vItemName, vWarehouseFk
FROM expedition e
JOIN packaging p ON p.id = e.packagingFk
JOIN item i ON i.id = p.itemFk
@ -47,17 +48,21 @@ BEGIN
SELECT vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk;
SET vTicketFk = LAST_INSERT_ID();
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
SELECT vItemFk, vTicketFk, vItemName, 1;
ELSE
SELECT id INTO vExists
SELECT id INTO vSaleFk
FROM sale
WHERE itemFk = vItemFk
AND ticketFk = vTicketFk;
-- Comprobar si existe o no y si existe, sumar +1 la quantity, si no, lo creamos
WHERE itemFk = vItemFk
AND ticketFk = vTicketFk;
IF vSaleFk NOT IS NULL THEN
UPDATE sale
SET quantity = quantity + 1
WHERE id = vSaleFk;
LEAVE proc;
END IF;
END IF;
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
SELECT vItemFk, vTicketFk, vItemName, 1;
END$$
DELIMITER ;