Compare commits

...

15 Commits

Author SHA1 Message Date
Guillermo Bonet 83ba2d29b3 feat: refs #4948 Minor change 2024-11-11 07:28:20 +01:00
Guillermo Bonet 019adc35f1 feat: refs #4948 Minor change 2024-11-11 07:23:47 +01:00
Guillermo Bonet 74f7fa0650 Merge branch 'dev' into 4948-procTicketSelfConsumption 2024-11-11 06:16:01 +00:00
Guillermo Bonet 927e837a29 feat: refs #4948 Requested changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-08 09:40:27 +01:00
Guillermo Bonet ad3b9ce365 feat: refs #4948 Version expedition_undoSelfConsumptionPackaging
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-07 12:57:31 +01:00
Guillermo Bonet ab384e565c Merge branch '4948-procTicketSelfConsumption' of https://gitea.verdnatura.es/verdnatura/salix into 4948-procTicketSelfConsumption
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-11-07 12:24:42 +01:00
Guillermo Bonet 73f1afda1f feat: refs #4948 Version expedition_doSelfConsumptionPackaging 2024-11-07 12:24:40 +01:00
Guillermo Bonet 005b698bbd Merge branch 'dev' into 4948-procTicketSelfConsumption
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-11-07 11:22:06 +00:00
Guillermo Bonet c9f8788ef4 feat: refs #4948 Version expedition_doSelfConsumptionPackaging
gitea/salix/pipeline/pr-dev Build queued... Details
2024-11-07 12:21:51 +01:00
Guillermo Bonet 9c2f3903a2 Merge branch '4948-procTicketSelfConsumption' of https://gitea.verdnatura.es/verdnatura/salix into 4948-procTicketSelfConsumption
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-10-29 14:25:07 +01:00
Guillermo Bonet 2e482d85ad feat: refs #4948 Version expedition_doSelfConsumptionPackaging 2024-10-29 14:25:06 +01:00
Guillermo Bonet 4db04f93d4 Merge branch 'dev' into 4948-procTicketSelfConsumption
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-29 12:55:04 +00:00
Guillermo Bonet 03b06b906e Merge branch 'dev' into 4948-procTicketSelfConsumption
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-04-09 07:01:28 +00:00
Guillermo Bonet bdc202b145 feat: refs #4948 Minor change
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-04-05 12:36:08 +02:00
Guillermo Bonet 7496a419cc feat: refs #4948 Added ticket_doSelfConsumptionPackaging proc & event
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-04-05 12:29:16 +02:00
2 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,94 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_selfConsumptionPackaging`(
vSelf INT,
vAction ENUM('add', 'remove')
)
BEGIN
/**
* Maneja el consumo de cajas para autoconsumo, permitiendo
* añadir o quitar cajas utilizadas según la acción indicada.
*
* @param vSelf Id de expedición
*/
DECLARE vClientFk INT;
DECLARE vAddressFk INT;
DECLARE vItemFk INT;
DECLARE vItemName VARCHAR(50);
DECLARE vWarehouseFk INT;
DECLARE vCreated DATE;
DECLARE vTicketFk 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,
pc.addressSelfConsumptionFk,
i.id,
i.name,
t.warehouseFk,
e.created
INTO vClientFk,
vAddressFk,
vItemFk,
vItemName,
vWarehouseFk,
vCreated
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 vCreated = DATE(vCreated);
SELECT id INTO vTicketFk
FROM ticket
WHERE shipped BETWEEN vCreated AND util.dayEnd(vCreated)
AND clientFk = vClientFk
AND addressFk = vAddressFk
AND warehouseFk = vWarehouseFk;
IF vTicketFk IS NULL AND vAction = 'add' THEN
INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
VALUES (vClientFk, vWarehouseFk, vCreated, 'CAJAS AUTOCONSUMO', vAddressFk);
SET vTicketFk = LAST_INSERT_ID();
END IF;
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
UPDATE sale
SET quantity = quantity + 1
WHERE id = vSaleFk;
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;
-- Test
END$$
DELIMITER ;

View File

@ -8,5 +8,7 @@ BEGIN
`changedModel` = 'Expedition',
`changedModelId` = OLD.id,
`userFk` = account.myUser_getId();
CALL expedition_selfConsumptionPackaging(OLD.id, 'remove');
END$$
DELIMITER ;