feat: refs #4948 Added ticket_doSelfConsumptionPackaging proc & event #2262

Closed
guillermo wants to merge 15 commits from 4948-procTicketSelfConsumption into dev
2 changed files with 47 additions and 0 deletions
Showing only changes of commit 7496a419cc - Show all commits

View File

@ -0,0 +1,8 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`ticket_doSelfConsumptionPackaging`
ON SCHEDULE EVERY 1 DAY
STARTS '2024-04-19 04:05:00.000'
ON COMPLETION PRESERVE
ENABLE
DO CALL ticket_doSelfConsumptionPackaging(util.yesterday(), util.yesterday())$$
DELIMITER ;

View File

@ -0,0 +1,39 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doSelfConsumptionPackaging`(
vDateFrom DATE,
vDateTo DATE
)
BEGIN
/**
* Crea un ticket de autoconsumo de un rango determinado de fechas.
*
* @param vDateFrom Fecha desde
* @param vDateTo Fecha hasta
*/
DECLARE vClientFk INT;
DECLARE vAddressFk INT;
DECLARE vTicketFk INT;
DECLARE vWarehouseFk INT;
SELECT clientSelfConsumptionFk, addressSelfConsumptionFk
INTO vClientFk, vAddressFk
FROM productionConfig;
SELECT id INTO vWarehouseFk
FROM warehouse
WHERE code = 'alg';
INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
SELECT vClientFk, vWarehouseFk, vDateFrom, 'AUTOCONSUMO CAJAS', vAddressFk;
SET vTicketFk = LAST_INSERT_ID();
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
SELECT i.id, vTicketFk, i.name, COUNT(*)
FROM expedition e
JOIN packaging p ON p.id = e.packagingFk
JOIN item i ON i.id = p.itemFk
WHERE e.created BETWEEN vDateFrom AND util.dayEnd(vDateTo)
GROUP BY e.packagingFk;
END$$
DELIMITER ;