feat: refs #4948 Added ticket_doSelfConsumptionPackaging proc & event #2262
|
@ -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 $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doSelfConsumptionPackaging`(
|
||||
vDateFrom DATE,
|
||||
vDateTo DATE
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_doSelfConsumptionPackaging`(
|
||||
vSelf DATE,
|
||||
)
|
||||
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 vDateTo Fecha hasta
|
||||
* @param vSelf Id de expedición
|
||||
*/
|
||||
DECLARE vCurdate DATE;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vAddressFk INT;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vItemName VARCHAR(50);
|
||||
DECLARE vExists BOOL;
|
||||
|
||||
SELECT pc.clientSelfConsumptionFk, pc.addressSelfConsumptionFk, w.id
|
||||
INTO vClientFk, vAddressFk, vWarehouseFk
|
||||
FROM productionConfig pc
|
||||
JOIN warehouse w ON w.code = 'alg';
|
||||
SET vCurdate = util.VN_CURDATE();
|
||||
|
||||
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
|
||||
guillermo marked this conversation as resolved
Outdated
|
||||
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)
|
||||
SELECT vClientFk, vWarehouseFk, vDateFrom, 'CAJAS AUTOCONSUMO', vAddressFk;
|
||||
SELECT vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', 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;
|
||||
SELECT vItemFk, vTicketFk, vItemName, 1;
|
||||
ELSE
|
||||
SELECT id INTO vExists
|
||||
FROM sale
|
||||
WHERE itemFk = vItemFk
|
||||
AND ticketFk = vTicketFk;
|
||||
|
||||
-- Comprobar si existe o no y si existe, sumar +1 la quantity, si no, lo creamos
|
||||
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue
@pako creà el cau, hi ha que valorar si es llança en un rango de una semana o un mes, si volem que es cree sols un ticket amb tots els embalatges, o que faça un ticket per dia.
Hi haurà casos que fallarà el procés, per tant, el seguen dia que es llance posaria els dos dies junts en un ticket, lo cual per a fer revisions o comprobacions serà molt confús.
Cal també saber si s'ha llançat o no, per a que no torne a insertar els mateixos embalatges, pe mirar que no existisca previament un ticket i si hi ha borrar el contingut y insertar de nou.
Jo voldría un ticket per dia. Es podría fer un consignatari en el client 450 que fora el dels embalatges, i així es podría comprovar si existeix el ticket o no. El proc deuria de revisar i fer, si cal, els tickets de la última setmana, cada nit