feat: refs #4948 Requested changes
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
ad3b9ce365
commit
927e837a29
|
@ -1,11 +1,12 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_doSelfConsumptionPackaging`(
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_selfConsumptionPackaging`(
|
||||||
vSelf INT
|
vSelf INT,
|
||||||
|
vAction ENUM('add', 'remove')
|
||||||
)
|
)
|
||||||
proc: BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Comprueba si existe un ticket de cajas autoconsumo ese mismo día,
|
* Maneja el consumo de cajas para autoconsumo, permitiendo
|
||||||
* si no lo está lo crea y añade la caja utilizada.
|
* añadir o quitar cajas utilizadas según la acción indicada.
|
||||||
*
|
*
|
||||||
* @param vSelf Id de expedición
|
* @param vSelf Id de expedición
|
||||||
*/
|
*/
|
||||||
|
@ -14,20 +15,27 @@ proc: BEGIN
|
||||||
DECLARE vItemFk INT;
|
DECLARE vItemFk INT;
|
||||||
DECLARE vItemName VARCHAR(50);
|
DECLARE vItemName VARCHAR(50);
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
DECLARE vCurdate DATE;
|
DECLARE vCreated DATE;
|
||||||
DECLARE vTicketFk INT;
|
DECLARE vTicketFk INT;
|
||||||
DECLARE vSaleFk INT;
|
DECLARE vSaleFk INT;
|
||||||
|
DECLARE vQuantity INT;
|
||||||
|
|
||||||
|
IF vAction NOT IN ('add', 'remove') THEN
|
||||||
|
CALL util.throw('Action not supported');
|
||||||
|
END IF;
|
||||||
|
|
||||||
SELECT pc.clientSelfConsumptionFk,
|
SELECT pc.clientSelfConsumptionFk,
|
||||||
pc.addressSelfConsumptionFk,
|
pc.addressSelfConsumptionFk,
|
||||||
i.id,
|
i.id,
|
||||||
i.name,
|
i.name,
|
||||||
t.warehouseFk
|
t.warehouseFk,
|
||||||
|
e.created
|
||||||
INTO vClientFk,
|
INTO vClientFk,
|
||||||
vAddressFk,
|
vAddressFk,
|
||||||
vItemFk,
|
vItemFk,
|
||||||
vItemName,
|
vItemName,
|
||||||
vWarehouseFk
|
vWarehouseFk,
|
||||||
|
vCreated
|
||||||
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
|
||||||
|
@ -39,35 +47,47 @@ proc: BEGIN
|
||||||
CALL util.throw('Some config parameters are not set');
|
CALL util.throw('Some config parameters are not set');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SET vCurdate = util.VN_CURDATE();
|
SET vCreated = DATE(vCreated);
|
||||||
|
|
||||||
SELECT id INTO vTicketFk
|
SELECT id INTO vTicketFk
|
||||||
FROM ticket
|
FROM ticket
|
||||||
WHERE shipped BETWEEN vCurdate AND util.dayEnd(vCurdate)
|
WHERE shipped BETWEEN vCreated AND util.dayEnd(vCreated)
|
||||||
AND clientFk = vClientFk
|
AND clientFk = vClientFk
|
||||||
AND addressFk = vAddressFk
|
AND addressFk = vAddressFk
|
||||||
AND warehouseFk = vWarehouseFk;
|
AND warehouseFk = vWarehouseFk;
|
||||||
|
|
||||||
IF vTicketFk IS NULL THEN
|
IF vTicketFk IS NULL AND vAction = 'add' THEN
|
||||||
INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
|
INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
|
||||||
SELECT vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk;
|
VALUES (vClientFk, vWarehouseFk, vCreated, 'CAJAS AUTOCONSUMO', vAddressFk);
|
||||||
|
|
||||||
SET vTicketFk = LAST_INSERT_ID();
|
SET vTicketFk = LAST_INSERT_ID();
|
||||||
ELSE
|
END IF;
|
||||||
SELECT id INTO vSaleFk
|
|
||||||
FROM sale
|
|
||||||
WHERE itemFk = vItemFk
|
|
||||||
AND ticketFk = vTicketFk;
|
|
||||||
|
|
||||||
|
SELECT id, quantity INTO vSaleFk, vQuantity
|
||||||
|
FROM sale
|
||||||
|
WHERE itemFk = vItemFk
|
||||||
|
AND ticketFk = vTicketFk
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF vAction = 'add' THEN
|
||||||
IF vSaleFk IS NOT NULL THEN
|
IF vSaleFk IS NOT NULL THEN
|
||||||
UPDATE sale
|
UPDATE sale
|
||||||
SET quantity = quantity + 1
|
SET quantity = quantity + 1
|
||||||
WHERE id = vSaleFk;
|
WHERE id = vSaleFk;
|
||||||
LEAVE proc;
|
ELSE
|
||||||
|
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
|
||||||
|
VALUES (vItemFk, vTicketFk, vItemName, 1);
|
||||||
|
END IF;
|
||||||
|
ELSE
|
||||||
|
IF vSaleFk IS NOT NULL THEN
|
||||||
|
IF vQuantity > 1 THEN
|
||||||
|
UPDATE sale
|
||||||
|
SET quantity = quantity - 1
|
||||||
|
WHERE id = vSaleFk;
|
||||||
|
ELSE
|
||||||
|
DELETE FROM sale WHERE id = vSaleFk;
|
||||||
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
|
|
||||||
SELECT vItemFk, vTicketFk, vItemName, 1;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -1,69 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_undoSelfConsumptionPackaging`(
|
|
||||||
vSelf INT
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Comprueba si existe un ticket de cajas autoconsumo ese mismo día,
|
|
||||||
* si lo está quita la caja utilizada.
|
|
||||||
*
|
|
||||||
* @param vSelf Id de expedición
|
|
||||||
*/
|
|
||||||
DECLARE vClientFk INT;
|
|
||||||
DECLARE vAddressFk INT;
|
|
||||||
DECLARE vItemFk INT;
|
|
||||||
DECLARE vItemName VARCHAR(50);
|
|
||||||
DECLARE vWarehouseFk INT;
|
|
||||||
DECLARE vCurdate DATE;
|
|
||||||
DECLARE vTicketFk INT;
|
|
||||||
DECLARE vSaleFk INT;
|
|
||||||
DECLARE vQuantity INT;
|
|
||||||
|
|
||||||
SELECT pc.clientSelfConsumptionFk,
|
|
||||||
pc.addressSelfConsumptionFk,
|
|
||||||
i.id,
|
|
||||||
i.name,
|
|
||||||
t.warehouseFk
|
|
||||||
INTO vClientFk,
|
|
||||||
vAddressFk,
|
|
||||||
vItemFk,
|
|
||||||
vItemName,
|
|
||||||
vWarehouseFk
|
|
||||||
FROM expedition e
|
|
||||||
JOIN packaging p ON p.id = e.packagingFk
|
|
||||||
JOIN item i ON i.id = p.itemFk
|
|
||||||
JOIN ticket t ON t.id = e.ticketFk
|
|
||||||
JOIN productionConfig pc
|
|
||||||
WHERE e.id = vSelf;
|
|
||||||
|
|
||||||
IF vClientFk IS NULL OR vAddressFk IS NULL THEN
|
|
||||||
CALL util.throw('Some config parameters are not set');
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SET vCurdate = util.VN_CURDATE();
|
|
||||||
|
|
||||||
SELECT id INTO vTicketFk
|
|
||||||
FROM ticket
|
|
||||||
WHERE shipped BETWEEN vCurdate AND util.dayEnd(vCurdate)
|
|
||||||
AND clientFk = vClientFk
|
|
||||||
AND addressFk = vAddressFk
|
|
||||||
AND warehouseFk = vWarehouseFk;
|
|
||||||
|
|
||||||
IF vTicketFk IS NOT NULL THEN
|
|
||||||
SELECT id, quantity INTO vSaleFk, vQuantity
|
|
||||||
FROM sale
|
|
||||||
WHERE itemFk = vItemFk
|
|
||||||
AND ticketFk = vTicketFk;
|
|
||||||
|
|
||||||
IF vSaleFk IS NOT NULL THEN
|
|
||||||
IF vQuantity <= 1 THEN
|
|
||||||
DELETE FROM sale WHERE id = vSaleFk;
|
|
||||||
ELSE
|
|
||||||
UPDATE sale
|
|
||||||
SET quantity = quantity - 1
|
|
||||||
WHERE id = vSaleFk;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -9,6 +9,6 @@ BEGIN
|
||||||
`changedModelId` = OLD.id,
|
`changedModelId` = OLD.id,
|
||||||
`userFk` = account.myUser_getId();
|
`userFk` = account.myUser_getId();
|
||||||
|
|
||||||
CALL expedition_undoSelfConsumptionPackaging(OLD.id);
|
CALL expedition_selfConsumptionPackaging(OLD.id, 'remove');
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue