feat: refs #4948 Version expedition_undoSelfConsumptionPackaging
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
ab384e565c
commit
ad3b9ce365
|
@ -4,37 +4,42 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_doSelfCons
|
||||||
)
|
)
|
||||||
proc: BEGIN
|
proc: BEGIN
|
||||||
/**
|
/**
|
||||||
* Comprueba si existe un ticket de autoconsumo ese mismo día
|
* Comprueba si existe un ticket de cajas 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.
|
||||||
*
|
*
|
||||||
* @param vSelf Id de expedición
|
* @param vSelf Id de expedición
|
||||||
*/
|
*/
|
||||||
DECLARE vCurdate DATE;
|
|
||||||
DECLARE vClientFk INT;
|
DECLARE vClientFk INT;
|
||||||
DECLARE vAddressFk INT;
|
DECLARE vAddressFk INT;
|
||||||
DECLARE vTicketFk INT;
|
|
||||||
DECLARE vItemFk INT;
|
DECLARE vItemFk INT;
|
||||||
DECLARE vItemName VARCHAR(50);
|
DECLARE vItemName VARCHAR(50);
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
|
DECLARE vCurdate DATE;
|
||||||
|
DECLARE vTicketFk INT;
|
||||||
DECLARE vSaleFk INT;
|
DECLARE vSaleFk INT;
|
||||||
|
|
||||||
SET vCurdate = util.VN_CURDATE();
|
SELECT pc.clientSelfConsumptionFk,
|
||||||
|
pc.addressSelfConsumptionFk,
|
||||||
SELECT clientSelfConsumptionFk, addressSelfConsumptionFk
|
i.id,
|
||||||
INTO vClientFk, vAddressFk
|
i.name,
|
||||||
FROM productionConfig;
|
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
|
IF vClientFk IS NULL OR vAddressFk IS NULL THEN
|
||||||
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, i.name, t.warehouseFk
|
SET vCurdate = util.VN_CURDATE();
|
||||||
INTO 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
|
|
||||||
WHERE e.id = vSelf;
|
|
||||||
|
|
||||||
SELECT id INTO vTicketFk
|
SELECT id INTO vTicketFk
|
||||||
FROM ticket
|
FROM ticket
|
|
@ -0,0 +1,69 @@
|
||||||
|
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 ;
|
|
@ -8,5 +8,7 @@ BEGIN
|
||||||
`changedModel` = 'Expedition',
|
`changedModel` = 'Expedition',
|
||||||
`changedModelId` = OLD.id,
|
`changedModelId` = OLD.id,
|
||||||
`userFk` = account.myUser_getId();
|
`userFk` = account.myUser_getId();
|
||||||
|
|
||||||
|
CALL expedition_undoSelfConsumptionPackaging(OLD.id);
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue