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
|
||||
/**
|
||||
* Comprueba si existe un ticket de autoconsumo ese mismo día
|
||||
* si no lo está lo crea, y añade la caja utilizada.
|
||||
*
|
||||
* Comprueba si existe un ticket de cajas autoconsumo ese mismo día,
|
||||
* si no lo está lo crea y añade la caja utilizada.
|
||||
*
|
||||
* @param vSelf Id de expedición
|
||||
*/
|
||||
DECLARE vCurdate DATE;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vAddressFk INT;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vItemName VARCHAR(50);
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vCurdate DATE;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vSaleFk INT;
|
||||
|
||||
SET vCurdate = util.VN_CURDATE();
|
||||
|
||||
SELECT clientSelfConsumptionFk, addressSelfConsumptionFk
|
||||
INTO vClientFk, vAddressFk
|
||||
FROM productionConfig;
|
||||
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;
|
||||
|
||||
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
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
WHERE e.id = vSelf;
|
||||
SET vCurdate = util.VN_CURDATE();
|
||||
|
||||
SELECT id INTO vTicketFk
|
||||
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',
|
||||
`changedModelId` = OLD.id,
|
||||
`userFk` = account.myUser_getId();
|
||||
|
||||
CALL expedition_undoSelfConsumptionPackaging(OLD.id);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue