feat: refs #4948 Version expedition_doSelfConsumptionPackaging
This commit is contained in:
parent
03b06b906e
commit
2e482d85ad
|
@ -1,8 +0,0 @@
|
||||||
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 ;
|
|
|
@ -1,36 +1,63 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doSelfConsumptionPackaging`(
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_doSelfConsumptionPackaging`(
|
||||||
vDateFrom DATE,
|
vSelf DATE,
|
||||||
vDateTo DATE
|
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Crea un ticket de autoconsumo de un rango determinado de fechas.
|
* Comprueba si existe un ticket de autoconsumo ese mismo día
|
||||||
|
* si no lo está lo crea, y añade la caja utilizada.
|
||||||
*
|
*
|
||||||
* @param vDateFrom Fecha desde
|
* @param vSelf Id de expedición
|
||||||
* @param vDateTo Fecha hasta
|
|
||||||
*/
|
*/
|
||||||
|
DECLARE vCurdate DATE;
|
||||||
DECLARE vClientFk INT;
|
DECLARE vClientFk INT;
|
||||||
DECLARE vAddressFk INT;
|
DECLARE vAddressFk INT;
|
||||||
DECLARE vTicketFk INT;
|
DECLARE vTicketFk INT;
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vItemFk INT;
|
||||||
|
DECLARE vItemName VARCHAR(50);
|
||||||
|
DECLARE vExists BOOL;
|
||||||
|
|
||||||
SELECT pc.clientSelfConsumptionFk, pc.addressSelfConsumptionFk, w.id
|
SET vCurdate = util.VN_CURDATE();
|
||||||
INTO vClientFk, vAddressFk, vWarehouseFk
|
|
||||||
FROM productionConfig pc
|
|
||||||
JOIN warehouse w ON w.code = 'alg';
|
|
||||||
|
|
||||||
|
SELECT clientSelfConsumptionFk, addressSelfConsumptionFk
|
||||||
|
INTO vClientFk, vAddressFk
|
||||||
|
FROM productionConfig;
|
||||||
|
|
||||||
|
IF vClientFk IS NULL OR vAddressFk IS NULL THEN
|
||||||
|
CALL util.throw('Some config parameters are not set');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT i.id, t.warehouseFk, i.name
|
||||||
|
INTO vItemFk, vWarehouseFk, vItemName
|
||||||
|
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
|
||||||
|
FROM ticket
|
||||||
|
WHERE shipped BETWEEN vCurdate AND util.dayEnd(vCurdate)
|
||||||
|
AND clientFk = vClientFk
|
||||||
|
AND addressFk = vAddressFk
|
||||||
|
AND warehouseFk = vWarehouseFk;
|
||||||
|
|
||||||
|
IF vTicketFk IS NULL THEN
|
||||||
INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
|
INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
|
||||||
SELECT vClientFk, vWarehouseFk, vDateFrom, 'CAJAS AUTOCONSUMO', vAddressFk;
|
SELECT vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk;
|
||||||
|
|
||||||
SET vTicketFk = LAST_INSERT_ID();
|
SET vTicketFk = LAST_INSERT_ID();
|
||||||
|
|
||||||
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
|
INSERT INTO sale(itemFk, ticketFk, concept, quantity)
|
||||||
SELECT i.id, vTicketFk, i.name, COUNT(*)
|
SELECT vItemFk, vTicketFk, vItemName, 1;
|
||||||
FROM expedition e
|
ELSE
|
||||||
JOIN packaging p ON p.id = e.packagingFk
|
SELECT id INTO vExists
|
||||||
JOIN item i ON i.id = p.itemFk
|
FROM sale
|
||||||
WHERE e.created BETWEEN vDateFrom AND util.dayEnd(vDateTo)
|
WHERE itemFk = vItemFk
|
||||||
GROUP BY e.packagingFk;
|
AND ticketFk = vTicketFk;
|
||||||
|
|
||||||
|
-- Comprobar si existe o no y si existe, sumar +1 la quantity, si no, lo creamos
|
||||||
|
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue