Merge pull request 'feat: refs #7564 Added volume column' (!2664) from 7564-ticketVolume into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2664
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Guillermo Bonet 2024-08-30 11:57:09 +00:00
commit b7fa6735a5
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,24 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolume`(
vSelf INT
)
BEGIN
/**
* Update the volume ticket
*
* @param vSelf Ticket id
*/
DECLARE vVolume DECIMAL(10,6);
SELECT SUM(s.quantity * ic.cm3delivery / 1000000) INTO vVolume
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = t.warehouseFk
WHERE t.id = vSelf;
UPDATE ticket
SET volume = vVolume
WHERE id = vSelf;
END$$
DELIMITER ;

View File

@ -0,0 +1,29 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
vItemFk INT
)
BEGIN
/**
* Update the volume tickets of item
*
* @param vSelf Ticket id
*/
CREATE OR REPLACE TEMPORARY TABLE tTicket
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = t.warehouseFk
WHERE s.itemFk = vItemFk
AND t.shipped >= util.VN_CURDATE()
GROUP BY t.id;
UPDATE ticket t
JOIN tTicket tt ON tt.id = t.id
SET t.volume = tt.volume;
DROP TEMPORARY TABLE tTicket;
END$$
DELIMITER ;

View File

@ -0,0 +1 @@
ALTER TABLE vn.ticket ADD volume decimal(10,6) DEFAULT NULL NULL COMMENT 'Unidad en m3';

View File

@ -0,0 +1,16 @@
-- Calculamos todos los volumenes de todos los tickets una sola vez
CREATE OR REPLACE TEMPORARY TABLE tmp.tTicketVolume
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
JOIN vn.itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = t.warehouseFk
GROUP BY t.id;
UPDATE vn.ticket t
JOIN tmp.tTicketVolume tv ON tv.id = t.id
SET t.volume = tv.volume;
DROP TEMPORARY TABLE tmp.tTicketVolume;