From 7f563f99bbe3254b5d2170b98618e1d52a4e241c Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jan 2024 07:11:03 +0100 Subject: [PATCH 01/81] refs #5890 feat:reserves --- .../vn/events/itemShelvingSale_doReserve.sql | 8 + .../collection_addWithReservation.sql | 87 +++++++ .../vn/procedures/collection_getAssigned.sql | 77 ++++++ .../itemShelvingSale_addByCollection.sql | 51 ++++ .../procedures/itemShelvingSale_addBySale.sql | 100 +++++++ .../procedures/itemShelvingSale_doReserve.sql | 52 ++++ .../itemShelvingSale_setQuantity.sql | 244 +++++++++--------- .../itemShelvingSale_setSaleGroup.sql | 34 +++ .../procedures/itemShelvingSale_unpicked.sql | 60 +++++ .../vn/procedures/itemShelvingTransfer.sql | 89 ++++--- .../vn/procedures/itemShelving_add.sql | 125 +++++---- .../vn/triggers/itemShelving_AFTER_INSERT.sql | 27 ++ .../vn/triggers/itemShelving_AFTER_UPDATE.sql | 16 ++ .../triggers/itemShelving_BEFORE_INSERT.sql | 10 + db/versions/10852-pinkOak/00-firstScript.sql | 23 ++ 15 files changed, 777 insertions(+), 226 deletions(-) create mode 100644 db/routines/vn/events/itemShelvingSale_doReserve.sql create mode 100644 db/routines/vn/procedures/collection_addWithReservation.sql create mode 100644 db/routines/vn/procedures/collection_getAssigned.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_addByCollection.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_addBySale.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_doReserve.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_unpicked.sql create mode 100644 db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql create mode 100644 db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql create mode 100644 db/versions/10852-pinkOak/00-firstScript.sql diff --git a/db/routines/vn/events/itemShelvingSale_doReserve.sql b/db/routines/vn/events/itemShelvingSale_doReserve.sql new file mode 100644 index 000000000..228886556 --- /dev/null +++ b/db/routines/vn/events/itemShelvingSale_doReserve.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`itemShelvingSale_doReserve` + ON SCHEDULE EVERY 15 SECOND + STARTS '2023-10-16 00:00:00' + ON COMPLETION PRESERVE + ENABLE +DO CALL vn.itemShelvingSale_doReserve$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql new file mode 100644 index 000000000..ea2632b05 --- /dev/null +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -0,0 +1,87 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_addWithReservation`( + vItemFk INT, + vQuantity INT, + vTicketFk INT +) +BEGIN +/** + * En el ámbito de las colecciones se añade una línea de sale a un ticket + * de una colección en caso de tener disponible y se realiza la reserva. + * + * @param vItemFk id of item + * @param vQuantity quantity to be added to the ticket + * @param vTicketFk ticket to which the sales line is added + */ + DECLARE vWarehouseFk INT; + DECLARE vCacheAvailableFk INT; + DECLARE vAvailable INT; + DECLARE vSaleFk INT; + DECLARE vConcept VARCHAR(50); + DECLARE vItemName VARCHAR(50); + DECLARE vHasThrow BOOLEAN DEFAULT FALSE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT t.warehouseFk INTO vWarehouseFk + FROM ticket t + JOIN ticketCollection tc ON tc.ticketFk = t.id + WHERE t.id = vTicketFk; + + CALL cache.available_refresh( + vCacheAvailableFk, + FALSE, + vWarehouseFk, + util.VN_CURDATE()); + + SELECT available INTO vAvailable + FROM cache.available + WHERE calc_id = vCacheAvailableFk + AND item_id = vItemFk; + + IF vAvailable < vQuantity THEN + SET vHasThrow = TRUE; + SELECT vAvailable, vQuantity; + ELSE + START TRANSACTION; + + SELECT `name`, + CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) + INTO vItemName, vConcept + FROM item + WHERE id = vItemFk; + + INSERT INTO ticketLog + SET originFk = vTicketFk, + userFk = getUser(), + `action` = 'update', + `description` = CONCAT('Añadido articulo ', vItemName, ' cantidad:', vQuantity); + + INSERT INTO sale + SET itemFk = vItemFk, + ticketFk = vTicketFk, + concept = vConcept, + quantity = vQuantity, + isAdded = TRUE; + + SELECT LAST_INSERT_ID() INTO vSaleFk; + + CALL sale_calculateComponent(vSaleFk, NULL); + CALL itemShelvingSale_addBySale(vSaleFk); + + IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN + SET vHasThrow = TRUE; + END IF; + END IF; + + IF vHasThrow THEN + CALL util.throw("No hay disponibilidad para el artículo seleccionado"); + ELSE + COMMIT; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_getAssigned.sql b/db/routines/vn/procedures/collection_getAssigned.sql new file mode 100644 index 000000000..dead563ac --- /dev/null +++ b/db/routines/vn/procedures/collection_getAssigned.sql @@ -0,0 +1,77 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getAssigned`( + vUserFk INT, + OUT vCollectionFk INT) +proc:BEGIN +/* Comprueba si existen colecciones libres que se ajustan al perfil del usuario + * y le asigna la más antigua. + * Añade un registro al semillero de colecciones y hace la reserva para la colección + * @param vUserFk Id de usuario + * @param vCollectionFk Id de colección + */ + DECLARE vHasTooMuchCollections BOOL; + DECLARE vLockTime INT DEFAULT 15; + + -- Si hay colecciones sin terminar, sale del proceso + CALL collection_get(vUserFk); + + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 + INTO vHasTooMuchCollections + FROM tCollection + JOIN productionConfig pc ; + + DROP TEMPORARY TABLE tCollection; + + IF vHasTooMuchCollections THEN + CALL util.throw('Hay colecciones pendientes'); + LEAVE proc; + END IF; + + IF NOT GET_LOCK('collection_getAssigned', vLockTime) THEN + LEAVE proc; + END IF; + + -- Se eliminan las colecciones sin asignar que estan obsoletas + INSERT INTO ticketTracking(stateFk, ticketFk) + SELECT s.id, tc.ticketFk + FROM collection c + JOIN ticketCollection tc ON tc.collectionFk = c.id + JOIN state s ON s.code = 'PRINTED_AUTO' + JOIN productionConfig pc + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + + DELETE c + FROM collection c + JOIN productionConfig pc + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + + -- Se añade registro al semillero + INSERT INTO collectionHotbed + SET userFk = vUserFk; + + -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion + SELECT MIN(c.id) INTO vCollectionFk + FROM collection c + JOIN operator o ON (o.itemPackingTypeFk = c.itemPackingTypeFk + OR c.itemPackingTypeFk IS NULL) + AND o.numberOfWagons = c.wagons + AND o.trainFk = c.trainFk + AND o.warehouseFk = c.warehouseFk + AND c.workerFk IS NULL + WHERE o.workerFk = vUserFk; + + IF vCollectionFk IS NULL THEN + CALL collection_new(vUserFk, vCollectionFk); + END IF; + + UPDATE collection + SET workerFk = vUserFk + WHERE id = vCollectionFk; + + CALL itemShelvingSale_addByCollection(vCollectionFk); + + DO RELEASE_LOCK('collection_getAssigned'); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql new file mode 100644 index 000000000..4e57fed0b --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql @@ -0,0 +1,51 @@ + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addByCollection`( + vCollectionFk INT(11) +) +BEGIN +/** + * Guarda la ubicación para el contenido de una colección + * + * @param vCollectionFk Identificador de collection + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vSaleFk INT; + DECLARE vSales CURSOR FOR + WITH sales AS ( + SELECT s.id saleFk, s.quantity, SUM(IFNULL(iss.quantity, 0)) quantityReserved + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + WHERE tc.collectionFk = vCollectionFk + GROUP BY s.id + HAVING quantity <> quantityReserved + ), trackedSales AS ( + SELECT sa.saleFk + FROM sales sa + JOIN vn.saleTracking st ON st.saleFk = sa.saleFk + JOIN vn.`state` s ON s.id = st.stateFk + WHERE st.isChecked + AND s.semaphore = 1 + GROUP BY sa.saleFk + ) SELECT s.saleFk + FROM sales s + LEFT JOIN trackedSales ts ON ts.saleFk = s.saleFk + WHERE ts.saleFk IS NULL; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vSales; + l: LOOP + SET vDone = FALSE; + FETCH vSales INTO vSaleFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL itemShelvingSale_addBySale(vSaleFk); + END LOOP; + CLOSE vSales; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql new file mode 100644 index 000000000..3ad581b15 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -0,0 +1,100 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( + vSaleFk INT +) +proc: BEGIN +/** + * Reserva una línea de venta en la ubicación más óptima + * + * @param vSaleFk Id de sale + * @param vItemShelvingSaleFk Id de reserva + */ + DECLARE vLastPickingOrder INT; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vItemShelvingFk INT; + DECLARE vAvailable INT; + DECLARE vReservedQuantity INT; + DECLARE vOutStanding INT; + DECLARE vUserFk INT; + + DECLARE vItemShelvingAvailable CURSOR FOR + SELECT ish.id itemShelvingFk, + ish.available + FROM sale s + JOIN itemShelving ish ON ish.itemFk = s.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector sc ON sc.id = p.sectorFk + JOIN productionConfig pc + WHERE s.id = vSaleFk + AND NOT sc.isHideForPickers + ORDER BY s.id, + p.pickingOrder >= vLastPickingOrder, + sh.priority DESC, + ish.available >= s.quantity DESC, + s.quantity MOD ish.grouping = 0 DESC, + ish.grouping DESC, + IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; +/* DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; +*/ + SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)) + INTO vLastPickingOrder, vOutStanding + FROM sale s + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + LEFT JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = sh.parkingFk + WHERE s.id = vSaleFk; + + IF vOutStanding <= 0 THEN + LEAVE proc; + END IF; + + SELECT getUser() INTO vUserFk; + + OPEN vItemShelvingAvailable; + l: LOOP + SET vDone = FALSE; + FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable; + + IF vOutStanding <= 0 OR vDone THEN + LEAVE l; + END IF; + + SELECT id INTO vItemShelvingFk + FROM itemShelving + WHERE id = vItemShelvingFk + FOR UPDATE; + + SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity; + SET vOutStanding = vOutStanding - vReservedQuantity; + + IF vReservedQuantity > 0 THEN + -- START TRANSACTION; + + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk; + + UPDATE itemShelving + SET available = available - vReservedQuantity + WHERE id = vItemShelvingFk; + + -- COMMIT; + END IF; + END LOOP; + CLOSE vItemShelvingAvailable; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_doReserve.sql b/db/routines/vn/procedures/itemShelvingSale_doReserve.sql new file mode 100644 index 000000000..d7bf4b181 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_doReserve.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_doReserve`() +proc: BEGIN +/** + * Genera reservas de la tabla itemShelvingSaleReserv + */ + DECLARE vDone BOOL; + DECLARE vSaleFk INT; + + DECLARE vSales CURSOR FOR + SELECT DISTINCT saleFk FROM tSale; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.itemShelvingSale_doReserve'); + ROLLBACK; + RESIGNAL; + END; + + IF !GET_LOCK('vn.itemShelvingSale_doReserve', 0) THEN + LEAVE proc; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tSale + ENGINE = MEMORY + SELECT id, saleFk FROM itemShelvingSaleReserv; + + OPEN vSales; + + myLoop: LOOP + SET vDone = FALSE; + FETCH vSales INTO vSaleFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL itemShelvingSale_addBySale (vSaleFk); + END LOOP; + + CLOSE vSales; + + DELETE iss FROM itemShelvingSaleReserv iss JOIN tSale s ON s.id = iss.id; + + DROP TEMPORARY TABLE tSale; + + DO RELEASE_LOCK('vn.itemShelvingSale_doReserve'); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index b792534fb..13b8a16ad 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -1,118 +1,126 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setQuantity`( - vItemShelvingSaleFk INT(10), - vQuantity DECIMAL(10,0), - vIsItemShelvingSaleEmpty BOOLEAN -) -BEGIN -/** - * Gestiona la reserva de un itemShelvingFk, actualizando isPicked y quantity - * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. - * Si la reserva de la ubicación es fallida, se regulariza la situación - * - * @param vItemShelvingSaleFk Id itemShelvingSaleFK - * @param vQuantity Cantidad real que se ha cogido de la ubicación - * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha - * quedado vacio tras el movimiento - */ - DECLARE vSaleFk INT; - DECLARE vCursorSaleFk INT; - DECLARE vItemShelvingFk INT; - DECLARE vReservedQuantity INT; - DECLARE vRemainingQuantity INT; - DECLARE vItemFk INT; - DECLARE vUserFk INT; - DECLARE vDone BOOLEAN DEFAULT FALSE; - DECLARE vSales CURSOR FOR - SELECT iss.saleFk, iss.userFk - FROM itemShelvingSale iss - JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vItemShelvingSaleFk - AND s.itemFk = vItemFk - AND NOT iss.isPicked; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - IF (SELECT isPicked FROM itemShelvingSale WHERE id = vItemShelvingSaleFk) THEN - CALL util.throw('Booking completed'); - END IF; - - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk - INTO vItemFk, vSaleFk, vItemShelvingFk - FROM itemShelvingSale iss - JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vItemShelvingSaleFk - AND NOT iss.isPicked; - - UPDATE itemShelvingSale - SET isPicked = TRUE, - quantity = vQuantity - WHERE id = vItemShelvingSaleFk; - - UPDATE itemShelving - SET visible = IF(vIsItemShelvingSaleEmpty, 0, GREATEST(0,visible - vQuantity)) - WHERE id = vItemShelvingFk; - - IF vIsItemShelvingSaleEmpty THEN - OPEN vSales; -l: LOOP - SET vDone = FALSE; - FETCH vSales INTO vCursorSaleFk, vUserFk; - IF vDone THEN - LEAVE l; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk, userFk)) - ENGINE = MEMORY - SELECT vCursorSaleFk, vUserFk; - - CALL itemShelvingSale_reserveWhitUser(); - DROP TEMPORARY TABLE tmp.sale; - - END LOOP; - CLOSE vSales; - - DELETE iss - FROM itemShelvingSale iss - JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vItemShelvingSaleFk - AND s.itemFk = vItemFk - AND NOT iss.isPicked; - END IF; - - SELECT SUM(quantity) INTO vRemainingQuantity - FROM itemShelvingSale - WHERE saleFk = vSaleFk - AND NOT isPicked; - - IF vRemainingQuantity THEN - CALL itemShelvingSale_reserveBySale (vSaleFk, vRemainingQuantity, NULL); - - SELECT SUM(quantity) INTO vRemainingQuantity - FROM itemShelvingSale - WHERE saleFk = vSaleFk - AND NOT isPicked; - - IF NOT vRemainingQuantity <=> 0 THEN - SELECT SUM(iss.quantity) - INTO vReservedQuantity - FROM itemShelvingSale iss - WHERE iss.saleFk = vSaleFk; - - CALL saleTracking_new( - vSaleFk, - TRUE, - vReservedQuantity, - `account`.`myUser_getId`(), - NULL, - 'PREPARED', - TRUE); - - UPDATE sale s - SET s.quantity = vReservedQuantity - WHERE s.id = vSaleFk ; - END IF; - END IF; -END$$ -DELIMITER ; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setQuantity`( + vItemShelvingSaleFk INT(10), + vQuantity DECIMAL(10,0), + vIsItemShelvingSaleEmpty BOOLEAN +) +BEGIN +/** + * Gestiona la reserva de un itemShelvingFk, actualizando isPicked y quantity + * en itemShelvingSale y sale.isPicked en caso necesario. + * Si la reserva de la ubicación es fallida, se regulariza la situación + * + * @param vItemShelvingSaleFk Id itemShelvingSaleFK + * @param vQuantity Cantidad real que se ha cogido de la ubicación + * @param vIsItemShelvingSaleEmpty determina si la ubicación itemShelvingSale se ha + * quedado vacio tras el movimiento + */ + DECLARE vSaleFk INT; + DECLARE vItemShelvingFk INT; + DECLARE vReservedQuantity INT; + DECLARE vRemainingQuantity INT; + DECLARE vItemFk INT; + DECLARE vTotalQuantity INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + IF (SELECT isPicked FROM itemShelvingSale WHERE id = vItemShelvingSaleFk) THEN + CALL util.throw('Reserva completada'); + END IF; + + SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)) + INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.id = vItemShelvingSaleFk + AND NOT iss.isPicked; + + IF vQuantity > vReservedQuantity + OR (vQuantity < vReservedQuantity AND + (NOT vIsItemShelvingSaleEmpty OR vIsItemShelvingSaleEmpty IS NULL)) + OR (vIsItemShelvingSaleEmpty IS NOT NULL AND vQuantity = vReservedQuantity) THEN + CALL util.throw('La cantidad no puede distinta a la reserva'); + END IF; + + + START TRANSACTION; + + + UPDATE itemShelvingSale + SET isPicked = TRUE, + quantity = vQuantity + WHERE id = vItemShelvingSaleFk; + + SELECT id INTO vItemShelvingFk + FROM itemShelving + WHERE id = vItemShelvingFk + AND FALSE + FOR UPDATE; + + UPDATE itemShelving + SET visible = IF(vIsItemShelvingSaleEmpty, 0, GREATEST(0, visible - vQuantity)) + WHERE id = vItemShelvingFk; + + COMMIT; + + IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN + + UPDATE itemShelving + SET visible = 0, + available = 0 + WHERE id = vItemShelvingFk + AND itemFk = vItemFk; + + CALL itemShelvingSale_addBySale(vSaleFk); + + START TRANSACTION; + + INSERT INTO itemShelvingSaleReserv (saleFk) + SELECT DISTINCT iss.saleFk + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + + DELETE iss + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + COMMIT; + + CALL itemShelvingSale_doReserve(); + END IF; + + SELECT SUM(IF(isPicked, 0, quantity)), SUM(quantity) + INTO vRemainingQuantity, vTotalQuantity + FROM itemShelvingSale + WHERE saleFk = vSaleFk; + + IF vRemainingQuantity = 0 THEN + START TRANSACTION; + + CALL saleTracking_new( + vSaleFk, + TRUE, + vTotalQuantity, + `account`.`myUser_getId`(), + NULL, + 'PREPARED', + TRUE); + + UPDATE sale s + SET s.quantity = vTotalQuantity, + isPicked = TRUE + WHERE s.id = vSaleFk; + + COMMIT; + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql b/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql new file mode 100644 index 000000000..911034ed1 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setSaleGroup`( + vSaleGroupFk INT(10) +) +BEGIN +/** + * Gestiona la reserva de un vn.saleGroup actualizando vn.itemShelvingSale.isPicked + * y cambiando el estado de la vn.sale + * + * @param vSaleGroupFk Id saleGroupFk + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + IF NOT (SELECT COUNT(*) FROM saleGroup WHERE id = vSaleGroupFk) THEN + CALL util.throw('Sale group not exists'); + END IF; + + START TRANSACTION; + + UPDATE itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + JOIN saleGroupDetail sg ON sg.saleFk = s.id + SET iss.isPicked = TRUE + WHERE sg.saleGroupFk = vSaleGroupFk; + + CALL saleTracking_addPreparedSaleGroup(vSaleGroupFk); + + COMMIT; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_unpicked.sql b/db/routines/vn/procedures/itemShelvingSale_unpicked.sql new file mode 100644 index 000000000..6813a65b1 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_unpicked.sql @@ -0,0 +1,60 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_unpicked`( + vSelf INT(11) +) +BEGIN +/** + * Desmarca una línea que ya estaba sacada, devolviendo la cantidad al itemShelving + * + * @param vSelf Identificador del itemShelvingSale + */ + DECLARE vSaleFk INT; + DECLARE vReservedQuantity INT; + DECLARE vIsSaleGroup BOOL; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + IF (SELECT NOT isPicked FROM itemShelvingSale WHERE id = vSelf) THEN + CALL util.throw('Reserva no completada'); + END IF; + + SELECT ish.saleFk, ish.quantity, IF(sg.id, TRUE, FALSE) + INTO vSaleFk, vReservedQuantity, vIsSaleGroup + FROM itemShelvingSale ish + LEFT JOIN saleGroupDetail sg ON sg.saleFk = ish.saleFk + WHERE ish.id = vSelf; + + IF vIsSaleGroup THEN + CALL util.throw('Can not unpicked a sale group'); + END IF; + + START TRANSACTION; + + UPDATE itemShelvingSale + SET isPicked = FALSE + WHERE id = vSelf; + + UPDATE sale s + JOIN itemShelvingSale ish ON ish.saleFk = s.id + SET s.isPicked = FALSE + WHERE ish.id = vSelf; + + UPDATE itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + SET ish.visible = ish.visible + iss.quantity + WHERE iss.id = vSelf; + + CALL saleTracking_new( + vSaleFk, + FALSE, + vReservedQuantity, + `account`.`myUser_getId`(), + NULL, + 'ON_PREPARATION', + TRUE); + COMMIT; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingTransfer.sql b/db/routines/vn/procedures/itemShelvingTransfer.sql index 326f8108b..2a6f9fef1 100644 --- a/db/routines/vn/procedures/itemShelvingTransfer.sql +++ b/db/routines/vn/procedures/itemShelvingTransfer.sql @@ -1,45 +1,44 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingTransfer`(vItemShelvingFk INT, vShelvingFk VARCHAR(3)) -BEGIN -/** - * Transfiere producto de una ubicación a otra, fusionando si coincide el - * packing y la fecha. - * - * @param vItemShelvingFk Identificador de itemShelving - * @param vShelvingFk Identificador de shelving - */ - DECLARE vNewItemShelvingFk INT DEFAULT 0; - - SELECT MAX(ish.id) - INTO vNewItemShelvingFk - FROM itemShelving ish - JOIN ( - SELECT - itemFk, - packing, - created - FROM itemShelving - WHERE id = vItemShelvingFk - ) ish2 - ON ish2.itemFk = ish.itemFk - AND ish2.packing = ish.packing - AND date(ish2.created) = date(ish.created) - WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci; - - IF vNewItemShelvingFk THEN - UPDATE itemShelving ish - JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk - SET ish.visible = ish.visible + ish2.visible - WHERE ish.id = vNewItemShelvingFk; - - DELETE FROM itemShelving - WHERE id = vItemShelvingFk; - ELSE - UPDATE itemShelving - SET shelvingFk = vShelvingFk - WHERE id = vItemShelvingFk; - END IF; - - SELECT true; -END$$ -DELIMITER ; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingTransfer`( + vItemShelvingFk INT, + vShelvingFk VARCHAR(3)) +BEGIN +/** + * Transfiere producto de una ubicación a otra, fusionando si coincide el + * packing y la fecha. + * + * @param vItemShelvingFk Identificador de itemShelving + * @param vShelvingFk Identificador de shelving + */ + DECLARE vNewItemShelvingFk INT DEFAULT 0; + + SELECT MAX(ish.id) + INTO vNewItemShelvingFk + FROM itemShelving ish + JOIN ( + SELECT itemFk, + packing, + created + FROM itemShelving + WHERE id = vItemShelvingFk + ) ish2 ON ish2.itemFk = ish.itemFk + AND ish2.packing = ish.packing + AND DATE(ish2.created) = DATE(ish.created) + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci; + + IF vNewItemShelvingFk THEN + UPDATE itemShelving ish + JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk + SET ish.visible = ish.visible + ish2.visible + WHERE ish.id = vNewItemShelvingFk; + + DELETE FROM itemShelving + WHERE id = vItemShelvingFk; + ELSE + UPDATE itemShelving + SET shelvingFk = vShelvingFk + WHERE id = vItemShelvingFk; + END IF; + SELECT true; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 02762fa0b..9bfce27ea 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -1,63 +1,62 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) -BEGIN - - -/** - * Añade registro o lo actualiza si ya existe. - * - * @param vShelvingFk matrícula del carro - * @param vBarcode el id del registro - * @param vQuantity indica la cantidad del producto - * @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra - * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra - * @param vPacking el packing del producto, NULL para coger el de la ultima compra - * @param vWarehouseFk indica el sector - * - **/ - - DECLARE vItemFk INT; - - SELECT barcodeToItem(vBarcode) INTO vItemFk; - - IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN - - INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); - INSERT INTO shelving(code, parkingFk) - SELECT vShelvingFk, id - FROM parking - WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; - - END IF; - - IF (SELECT COUNT(*) FROM itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN - - UPDATE itemShelving - SET visible = visible+vQuantity - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; - - ELSE - CALL cache.last_buy_refresh(FALSE); - INSERT INTO itemShelving( itemFk, - shelvingFk, - visible, - grouping, - packing, - packagingFk) - - SELECT vItemFk, - vShelvingFk, - vQuantity, - IFNULL(vGrouping, b.grouping), - IFNULL(vPacking, b.packing), - IFNULL(vPackagingFk, b.packagingFk) - FROM item i - LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id - WHERE i.id = vItemFk; - END IF; -END$$ -DELIMITER ; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) +BEGIN +/** + * Añade registro o lo actualiza si ya existe. + * + * @param vShelvingFk matrícula del carro + * @param vBarcode el id del registro + * @param vQuantity indica la cantidad del producto + * @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra + * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra + * @param vPacking el packing del producto, NULL para coger el de la ultima compra + * @param vWarehouseFk indica el sector + * + **/ + + DECLARE vItemFk INT; + + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN + + INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); + INSERT INTO shelving(code, parkingFk) + SELECT vShelvingFk, id + FROM parking + WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; + + END IF; + + IF (SELECT COUNT(*) FROM itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk + AND packing = vPacking) = 1 THEN + + UPDATE itemShelving + SET visible = visible + vQuantity + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; + + ELSE + CALL cache.last_buy_refresh(FALSE); + INSERT INTO itemShelving( itemFk, + shelvingFk, + visible, + grouping, + packing, + packagingFk) + + SELECT vItemFk, + vShelvingFk, + vQuantity, + IFNULL(vGrouping, b.grouping), + IFNULL(vPacking, b.packing), + IFNULL(vPackagingFk, b.packagingFk), + vQuantity + FROM item i + LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN buy b ON b.id = lb.buy_id + WHERE i.id = vItemFk; + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql b/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql new file mode 100644 index 000000000..784a736ec --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT` + AFTER INSERT ON `itemShelving` + FOR EACH ROW +BEGIN + + INSERT INTO vn.itemShelvingLog( + itemShelvingFk, + workerFk, + accion, + itemFk, + shelvingFk, + visible, + `grouping`, + packing, + available) + VALUES( NEW.id, + NEW.userFk, + 'CREA REGISTRO', + NEW.itemFk, + NEW.shelvingFk, + NEW.visible, + NEW.`grouping`, + NEW.packing, + NEW.available); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql b/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql new file mode 100644 index 000000000..23ea14e85 --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE` + AFTER UPDATE ON `itemShelving` + FOR EACH ROW +BEGIN + INSERT INTO itemShelvingLog + SET itemShelvingFk = NEW.id, + workerFk = account.myUser_getId(), + accion = 'CAMBIO', + itemFk = NEW.itemFk, + shelvingFk = NEW.shelvingFk, + visible = NEW.visible, + `grouping` = NEW.`grouping`, + packing = NEW.packing; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql b/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql new file mode 100644 index 000000000..0bed738d2 --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_INSERT` + BEFORE INSERT ON `itemShelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.userFk = account.myUser_getId(); + SET NEW.available = NEW.visible; +END$$ +DELIMITER ; diff --git a/db/versions/10852-pinkOak/00-firstScript.sql b/db/versions/10852-pinkOak/00-firstScript.sql new file mode 100644 index 000000000..3fd8f447b --- /dev/null +++ b/db/versions/10852-pinkOak/00-firstScript.sql @@ -0,0 +1,23 @@ +ALTER TABLE vn.itemShelvingSale DROP COLUMN IF EXISTS isPicked; + +ALTER TABLE vn.itemShelvingSale + ADD isPicked TINYINT(1) DEFAULT FALSE NOT NULL; + +ALTER TABLE vn.productionConfig DROP COLUMN IF EXISTS orderMode; + +ALTER TABLE vn.productionConfig + ADD orderMode ENUM('Location', 'Age') NOT NULL DEFAULT 'Location'; + +ALTER TABLE vn.itemShelving DROP COLUMN IF EXISTS available; + +ALTER TABLE vn.itemShelving ADD available INT NULL; + +UPDATE vn.itemShelving SET available = visible; + +CREATE TABLE vn.itemShelvingSaleReserv ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `saleFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `itemShelvingSaleReserv_ibfk_1` (`saleFk`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci + COMMENT='Queue of changed itemShelvingSale to reserve'; From 844bab3cc84e55b6884fc56a71b00502712080d7 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 6 Feb 2024 16:17:53 +0100 Subject: [PATCH 02/81] #refs 5890 feat:add assignCollection --- back/methods/collection/assignCollection.js | 29 ++++++++++++++ .../collection/spec/assignCollection.spec.js | 38 +++++++++++++++++++ back/models/collection.js | 1 + db/versions/10852-pinkOak/00-firstScript.sql | 5 +++ loopback/locale/es.json | 6 ++- 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 back/methods/collection/assignCollection.js create mode 100644 back/methods/collection/spec/assignCollection.spec.js diff --git a/back/methods/collection/assignCollection.js b/back/methods/collection/assignCollection.js new file mode 100644 index 000000000..2ff37ab59 --- /dev/null +++ b/back/methods/collection/assignCollection.js @@ -0,0 +1,29 @@ +const UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + Self.remoteMethodCtx('assignCollection', { + description: 'Assign a collection', + accessType: 'WRITE', + http: { + path: `/assignCollection`, + verb: 'POST' + }, + returns: { + type: ['object'], + root: true + }, + }); + + Self.assignCollection = async(ctx, options) => { + const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + const [info, info2, [{'@vCollectionFk': collectionFk}]] = await Self.rawSql( + 'CALL vn.collection_getAssigned(?, @vCollectionFk);SELECT @vCollectionFk', [userId], myOptions); + if (!collectionFk) throw new UserError('There are not picking tickets'); + await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions); + + return collectionFk; + }; +}; diff --git a/back/methods/collection/spec/assignCollection.spec.js b/back/methods/collection/spec/assignCollection.spec.js new file mode 100644 index 000000000..340bd6a93 --- /dev/null +++ b/back/methods/collection/spec/assignCollection.spec.js @@ -0,0 +1,38 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +fdescribe('ticket assignCollection()', () => { + let ctx; + let options; + let tx; + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 1106}, + headers: {origin: 'http://localhost'}, + __: value => value + }, + args: {} + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx.req + }); + + options = {transaction: tx}; + tx = await models.Sale.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should throw an error when there is not picking tickets', async() => { + try { + await models.Collection.assignCollection(ctx, options); + } catch (e) { + expect(e.message).toEqual('There are not picking tickets'); + } + }); +}); diff --git a/back/models/collection.js b/back/models/collection.js index 1c10d49fa..a0d34712f 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -4,4 +4,5 @@ module.exports = Self => { require('../methods/collection/setSaleQuantity')(Self); require('../methods/collection/previousLabel')(Self); require('../methods/collection/getTickets')(Self); + require('../methods/collection/assignCollection')(Self); }; diff --git a/db/versions/10852-pinkOak/00-firstScript.sql b/db/versions/10852-pinkOak/00-firstScript.sql index 3fd8f447b..7af48148c 100644 --- a/db/versions/10852-pinkOak/00-firstScript.sql +++ b/db/versions/10852-pinkOak/00-firstScript.sql @@ -21,3 +21,8 @@ CREATE TABLE vn.itemShelvingSaleReserv ( KEY `itemShelvingSaleReserv_ibfk_1` (`saleFk`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue of changed itemShelvingSale to reserve'; + +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + + ('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5c7dc41b6..394fca450 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -338,5 +338,7 @@ "The alias cant be modified": "Este alias de correo no puede ser modificado", "No tickets to invoice": "No hay tickets para facturar", "Name should be uppercase": "El nombre debe ir en mayúscula", - "An email is necessary": "Es necesario un email" -} + "An email is necessary": "Es necesario un email", + "printerNotExists": "printerNotExists", + "There are not picking tickets": "No hay tickets para sacar" +} \ No newline at end of file From 93de845b6764da67a78386e2fc8496918884a740 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 16 Feb 2024 07:03:05 +0100 Subject: [PATCH 03/81] refs#5890 feat: delete trigger and modify getTickets --- back/methods/collection/getTickets.js | 2 +- .../vn/triggers/itemShelvingSale_afterInsert.sql | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 db/routines/vn/triggers/itemShelvingSale_afterInsert.sql diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 50117b954..fc77d4af3 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -68,7 +68,7 @@ module.exports = Self => { LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk JOIN item i ON i.id = s.itemFk - LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN parking p ON p.id = sh.parkingFk diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql deleted file mode 100644 index 63ca893bd..000000000 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ /dev/null @@ -1,12 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterInsert` - AFTER INSERT ON `itemShelvingSale` - FOR EACH ROW -BEGIN - - UPDATE vn.sale - SET isPicked = TRUE - WHERE id = NEW.saleFk; - -END$$ -DELIMITER ; From c20747434e09fd7d5d8fedcf35a7f118fc25796f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 18 Mar 2024 17:51:35 +0100 Subject: [PATCH 04/81] feat: previas con sitema de reservas refs #6861 --- ...ShelvingSale_reserveBySectorCollection.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql new file mode 100644 index 000000000..3ea351288 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE + `vn`.`itemShelvingSale_reserveBySectorCollection`(vSectorCollectionFk INT(11)) +BEGIN +/** + * Reserva cantidades con ubicaciones para el contenido de una preparación previa + * de la cual ya tiene generada la asociación del saleGroup con sectorCollection + * + * @param vSectorCollectionFk Identificador de sectorCollection + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT s.id + FROM sectorCollectionSaleGroup sc + JOIN saleGroupDetail sg ON sg.saleGroupFk = sc.saleGroupFk + JOIN sale s ON sg.saleFk = s.id + JOIN saleTracking str ON str.saleFk = s.id + JOIN `state` st ON st.id = str.stateFk + AND st.code = 'PREVIOUS_PREPARATION' + WHERE sc.sectorCollectionFk = vSectorCollectionFk + AND str.workerFk = account.myUser_getId(); + + CALL itemShelvingSale_reserve(); +END$$ +DELIMITER ; From f1e8f965b35475d3684b22d19b36abb45d449295 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 21 Mar 2024 11:59:45 +0100 Subject: [PATCH 05/81] refs #5890 itemShelving --- ...ShelvingSale_reserveBySectorCollection.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql new file mode 100644 index 000000000..3510e774e --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE + `vn`.`itemShelvingSale_reserveBySectorCollection`(vSectorCollectionFk INT(11)) +BEGIN +/** + * Reserva cantidades con ubicaciones para el contenido de una preparación previa + * de la cual ya tiene generada la asociación del saleGroup con sectorCollection + * + * @param vSectorCollectionFk Identificador de sectorCollection + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT s.id + FROM sectorCollectionSaleGroup sc + JOIN saleGroupDetail sg ON sg.saleGroupFk = sc.saleGroupFk + JOIN sale s ON sg.saleFk = s.id + JOIN saleTracking str ON str.saleFk = s.id + JOIN `state` st ON st.id = str.stateFk + AND st.code = 'PREVIOUS_PREPARATION' + WHERE sc.sectorCollectionFk = vSectorCollectionFk + AND str.workerFk = account.myUser_getId(); + + CALL itemShelvingSale_reserve(); +END$$ +DELIMITER ; \ No newline at end of file From f18d61d17dab66359471710d6529c808fbff647b Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 21 Mar 2024 17:28:08 +0100 Subject: [PATCH 06/81] refs #5890 fix: dev --- back/methods/url/getUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/url/getUrl.js b/back/methods/url/getUrl.js index ef741e5a0..8a86ba579 100644 --- a/back/methods/url/getUrl.js +++ b/back/methods/url/getUrl.js @@ -22,7 +22,7 @@ module.exports = Self => { const {url} = await Self.app.models.Url.findOne({ where: { appName, - environment: process.env.NODE_ENV || 'development' + environment: process.env.NODE_ENV || 'dev' } }); return url; From 6db1696094f50f5fc47e07002cd933a131eb97b9 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 3 Apr 2024 07:04:12 +0200 Subject: [PATCH 07/81] refs #5890 feat:trigger --- .../itemShelvingSale_addByCollection.sql | 2 +- .../vn/triggers/itemShelving_AFTER_INSERT.sql | 27 ---------------- .../vn/triggers/itemShelving_AFTER_UPDATE.sql | 16 ---------- .../triggers/itemShelving_BEFORE_INSERT.sql | 10 ------ .../vn/triggers/itemShelving_afterInsert.sql | 31 +++++++++++-------- .../vn/triggers/itemShelving_afterUpdate.sql | 10 ++++-- .../vn/triggers/itemShelving_beforeInsert.sql | 1 + .../vn/triggers/itemShelving_beforeUpdate.sql | 6 ++++ 8 files changed, 33 insertions(+), 70 deletions(-) delete mode 100644 db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql delete mode 100644 db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql delete mode 100644 db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql diff --git a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql index 4e57fed0b..9bc549235 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_ad ) BEGIN /** - * Guarda la ubicación para el contenido de una colección + * Reserva cantidades con ubicaciones para el contenido de una colección * * @param vCollectionFk Identificador de collection */ diff --git a/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql b/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql deleted file mode 100644 index 784a736ec..000000000 --- a/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql +++ /dev/null @@ -1,27 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT` - AFTER INSERT ON `itemShelving` - FOR EACH ROW -BEGIN - - INSERT INTO vn.itemShelvingLog( - itemShelvingFk, - workerFk, - accion, - itemFk, - shelvingFk, - visible, - `grouping`, - packing, - available) - VALUES( NEW.id, - NEW.userFk, - 'CREA REGISTRO', - NEW.itemFk, - NEW.shelvingFk, - NEW.visible, - NEW.`grouping`, - NEW.packing, - NEW.available); -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql b/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql deleted file mode 100644 index 23ea14e85..000000000 --- a/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql +++ /dev/null @@ -1,16 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE` - AFTER UPDATE ON `itemShelving` - FOR EACH ROW -BEGIN - INSERT INTO itemShelvingLog - SET itemShelvingFk = NEW.id, - workerFk = account.myUser_getId(), - accion = 'CAMBIO', - itemFk = NEW.itemFk, - shelvingFk = NEW.shelvingFk, - visible = NEW.visible, - `grouping` = NEW.`grouping`, - packing = NEW.packing; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql b/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql deleted file mode 100644 index 0bed738d2..000000000 --- a/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql +++ /dev/null @@ -1,10 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_INSERT` - BEFORE INSERT ON `itemShelving` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - SET NEW.userFk = account.myUser_getId(); - SET NEW.available = NEW.visible; -END$$ -DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_afterInsert.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql index 5c0cb3853..1408615c3 100644 --- a/db/routines/vn/triggers/itemShelving_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelving_afterInsert.sql @@ -1,22 +1,27 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT` AFTER INSERT ON `itemShelving` FOR EACH ROW -INSERT INTO vn.itemShelvingLog( itemShelvingFk, - workerFk, - accion, - itemFk, - shelvingFk, - visible, - `grouping`, - packing) - VALUES( NEW.id, +BEGIN + + INSERT INTO vn.itemShelvingLog( + itemShelvingFk, + workerFk, + accion, + itemFk, + shelvingFk, + visible, + `grouping`, + packing, + available) + VALUES( NEW.id, NEW.userFk, 'CREA REGISTRO', NEW.itemFk, NEW.shelvingFk, NEW.visible, NEW.`grouping`, - NEW.packing - )$$ -DELIMITER ; + NEW.packing, + NEW.available); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/itemShelving_afterUpdate.sql b/db/routines/vn/triggers/itemShelving_afterUpdate.sql index 107e8ecdc..1d7dc4ac6 100644 --- a/db/routines/vn/triggers/itemShelving_afterUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_afterUpdate.sql @@ -1,8 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterUpdate` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE` AFTER UPDATE ON `itemShelving` FOR EACH ROW -INSERT INTO itemShelvingLog +BEGIN + INSERT INTO itemShelvingLog SET itemShelvingFk = NEW.id, workerFk = account.myUser_getId(), accion = 'CAMBIO', @@ -10,5 +11,8 @@ INSERT INTO itemShelvingLog shelvingFk = NEW.shelvingFk, visible = NEW.visible, `grouping` = NEW.`grouping`, - packing = NEW.packing$$ + packing = NEW.packing, + available = NEW.available; + +END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_beforeInsert.sql b/db/routines/vn/triggers/itemShelving_beforeInsert.sql index 011cf3701..e9fe17cf2 100644 --- a/db/routines/vn/triggers/itemShelving_beforeInsert.sql +++ b/db/routines/vn/triggers/itemShelving_beforeInsert.sql @@ -5,6 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeIn BEGIN SET NEW.editorFk = account.myUser_getId(); SET NEW.userFk = account.myUser_getId(); + SET NEW.available = NEW.visible; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index 6fd919d2e..214c64b45 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -3,9 +3,15 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeUp BEFORE UPDATE ON `itemShelving` FOR EACH ROW BEGIN + SET NEW.editorFk = account.myUser_getId(); IF NEW.userFk IS NULL THEN SET NEW.userFk = account.myUser_getId(); END IF; + + IF (NEW.visible <> OLD.visible) THEN + SET NEW.available = GREATEST(NEW.available + NEW.visible - OLD.visible, 0); + END IF; + END$$ DELIMITER ; From 78f55861365eeafaf3fe22e9278a619081b963fd Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 4 Apr 2024 09:37:34 +0200 Subject: [PATCH 08/81] refs #5890 feat:itemShelving_add --- db/routines/vn/procedures/itemShelving_add.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index dee96f43c..09a3e5bb6 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -55,8 +55,7 @@ BEGIN vQuantity, IFNULL(vGrouping, b.grouping), IFNULL(vPacking, b.packing), - IFNULL(vPackagingFk, b.packagingFk), - vQuantity + IFNULL(vPackagingFk, b.packagingFk) FROM item i LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk LEFT JOIN buy b ON b.id = lb.buy_id From 09812c24ddcb717f7b09196bd644f0b66e6e6dc9 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 8 Apr 2024 09:54:23 +0200 Subject: [PATCH 09/81] refs #5890 feat: triggers --- db/routines/vn/triggers/itemShelving_afterInsert.sql | 2 +- db/routines/vn/triggers/itemShelving_afterUpdate.sql | 2 +- db/versions/10983-chocolateDracena/00-firstScript.sql | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/versions/10983-chocolateDracena/00-firstScript.sql diff --git a/db/routines/vn/triggers/itemShelving_afterInsert.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql index 1408615c3..86f149473 100644 --- a/db/routines/vn/triggers/itemShelving_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelving_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` AFTER INSERT ON `itemShelving` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/itemShelving_afterUpdate.sql b/db/routines/vn/triggers/itemShelving_afterUpdate.sql index 1d7dc4ac6..1ad57961a 100644 --- a/db/routines/vn/triggers/itemShelving_afterUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterUpdate` AFTER UPDATE ON `itemShelving` FOR EACH ROW BEGIN diff --git a/db/versions/10983-chocolateDracena/00-firstScript.sql b/db/versions/10983-chocolateDracena/00-firstScript.sql new file mode 100644 index 000000000..2baf1b21f --- /dev/null +++ b/db/versions/10983-chocolateDracena/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +USE vn; + +DROP TRIGGER IF EXISTS itemShelving_AFTER_UPDATE; +DROP TRIGGER IF EXISTS itemShelving_AFTER_INSERT; From 5967bd545c40df79625996295edafa515e9ebdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 11 Apr 2024 12:16:00 +0200 Subject: [PATCH 10/81] feat: previas con reserva refs #6861 --- back/methods/collection/getSales.js | 4 +- back/methods/collection/getTickets.js | 57 +++++++-- db/routines/vn/functions/ticket_get.sql | 88 ++++++-------- .../vn/procedures/collection_getTickets.sql | 115 +++++++++++------- 4 files changed, 155 insertions(+), 109 deletions(-) diff --git a/back/methods/collection/getSales.js b/back/methods/collection/getSales.js index 78945dc80..d4bf371b2 100644 --- a/back/methods/collection/getSales.js +++ b/back/methods/collection/getSales.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('getSales', { - description: 'Get sales from ticket or collection', + description: 'Get sales from ticket, collection or sectorCollection', accessType: 'READ', accepts: [ { @@ -59,7 +59,7 @@ module.exports = Self => { if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions); for (let ticket of tickets) { - let observations = ticket.observaciones.split(' '); + let observations = ticket.observation.split(' '); for (let observation of observations) { const salesPerson = ticket.salesPersonFk; diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 50117b954..ab974e371 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -37,6 +37,7 @@ module.exports = Self => { const promises = []; const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions); + const sales = await Self.rawSql(` SELECT s.ticketFk, sgd.saleGroupFk, @@ -76,17 +77,55 @@ module.exports = Self => { LEFT JOIN origin o ON o.id = i.originFk WHERE tc.collectionFk = ? GROUP BY s.id, ish.id, p.code, p2.code - ORDER BY pickingOrder;`, [id], myOptions); - + UNION ALL + SELECT s.ticketFk, + sgd.saleGroupFk, + s.id saleFk, + s.itemFk, + i.longName, + i.size, + ic.color, + o.code origin, + ish.packing, + ish.grouping, + s.isAdded, + s.originalQuantity, + s.quantity, + iss.quantity, + SUM(iss.quantity) OVER (PARTITION BY s.id ORDER BY ish.id), + ROW_NUMBER () OVER (PARTITION BY s.id ORDER BY p.pickingOrder), + COUNT(*) OVER (PARTITION BY s.id ORDER BY s.id) , + sh.code, + IFNULL(p2.code, p.code), + IFNULL(p2.pickingOrder, p.pickingOrder), + iss.id itemShelvingSaleFk, + iss.isPicked + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id + JOIN saleGroup sg ON sg.id = ss.saleGroupFk + JOIN ticket t ON t.id = sg.ticketFk + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN parking p2 ON p2.id = sg.parkingFk + JOIN item i ON i.id = s.itemFk + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + LEFT JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = sh.parkingFk + LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk + LEFT JOIN origin o ON o.id = i.originFk + WHERE sc.id = ? + GROUP BY s.id, ish.id, p.code, p2.code`, [id, id], myOptions); if (print) await Self.rawSql(`CALL vn.collection_printSticker(?, ?)`, [id, null], myOptions); const collection = {collectionFk: id, tickets: []}; + if (tickets && tickets.length) { for (const ticket of tickets) { const ticketId = ticket.ticketFk; - if (ticket.observaciones != '') { - for (observation of ticket.observaciones.split(' ')) { + if (ticket.observation) { + for (observation of ticket.observation?.split(' ')) { if (['#', '@'].includes(observation.charAt(0))) { promises.push(Self.app.models.Chat.send(ctx, observation, $t('The ticket is in preparation', { @@ -100,11 +139,11 @@ module.exports = Self => { if (sales && sales.length) { const barcodes = await Self.rawSql(` SELECT s.id saleFk, b.code, c.id - FROM vn.sale s - LEFT JOIN vn.itemBarcode b ON b.itemFk = s.itemFk - LEFT JOIN vn.buy c ON c.itemFk = s.itemFk - LEFT JOIN vn.entry e ON e.id = c.entryFk - LEFT JOIN vn.travel tr ON tr.id = e.travelFk + FROM sale s + LEFT JOIN itemBarcode b ON b.itemFk = s.itemFk + LEFT JOIN buy c ON c.itemFk = s.itemFk + LEFT JOIN entry e ON e.id = c.entryFk + LEFT JOIN travel tr ON tr.id = e.travelFk WHERE s.ticketFk = ? AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`, [ticketId], myOptions); diff --git a/db/routines/vn/functions/ticket_get.sql b/db/routines/vn/functions/ticket_get.sql index 1f0e9a25a..b55b1297e 100644 --- a/db/routines/vn/functions/ticket_get.sql +++ b/db/routines/vn/functions/ticket_get.sql @@ -1,64 +1,44 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_get`(vParamFk INT) - RETURNS int(11) + RETURNS INT(11) NOT DETERMINISTIC READS SQL DATA -proc:BEGIN - - /* Devuelve el número de ticket o collection consultando en varias tablas posibles - * - * @param vParamFk Número a validar - * @return vValidFk Identificador validado - */ - - DECLARE vValidFk INT; +BEGIN +/** + * Devuelve el número de ticket / collection / sectorCollection consultando + * en que tabla se encuantra en la última semana + * + * @param vParamFk Número a validar + * @return vReturn Identificador validado + */ + DECLARE vReturn INT DEFAULT NULL; + DECLARE vDated DATE; - -- Tabla vn.saleGroup - SELECT s.ticketFk INTO vValidFk - FROM vn.sale s - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk - WHERE sg.id = vParamFk - AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()) - LIMIT 1; - - IF vValidFk THEN - - RETURN vValidFk; - - LEAVE proc; - - END IF; + SET vDated = util.VN_CURDATE() - INTERVAL 1 WEEK; - -- Tabla vn.collection - SELECT c.id INTO vValidFk - FROM vn.collection c - WHERE c.id = vParamFk - AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); - - IF vValidFk THEN - - RETURN vValidFk; - - LEAVE proc; - - END IF; + SELECT COALESCE( + (SELECT s.ticketFk + FROM sale s + JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN saleGroup sg ON sg.id = sgd.saleGroupFk + WHERE sg.id = vParamFk + AND sg.created > vDated + LIMIT 1), + (SELECT c.id + FROM collection c + WHERE c.id = vParamFk + AND c.created > vDated), + (SELECT id + FROM ticket + WHERE id = vParamFk + AND shipped > vDated), + (SELECT id + FROM sectorCollection + WHERE id = vParamFk + AND created > vDated) + ) INTO vReturn; - -- Tabla vn.ticket - SELECT t.id INTO vValidFk - FROM vn.ticket t - WHERE t.id = vParamFk - AND t.shipped > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); - - IF vValidFk THEN - - RETURN vValidFk; - - LEAVE proc; - - END IF; - - RETURN NULL; + RETURN vReturn; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 0a71ada78..09624acd2 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -2,61 +2,88 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getTickets`(vParamFk INT) BEGIN /** - * Selecciona los tickets de una colección/ticket - * @param vParamFk ticketFk/collectionFk - * @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observaciones + * Selecciona los tickets de una colección/ticket/sectorCollection + * @param vParamFk ticketFk/collectionFk/sectorCollection + * @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observation */ DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE vDated DATE; -- Si los sacadores son los de pruebas, pinta los colores - SELECT itemPackingTypeFk INTO vItemPackingTypeFk - FROM vn.collection + SELECT itemPackingTypeFk + INTO vItemPackingTypeFk + FROM collection WHERE id = vParamFk; + + SET vDated = util.yesterday(); - SELECT t.id ticketFk, - IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`, - am.name agencyName, - t.warehouseFk, - w.id salesPersonFk, - IFNULL(tob.description,'') observaciones, - cc.rgb - FROM vn.ticket t - LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 - LEFT JOIN vn.collectionColors cc - ON cc.wagon = tc.wagon - AND cc.shelve = tc.`level` - AND cc.trainFk = c2.trainFk -- PAK 23/12/21 - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN vn.client c ON c.id = t.clientFk - LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id - AND tob.observationTypeFk = 1 - WHERE t.id = vParamFk - AND t.shipped >= util.yesterday() - UNION ALL + WITH observation AS ( + SELECT tob.ticketFk, tob.description + FROM ticketObservation tob + JOIN ticketCollection tc ON tc.ticketFk = tob.ticketFk + LEFT JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE ot.`code` = 'itemPicker' + AND tc.collectionFk = vParamFk + ) SELECT t.id ticketFk, IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, am.name agencyName, t.warehouseFk, - w.id salesPersonFk, - IFNULL(tob.description, '') observaciones, - IF(!(vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb` - FROM vn.ticket t - JOIN vn.ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 - LEFT JOIN vn.collectionColors cc + w.id salesPersonFk, + IFNULL(ob.description,'') observation, + cc.rgb + FROM ticket t + LEFT JOIN ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN collection c2 ON c2.id = tc.collectionFk + LEFT JOIN collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` + AND cc.trainFk = c2.trainFk + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN observation ob ON ob.ticketFk = t.id + WHERE t.id = vParamFk + AND t.shipped >= vDated + UNION ALL + SELECT t.id ticketFk, + IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, + am.name agencyName, + t.warehouseFk, + w.id salesPersonFk, + ob.description, + IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb` + FROM ticket t + JOIN ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN collection c2 ON c2.id = tc.collectionFk + LEFT JOIN collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` - AND cc.trainFk = c2.trainFk -- PAK 23/12/21 - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN vn.client c ON c.id = t.clientFk - LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id - AND tob.observationTypeFk = 1 - WHERE tc.collectionFk = vParamFk; - + AND cc.trainFk = c2.trainFk + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN observation ob ON ob.ticketFk = t.id + WHERE tc.collectionFk = vParamFk + UNION ALL + SELECT sg.ticketFk, + NULL `level`, + am.name agencyName, + t.warehouseFk, + c.salesPersonFk, + ob.description, + NULL `rgb` + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id + JOIN saleGroup sg ON sg.id = ss.saleGroupFk + JOIN ticket t ON t.id = sg.ticketFk + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN observation ob ON ob.ticketFk = t.id + LEFT JOIN client c ON c.id = t.clientFk + WHERE sc.id = vParamFk + AND t.shipped >= vDated; END$$ DELIMITER ; From bc1397d916acea00fe70ef118c4f0d76b5d53dc8 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 11 Apr 2024 12:27:16 +0200 Subject: [PATCH 11/81] refs #6861 feat: reservePrevious --- db/routines/floranet/events/clean.sql | 22 ------- .../floranet/procedures/catalogue_get.sql | 64 ------------------- .../floranet/procedures/contact_request.sql | 20 ------ .../floranet/procedures/deliveryDate_get.sql | 29 --------- .../floranet/procedures/order_confirm.sql | 25 -------- db/routines/floranet/procedures/order_put.sql | 42 ------------ .../floranet/procedures/sliders_get.sql | 20 ------ .../vn/procedures/collection_getTickets.sql | 52 +++++++-------- 8 files changed, 26 insertions(+), 248 deletions(-) delete mode 100644 db/routines/floranet/events/clean.sql delete mode 100644 db/routines/floranet/procedures/catalogue_get.sql delete mode 100644 db/routines/floranet/procedures/contact_request.sql delete mode 100644 db/routines/floranet/procedures/deliveryDate_get.sql delete mode 100644 db/routines/floranet/procedures/order_confirm.sql delete mode 100644 db/routines/floranet/procedures/order_put.sql delete mode 100644 db/routines/floranet/procedures/sliders_get.sql diff --git a/db/routines/floranet/events/clean.sql b/db/routines/floranet/events/clean.sql deleted file mode 100644 index 4477112fd..000000000 --- a/db/routines/floranet/events/clean.sql +++ /dev/null @@ -1,22 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE - DEFINER=`root`@`localhost` - EVENT `floranet`.`clean` - ON SCHEDULE EVERY 1 DAY - STARTS '2024-01-01 23:00:00.000' - ON COMPLETION PRESERVE - ENABLE -DO -BEGIN - DELETE - FROM `order` - WHERE created < CURDATE() - AND isPaid = FALSE; - - DELETE c.* - FROM catalogue c - LEFT JOIN `order` o ON o.catalogueFk = c.id - WHERE c.created < CURDATE() - AND o.id IS NULL; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/floranet/procedures/catalogue_get.sql b/db/routines/floranet/procedures/catalogue_get.sql deleted file mode 100644 index e45fa7ddf..000000000 --- a/db/routines/floranet/procedures/catalogue_get.sql +++ /dev/null @@ -1,64 +0,0 @@ -DROP PROCEDURE IF EXISTS floranet.catalogue_get; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.catalogue_get(vLanded DATE, vPostalCode VARCHAR(15)) -READS SQL DATA -proc:BEGIN -/** - * Returns list, price and all the stuff regarding the floranet items - * - * @param vLanded Delivery date - * @param vPostalCode Delivery address postal code - */ - DECLARE vLastCatalogueFk INT; - DECLARE vLockName VARCHAR(20); - DECLARE vLockTime INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK(vLockName); - - RESIGNAL; - END; - - SET vLockName = 'catalogue_get'; - SET vLockTime = 15; - - IF NOT GET_LOCK(vLockName, vLockTime) THEN - LEAVE proc; - END IF; - - SELECT MAX(id) INTO vLastCatalogueFk - FROM catalogue; - - INSERT INTO catalogue( - name, - price, - itemFk, - dated, - postalCode, - `type`, - image, - description - ) - SELECT i.name, - i.`size`, - i.id, - vLanded, - vPostalCode, - it.name, - CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image), - i.description - FROM vn.item i - JOIN vn.itemType it ON it.id = i.typeFk - WHERE it.code IN ('FNR','FNP'); - - SELECT * - FROM catalogue - WHERE id > IFNULL(vLastCatalogueFk,0); - - DO RELEASE_LOCK(vLockName); - -END$$ -DELIMITER ; diff --git a/db/routines/floranet/procedures/contact_request.sql b/db/routines/floranet/procedures/contact_request.sql deleted file mode 100644 index 044c22c6f..000000000 --- a/db/routines/floranet/procedures/contact_request.sql +++ /dev/null @@ -1,20 +0,0 @@ -DROP PROCEDURE IF EXISTS floranet.contact_request; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` -PROCEDURE floranet.contact_request( - vName VARCHAR(100), - vPhone VARCHAR(15), - vEmail VARCHAR(100), - vMessage TEXT) -READS SQL DATA -BEGIN -/** - * Set actions for contact request. - * - * @param vPostalCode Delivery address postal code - */ - -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/floranet/procedures/deliveryDate_get.sql b/db/routines/floranet/procedures/deliveryDate_get.sql deleted file mode 100644 index 29751ebe4..000000000 --- a/db/routines/floranet/procedures/deliveryDate_get.sql +++ /dev/null @@ -1,29 +0,0 @@ -DROP PROCEDURE IF EXISTS floranet.deliveryDate_get; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `floranet`.`deliveryDate_get`(vPostalCode VARCHAR(15)) - READS SQL DATA -BEGIN -/** - * Returns available dates for this postalCode, in the next seven days - * - * @param vPostalCode Delivery address postal code - */ - DECLARE vCurrentDayOfWeek INT; - - SET vCurrentDayOfWeek = DAYOFWEEK(NOW()); - - SELECT DISTINCT nextDay - FROM ( - SELECT CURDATE() + INTERVAL IF( - apc.dayOfWeek >= vCurrentDayOfWeek, - apc.dayOfWeek - vCurrentDayOfWeek, - 7 - apc.dayOfWeek - ) DAY nextDay, - NOW() + INTERVAL apc.hoursInAdvance - 12 HOUR minDeliveryTime - FROM addressPostCode apc - WHERE apc.postCode = vPostalCode - HAVING nextDay > minDeliveryTime) sub; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/floranet/procedures/order_confirm.sql b/db/routines/floranet/procedures/order_confirm.sql deleted file mode 100644 index fed123663..000000000 --- a/db/routines/floranet/procedures/order_confirm.sql +++ /dev/null @@ -1,25 +0,0 @@ -DROP PROCEDURE IF EXISTS floranet.order_confirm; - -DELIMITER $$ -$$ - -CREATE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT) -READS SQL DATA - -BEGIN -/** Update order.isPaid field - * - * @param vCatalogueFk floranet.catalogue.id - * - * @returns floranet.order.isPaid - */ - UPDATE `order` - SET isPaid = TRUE, - payed = NOW() - WHERE catalogueFk = vCatalogueFk; - - SELECT isPaid - FROM `order` - WHERE catalogueFk = vCatalogueFk; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/floranet/procedures/order_put.sql b/db/routines/floranet/procedures/order_put.sql deleted file mode 100644 index c26cef19a..000000000 --- a/db/routines/floranet/procedures/order_put.sql +++ /dev/null @@ -1,42 +0,0 @@ -DROP PROCEDURE IF EXISTS floranet.order_put; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.order_put(vOrder JSON) -READS SQL DATA -BEGIN -/** - * Get and process an order - * - * @param vOrder Data of the order - * - * Customer data: , , - * - * Item data: , - * - * Delivery data: ,
, - * - */ - INSERT IGNORE INTO `order`( - catalogueFk, - customerName, - email, - customerPhone, - message, - deliveryName, - address, - deliveryPhone - ) - VALUES (JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.catalogueFk')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.customerName')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.email')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.customerPhone')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.message')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.deliveryName')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.address')), - JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.deliveryPhone')) - ); - - SELECT LAST_INSERT_ID() orderFk; -END$$ -DELIMITER ; diff --git a/db/routines/floranet/procedures/sliders_get.sql b/db/routines/floranet/procedures/sliders_get.sql deleted file mode 100644 index bd791dec7..000000000 --- a/db/routines/floranet/procedures/sliders_get.sql +++ /dev/null @@ -1,20 +0,0 @@ -DROP PROCEDURE IF EXISTS floranet.sliders_get; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.sliders_get() -READS SQL DATA -BEGIN -/** - * Returns list of url for sliders - */ - SELECT - CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url, - i.longName - FROM vn.item i - JOIN vn.itemType it ON it.id = i.typeFk - WHERE it.code IN ('FNR','FNP') - LIMIT 3; - -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 09624acd2..3f1239e9b 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -19,9 +19,9 @@ BEGIN WITH observation AS ( SELECT tob.ticketFk, tob.description - FROM ticketObservation tob - JOIN ticketCollection tc ON tc.ticketFk = tob.ticketFk - LEFT JOIN observationType ot ON ot.id = tob.observationTypeFk + FROM vn.ticketObservation tob + JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk + LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk WHERE ot.`code` = 'itemPicker' AND tc.collectionFk = vParamFk ) @@ -32,17 +32,17 @@ BEGIN w.id salesPersonFk, IFNULL(ob.description,'') observation, cc.rgb - FROM ticket t - LEFT JOIN ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN collection c2 ON c2.id = tc.collectionFk - LEFT JOIN collectionColors cc + FROM vn.ticket t + LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk + LEFT JOIN vn.collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE t.id = vParamFk AND t.shipped >= vDated @@ -54,17 +54,17 @@ BEGIN w.id salesPersonFk, ob.description, IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb` - FROM ticket t - JOIN ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN collection c2 ON c2.id = tc.collectionFk - LEFT JOIN collectionColors cc + FROM vn.ticket t + JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk + LEFT JOIN vn.collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE tc.collectionFk = vParamFk UNION ALL @@ -75,14 +75,14 @@ BEGIN c.salesPersonFk, ob.description, NULL `rgb` - FROM sectorCollection sc - JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id - JOIN saleGroup sg ON sg.id = ss.saleGroupFk - JOIN ticket t ON t.id = sg.ticketFk - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + FROM vn.sectorCollection sc + JOIN vn.sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id + JOIN vn.saleGroup sg ON sg.id = ss.saleGroupFk + JOIN vn.ticket t ON t.id = sg.ticketFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN observation ob ON ob.ticketFk = t.id - LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN vn.client c ON c.id = t.clientFk WHERE sc.id = vParamFk AND t.shipped >= vDated; END$$ From 3a8dcbfd292a1f1846e003a657143c366db1a3a5 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 11 Apr 2024 13:45:43 +0200 Subject: [PATCH 12/81] refs #6861 feat:reserve previos --- back/methods/collection/getTickets.js | 5 +++-- .../itemShelvingSale_reserveBySectorCollection.sql | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index a16757fd4..663b70e94 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -108,13 +108,14 @@ module.exports = Self => { LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN parking p2 ON p2.id = sg.parkingFk JOIN item i ON i.id = s.itemFk - LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN origin o ON o.id = i.originFk - WHERE sc.id = ? + WHERE sc.id = ? + AND sgd.saleGroupFk GROUP BY s.id, ish.id, p.code, p2.code`, [id, id], myOptions); if (print) await Self.rawSql(`CALL vn.collection_printSticker(?, ?)`, [id, null], myOptions); diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql index 3ea351288..52d83a75d 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql @@ -11,7 +11,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk)) ENGINE = MEMORY - SELECT s.id + SELECT s.id saleFk, str.workerFk userFK FROM sectorCollectionSaleGroup sc JOIN saleGroupDetail sg ON sg.saleGroupFk = sc.saleGroupFk JOIN sale s ON sg.saleFk = s.id From 0f1a086bca6c2493c9513378b1fdba8d34bea922 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Apr 2024 13:03:27 +0200 Subject: [PATCH 13/81] refs #6861 feat:reserve previos --- db/routines/vn/procedures/itemShelvingSale_unpicked.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_unpicked.sql b/db/routines/vn/procedures/itemShelvingSale_unpicked.sql index 6813a65b1..889cadfd0 100644 --- a/db/routines/vn/procedures/itemShelvingSale_unpicked.sql +++ b/db/routines/vn/procedures/itemShelvingSale_unpicked.sql @@ -27,9 +27,9 @@ BEGIN LEFT JOIN saleGroupDetail sg ON sg.saleFk = ish.saleFk WHERE ish.id = vSelf; - IF vIsSaleGroup THEN + /*IF vIsSaleGroup THEN CALL util.throw('Can not unpicked a sale group'); - END IF; + END IF;*/ START TRANSACTION; From 611f907ef0122b5c6137c0d6d61b38dc1d231ea7 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 25 Apr 2024 16:15:53 +0200 Subject: [PATCH 14/81] refs #6861 feat:reserveWithReservation --- .../vn/procedures/collection_addWithReservation.sql | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index ea2632b05..ac0721146 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -2,7 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_addWithReservation`( vItemFk INT, vQuantity INT, - vTicketFk INT + vTicketFk INT, + vSaleGroupFk INT ) BEGIN /** @@ -12,7 +13,9 @@ BEGIN * @param vItemFk id of item * @param vQuantity quantity to be added to the ticket * @param vTicketFk ticket to which the sales line is added + * @param vSaleGroupFk saleGroupFk id to add saleGroupDetail */ + DECLARE vWarehouseFk INT; DECLARE vCacheAvailableFk INT; DECLARE vAvailable INT; @@ -72,7 +75,7 @@ BEGIN CALL sale_calculateComponent(vSaleFk, NULL); CALL itemShelvingSale_addBySale(vSaleFk); - + IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN SET vHasThrow = TRUE; END IF; @@ -81,6 +84,10 @@ BEGIN IF vHasThrow THEN CALL util.throw("No hay disponibilidad para el artículo seleccionado"); ELSE + IF vSaleGroupFk THEN + INSERT INTO saleGroupDetail + SET saleFk = vSaleFk, + saleGroupFk = vSaleGroupFk, COMMIT; END IF; END$$ From 3146f4f5b611a57d371ad3456049f1300d7deb45 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 2 May 2024 14:59:30 +0200 Subject: [PATCH 15/81] refactor: refs #6701 Refactor claim_ratio_routine --- .../bi/procedures/claim_ratio_routine.sql | 166 ------------------ db/routines/vn/procedures/claimRatio_add.sql | 154 ++++++++++++++++ .../11028-silverCarnation/00-firstScript.sql | 4 + 3 files changed, 158 insertions(+), 166 deletions(-) delete mode 100644 db/routines/bi/procedures/claim_ratio_routine.sql create mode 100644 db/routines/vn/procedures/claimRatio_add.sql create mode 100644 db/versions/11028-silverCarnation/00-firstScript.sql diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql deleted file mode 100644 index ae87e15a2..000000000 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ /dev/null @@ -1,166 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`claim_ratio_routine`() -BEGIN - DECLARE vMonthToRefund INT DEFAULT 4; - - /* - * PAK 2015-11-20 - * Se trata de añadir a la tabla Greuges todos los - * cargos que luego vamos a utilizar para calcular el recobro - */ - - -- Reclamaciones demasiado sensibles - - INSERT INTO vn.greuge(shipped, clientFk, description, - amount, greugeTypeFk, ticketFk) - SELECT c.ticketCreated - , c.clientFk - , concat('Claim ', c.id,' : ', s.concept) - ,round( -1 * ((c.responsibility -1)/4) * s.quantity * - s.price * (100 - s.discount) / 100, 2) - , 4 - , s.ticketFk - FROM vn.sale s - JOIN vn.claimEnd ce ON ce.saleFk = s.id - JOIN vn.claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3; - - -- Reclamaciones que pasan a Maná - - INSERT INTO vn.greuge(shipped, clientFk, description, - amount, greugeTypeFk, ticketFk) - SELECT c.ticketCreated - , c.clientFk - , concat('Claim_mana ',c.id,' : ', s.concept) - ,round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2) - ,3 - ,s.ticketFk - FROM vn.sale s - JOIN vn.claimEnd ce ON ce.saleFk = s.id - JOIN vn.claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3 - AND c.isChargedToMana; - - -- Marcamos para no repetir - UPDATE vn.claimEnd ce - JOIN vn.claim c ON c.id = ce.claimFk - SET c.isChargedToMana = TRUE - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3; - - -- Recobros - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - CREATE TEMPORARY TABLE tmp.ticket_list - (PRIMARY KEY (Id_Ticket)) - SELECT DISTINCT t.id Id_Ticket - FROM vn.saleComponent sc - JOIN vn.sale s ON sc.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.ticketLastState ts ON ts.ticketFk = t.id - JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk - JOIN vn.state st ON st.id = tt.stateFk - WHERE sc.componentFk = 17 - AND sc.isGreuge = 0 - AND t.shipped >= '2016-10-01' - AND t.shipped < util.VN_CURDATE() - AND st.alertLevel >= 3; - - DELETE g.* - FROM vn.greuge g - JOIN tmp.ticket_list t ON g.ticketFk = t.Id_Ticket - WHERE g.greugeTypeFk = 2; - - INSERT INTO vn.greuge(clientFk, description, amount,shipped, - greugeTypeFk, ticketFk) - SELECT t.clientFk - ,concat('recobro ', s.ticketFk), - round(SUM(sc.value*s.quantity),2) - AS dif, - date(t.shipped) - , 2 - ,tt.Id_Ticket - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id - JOIN vn.saleComponent sc - ON sc.saleFk = s.id AND sc.componentFk = 17 - GROUP BY t.id - HAVING ABS(dif) > 1; - - UPDATE vn.saleComponent sc - JOIN vn.sale s ON s.id = sc.saleFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = s.ticketFk - SET sc.isGreuge = 1 - WHERE sc.componentFk = 17; - - /* - * Recalculamos la ratio de las reclamaciones, que luego - * se va a utilizar en el recobro - */ - - REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT id, 0,0,0,0 - FROM vn.client; - - REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones, - round(Reclamaciones / (12*fm.Consumo),4), 0 - FROM bi.facturacion_media_anual fm - LEFT JOIN( - SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) * - s.quantity * s.price * (100 - s.discount) / 100)) - AS Reclamaciones - FROM vn.sale s - JOIN vn.claimEnd ce ON ce.saleFk = s.id - JOIN vn.claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND c.claimStateFk = 3 - AND c.ticketCreated >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) - GROUP BY c.clientFk - ) claims ON claims.clientFk = fm.Id_Cliente; - - - -- Calculamos el porcentaje del recobro para añadirlo al precio de venta - UPDATE bi.claims_ratio cr - JOIN ( - SELECT clientFk Id_Cliente, IFNULL(SUM(amount), 0) AS Greuge - FROM vn.greuge - WHERE shipped <= util.VN_CURDATE() - GROUP BY clientFk - ) g ON g.Id_Cliente = cr.Id_Cliente - SET recobro = GREATEST(0,round(IFNULL(Greuge, 0) / - (IFNULL(Consumo, 0) * vMonthToRefund / 12 ) ,3)); - - -- Protección neonatos - UPDATE bi.claims_ratio cr - JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente - SET recobro = 0, Ratio = 0 - WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); - - -- CLIENTE 7983, JULIAN SUAU - UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; - - -- CLIENTE 4358 - UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 4358; - - -- CLIENTE 5523, VERDECORA - UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; - - -- CLIENTE 15979, SERVEIS VETERINARIS - UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 15979; - - -- CLIENTE 5189 i 8942, son de CSR i son el mateix client - UPDATE bi.claims_ratio cr - JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro - FROM bi.claims_ratio - WHERE Id_Cliente IN ( 5189,8942) - ) sub - SET cr.recobro = sub.recobro - WHERE Id_Cliente IN ( 5189,8942); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql new file mode 100644 index 000000000..2f64f8c7e --- /dev/null +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -0,0 +1,154 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`() +BEGIN +/* +* PAK 2015-11-20 +* Se trata de añadir a la tabla Greuges todos los +* cargos que luego vamos a utilizar para calcular el recobro +*/ + DECLARE vMonthToRefund INT DEFAULT 4; + DECLARE vRecoveryGreugeType INT; + + SELECT id INTO vRecoveryGreugeType + FROM greugeType + WHERE code = 'recovery'; + + -- Reclamaciones demasiado sensibles + INSERT INTO greuge(shipped, clientFk, description, + amount, greugeTypeFk, ticketFk) + SELECT c.ticketCreated + , c.clientFk + , concat('Claim ', c.id,' : ', s.concept) + ,round( -1 * ((c.responsibility -1)/4) * s.quantity * + s.price * (100 - s.discount) / 100, 2) + , 4 + , s.ticketFk + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claim c ON c.id = ce.claimFk + WHERE ce.claimDestinationFk NOT IN (1,5) + AND NOT ce.isGreuge + AND c.claimStateFk = 3; + + -- Reclamaciones que pasan a Maná + INSERT INTO greuge(shipped, + clientFk, + `description`, + amount, + greugeTypeFk, + ticketFk) + SELECT c.ticketCreated, + c.clientFk, + concat('Claim_mana ',c.id,' : ', s.concept), + round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), + 3, + s.ticketFk + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claim c ON c.id = ce.claimFk + WHERE ce.claimDestinationFk NOT IN (1,5) + AND NOT ce.isGreuge + AND c.claimStateFk = 3 + AND c.isChargedToMana; + + -- Marcamos para no repetir + UPDATE claimEnd ce + JOIN claim c ON c.id = ce.claimFk + SET c.isChargedToMana = TRUE + WHERE ce.claimDestinationFk NOT IN (1,5) + AND NOT ce.isGreuge + AND c.claimStateFk = 3; + + -- Recobros + CREATE OR REPLACE TEMPORARY TABLE tTicketList + (PRIMARY KEY (ticketFk)) + SELECT DISTINCT s.ticketFk + FROM saleComponent sc + JOIN sale s ON sc.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN ticketLastState ts ON ts.ticketFk = t.id + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state st ON st.id = tt.stateFk + WHERE sc.componentFk = 17 + AND sc.isGreuge = 0 + AND t.shipped >= '2016-10-01' + AND t.shipped < util.VN_CURDATE() + AND st.alertLevel >= 3; + + DELETE g.* + FROM greuge g + JOIN tTicketList t ON t.ticketFk = g.ticketFk + WHERE g.greugeTypeFk = vRecoveryGreugeType; + + INSERT INTO greuge(clientFk, + `description`, + amount, + shipped, + greugeTypeFk, + ticketFk) + SELECT t.clientFk, + 'Recobro', + - ROUND(SUM(sc.value * s.quantity), 2) dif, + DATE(t.shipped), + vRecoveryGreugeType, + tl.ticketFk + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN tTicketList tl ON tl.ticketFk = t.id + JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = 17 + GROUP BY t.id + HAVING ABS(dif) > 1; + + UPDATE saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN tTicketList tl ON tl.ticketFk = s.ticketFk + SET sc.isGreuge = TRUE + WHERE sc.componentFk = 17; + + /* + * Recalculamos la ratio de las reclamaciones, que luego + * se va a utilizar en el recobro + */ + REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) + SELECT id, 0, 0, 0, 0 + FROM client; + + REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) + SELECT cac.clientFk, 12 * cac.invoiced, totalClaims, + ROUND(totalClaims / (12 * cac.invoiced), 4), 0 + FROM bs.clientAnnualConsumption cac + LEFT JOIN( + SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) * + s.quantity * s.price * (100 - s.discount) / 100)) + totalClaims + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claim c ON c.id = ce.claimFk + WHERE ce.claimDestinationFk NOT IN (1,5) + AND c.claimStateFk = 3 + AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR + GROUP BY c.clientFk + ) claims ON claims.clientFk = fm.Id_Cliente; + + -- Calculamos el porcentaje del recobro para añadirlo al precio de venta + UPDATE claimRatio cr + JOIN ( + SELECT clientFk, IFNULL(SUM(amount), 0) AS Greuge + FROM greuge + WHERE shipped <= util.VN_CURDATE() + GROUP BY clientFk + ) g ON g.clientFk = cr.clientFk + SET cr.priceIncreasing = GREATEST(0, round(IFNULL(Greuge, 0) / + (IFNULL(Consumo, 0) * vMonthToRefund / 12 ), 3)); + + -- Protección neonatos + UPDATE claimRatio cr + JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk + SET cr.priceIncreasing = 0, + cr.claimingRate = 0 + WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH; + + DROP TEMPORARY TABLE tTicketList; +END$$ +DELIMITER ; diff --git a/db/versions/11028-silverCarnation/00-firstScript.sql b/db/versions/11028-silverCarnation/00-firstScript.sql new file mode 100644 index 000000000..f865b0caf --- /dev/null +++ b/db/versions/11028-silverCarnation/00-firstScript.sql @@ -0,0 +1,4 @@ +UPDATE IGNORE bs.nightTask + SET `procedure` = 'claimRatio_add', + `schema` = 'vn' + WHERE `procedure` = 'claim_ratio_routine'; From 883f6f18a3b48560e82446251453057f5ef4a894 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 3 May 2024 13:47:55 +0200 Subject: [PATCH 16/81] refactor: refs #6701 Refactor claim_ratio_routine --- db/routines/vn/procedures/claimRatio_add.sql | 171 ++++++++++++------- 1 file changed, 108 insertions(+), 63 deletions(-) diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 2f64f8c7e..deb5cc068 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -7,57 +7,82 @@ BEGIN * cargos que luego vamos a utilizar para calcular el recobro */ DECLARE vMonthToRefund INT DEFAULT 4; - DECLARE vRecoveryGreugeType INT; + DECLARE vRecoveryGreugeType INT + DEFAULT (SELECT id FROM greugeType WHERE code = 'recovery'); + DECLARE vManaGreugeType INT + DEFAULT (SELECT id FROM greugeType WHERE code = 'mana'); + DECLARE vClaimGreugeType INT + DEFAULT (SELECT id FROM greugeType WHERE code = 'claim'); + DECLARE vDebtComponentType INT + DEFAULT (SELECT id FROM component WHERE code = 'debtCollection'); - SELECT id INTO vRecoveryGreugeType - FROM greugeType - WHERE code = 'recovery'; + IF vRecoveryGreugeType IS NULL + OR vManaGreugeType IS NULL + OR vClaimGreugeType IS NULL + OR vDebtComponentType IS NULL THEN + + CALL util.throw('Required variables not found'); + END IF; -- Reclamaciones demasiado sensibles - INSERT INTO greuge(shipped, clientFk, description, - amount, greugeTypeFk, ticketFk) - SELECT c.ticketCreated - , c.clientFk - , concat('Claim ', c.id,' : ', s.concept) - ,round( -1 * ((c.responsibility -1)/4) * s.quantity * - s.price * (100 - s.discount) / 100, 2) - , 4 - , s.ticketFk - FROM sale s - JOIN claimEnd ce ON ce.saleFk = s.id - JOIN claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3; - - -- Reclamaciones que pasan a Maná - INSERT INTO greuge(shipped, - clientFk, - `description`, - amount, - greugeTypeFk, - ticketFk) + INSERT INTO greuge( + shipped, + clientFk, + `description`, + amount, + greugeTypeFk, + ticketFk + ) SELECT c.ticketCreated, c.clientFk, - concat('Claim_mana ',c.id,' : ', s.concept), - round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), - 3, + CONCAT('Claim ', c.id,' : ', s.concept), + ROUND(-1 * ((c.responsibility - 1) / 4) * s.quantity * + s.price * (100 - s.discount) / 100, 2), + vClaimGreugeType, s.ticketFk FROM sale s JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) + JOIN claimState cs ON cs.id = c.claimStateFk + WHERE ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge - AND c.claimStateFk = 3 + AND cs.code = 'resolved'; + + -- Reclamaciones que pasan a Maná + INSERT INTO greuge( + shipped, + clientFk, + `description`, + amount, + greugeTypeFk, + ticketFk + ) + SELECT c.ticketCreated, + c.clientFk, + CONCAT('Claim_mana ', c.id,' : ', s.concept), + ROUND( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), + vManaGreugeType, + s.ticketFk + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk + JOIN claim c ON c.id = ce.claimFk + JOIN claimState cs ON cs.id = c.claimStateFk + WHERE cd.description NOT IN ('Bueno', 'Corregido') + AND NOT ce.isGreuge + AND cs.code = 'resolved' AND c.isChargedToMana; -- Marcamos para no repetir UPDATE claimEnd ce + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk + JOIN claimState cs ON cs.id = c.claimStateFk SET c.isChargedToMana = TRUE - WHERE ce.claimDestinationFk NOT IN (1,5) + WHERE cd.description NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge - AND c.claimStateFk = 3; + AND cs.code = 'resolved'; -- Recobros CREATE OR REPLACE TEMPORARY TABLE tTicketList @@ -69,23 +94,26 @@ BEGIN JOIN ticketLastState ts ON ts.ticketFk = t.id JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk JOIN state st ON st.id = tt.stateFk - WHERE sc.componentFk = 17 - AND sc.isGreuge = 0 + JOIN alertLevel al ON al.id = st.alertLevel + WHERE sc.componentFk = vDebtComponentType + AND NOT sc.isGreuge AND t.shipped >= '2016-10-01' AND t.shipped < util.VN_CURDATE() - AND st.alertLevel >= 3; + AND al.code = 'DELIVERED'; DELETE g.* FROM greuge g JOIN tTicketList t ON t.ticketFk = g.ticketFk WHERE g.greugeTypeFk = vRecoveryGreugeType; - INSERT INTO greuge(clientFk, - `description`, - amount, - shipped, - greugeTypeFk, - ticketFk) + INSERT INTO greuge( + clientFk, + `description`, + amount, + shipped, + greugeTypeFk, + ticketFk + ) SELECT t.clientFk, 'Recobro', - ROUND(SUM(sc.value * s.quantity), 2) dif, @@ -96,51 +124,68 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk JOIN tTicketList tl ON tl.ticketFk = t.id JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = 17 + AND sc.componentFk = vDebtComponentType GROUP BY t.id - HAVING ABS(dif) > 1; + HAVING ABS(dif) > 1; UPDATE saleComponent sc JOIN sale s ON s.id = sc.saleFk JOIN tTicketList tl ON tl.ticketFk = s.ticketFk SET sc.isGreuge = TRUE - WHERE sc.componentFk = 17; + WHERE sc.componentFk = vDebtComponentType; /* * Recalculamos la ratio de las reclamaciones, que luego * se va a utilizar en el recobro */ - REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) - SELECT id, 0, 0, 0, 0 - FROM client; + REPLACE claimRatio( + clientFk, + yearSale, + claimAmount, + claimingRate, + priceIncreasing + ) + SELECT id, 0, 0, 0, 0 FROM client; - REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) - SELECT cac.clientFk, 12 * cac.invoiced, totalClaims, - ROUND(totalClaims / (12 * cac.invoiced), 4), 0 + REPLACE claimRatio( + clientFk, + yearSale, + claimAmount, + claimingRate, + priceIncreasing + ) + SELECT cac.clientFk, + 12 * cac.invoiced, + totalClaims, + ROUND(totalClaims / (12 * cac.invoiced), 4), + 0 FROM bs.clientAnnualConsumption cac - LEFT JOIN( - SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) * - s.quantity * s.price * (100 - s.discount) / 100)) - totalClaims + LEFT JOIN ( + SELECT c.clientFk, + ROUND(SUM(-1 * ((c.responsibility - 1) / 4) * + s.quantity * s.price * (100 - s.discount) + / 100)) totalClaims FROM sale s JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND c.claimStateFk = 3 + JOIN claimState cs ON cs.id = c.claimStateFk + WHERE ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') + AND cs.code = 'resolved' AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR GROUP BY c.clientFk - ) claims ON claims.clientFk = fm.Id_Cliente; + ) sub ON sub.clientFk = cac.clientFk; -- Calculamos el porcentaje del recobro para añadirlo al precio de venta UPDATE claimRatio cr JOIN ( - SELECT clientFk, IFNULL(SUM(amount), 0) AS Greuge + SELECT clientFk, IFNULL(SUM(amount), 0) greuge FROM greuge WHERE shipped <= util.VN_CURDATE() GROUP BY clientFk - ) g ON g.clientFk = cr.clientFk - SET cr.priceIncreasing = GREATEST(0, round(IFNULL(Greuge, 0) / - (IFNULL(Consumo, 0) * vMonthToRefund / 12 ), 3)); + ) sub ON subg.clientFk = cr.clientFk + SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) / + (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)); -- Protección neonatos UPDATE claimRatio cr From f0b814c79b895ee4ac6487a6a4494c35feaf8c64 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 3 May 2024 14:15:55 +0200 Subject: [PATCH 17/81] refactor: refs #6701 Refactor claim_ratio_routine --- db/dump/fixtures.before.sql | 6 +-- db/routines/vn/procedures/claimRatio_add.sql | 37 +++++++------------ .../11028-silverCarnation/00-firstScript.sql | 6 +++ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 06e94c99e..6b8166caa 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -831,9 +831,9 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) VALUES (1, 'Diff', 'diff'), - (2, 'Recover', 'recover'), - (3, 'Mana', 'mana'), - (4, 'Reclaim', 'reclaim'), + (2, 'Recobro', 'recovery'), + (3, 'Maná', 'mana'), + (4, 'Reclamación', 'claim'), (5, 'Heritage', 'heritage'), (6, 'Miscellaneous', 'miscellaneous'), (7, 'Freight Pickup', 'freightPickUp'); diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index deb5cc068..36b9023da 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -2,9 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`() BEGIN /* -* PAK 2015-11-20 -* Se trata de añadir a la tabla Greuges todos los -* cargos que luego vamos a utilizar para calcular el recobro +* Añade a la tabla greuges todos los cargos necesario y +* que luego lo utilizamos para calcular el recobro. */ DECLARE vMonthToRefund INT DEFAULT 4; DECLARE vRecoveryGreugeType INT @@ -61,7 +60,8 @@ BEGIN SELECT c.ticketCreated, c.clientFk, CONCAT('Claim_mana ', c.id,' : ', s.concept), - ROUND( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), + ROUND(((c.responsibility - 1) / 4) * s.quantity * + s.price * (100 - s.discount) / 100, 2), vManaGreugeType, s.ticketFk FROM sale s @@ -134,20 +134,7 @@ BEGIN SET sc.isGreuge = TRUE WHERE sc.componentFk = vDebtComponentType; - /* - * Recalculamos la ratio de las reclamaciones, que luego - * se va a utilizar en el recobro - */ - REPLACE claimRatio( - clientFk, - yearSale, - claimAmount, - claimingRate, - priceIncreasing - ) - SELECT id, 0, 0, 0, 0 FROM client; - - REPLACE claimRatio( + INSERT INTO claimRatio( clientFk, yearSale, claimAmount, @@ -163,8 +150,8 @@ BEGIN LEFT JOIN ( SELECT c.clientFk, ROUND(SUM(-1 * ((c.responsibility - 1) / 4) * - s.quantity * s.price * (100 - s.discount) - / 100)) totalClaims + s.quantity * s.price * (100 - s.discount) + / 100)) totalClaims FROM sale s JOIN claimEnd ce ON ce.saleFk = s.id JOIN claimDestination cd ON cd.id = ce.claimDestinationFk @@ -183,17 +170,19 @@ BEGIN FROM greuge WHERE shipped <= util.VN_CURDATE() GROUP BY clientFk - ) sub ON subg.clientFk = cr.clientFk + ) sub ON sub.clientFk = cr.clientFk SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) / - (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)); + (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)) + WHERE cr.dated = util.VN_CURDATE(); -- Protección neonatos UPDATE claimRatio cr JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk SET cr.priceIncreasing = 0, cr.claimingRate = 0 - WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH; - + WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH + AND cr.dated = util.VN_CURDATE(); + DROP TEMPORARY TABLE tTicketList; END$$ DELIMITER ; diff --git a/db/versions/11028-silverCarnation/00-firstScript.sql b/db/versions/11028-silverCarnation/00-firstScript.sql index f865b0caf..9d291f451 100644 --- a/db/versions/11028-silverCarnation/00-firstScript.sql +++ b/db/versions/11028-silverCarnation/00-firstScript.sql @@ -2,3 +2,9 @@ UPDATE IGNORE bs.nightTask SET `procedure` = 'claimRatio_add', `schema` = 'vn' WHERE `procedure` = 'claim_ratio_routine'; + +ALTER TABLE vn.claimRatio ADD dated DATE DEFAULT current_timestamp() NOT NULL; +ALTER TABLE vn.claimRatio CHANGE dated dated DATE DEFAULT current_timestamp() NOT NULL FIRST; +ALTER TABLE vn.claimRatio DROP FOREIGN KEY claimRatio_ibfk_1; +ALTER TABLE vn.claimRatio DROP PRIMARY KEY; +ALTER TABLE vn.claimRatio ADD CONSTRAINT claimRatio_pk PRIMARY KEY (dated,clientFk); From 5a0882c2ac91c5ee7c9a1b087893822549d61a17 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 8 May 2024 10:59:19 +0200 Subject: [PATCH 18/81] refs #6861 feat:sectoCollection reserve --- .../collection_addWithReservation.sql | 11 ++++---- .../procedures/itemShelvingSale_reserve.sql | 2 ++ ...ShelvingSale_reserveBySectorCollection.sql | 15 ++++++++-- .../sectorCollection_getPartial.sql | 19 +++++++++++++ .../sectorCollection_hasSalesReserved.sql | 28 +++++++++++++++++++ db/versions/10852-pinkOak/00-firstScript.sql | 2 ++ 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 db/routines/vn/procedures/sectorCollection_getPartial.sql create mode 100644 db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index ac0721146..cc207b572 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -85,10 +85,11 @@ BEGIN CALL util.throw("No hay disponibilidad para el artículo seleccionado"); ELSE IF vSaleGroupFk THEN - INSERT INTO saleGroupDetail - SET saleFk = vSaleFk, - saleGroupFk = vSaleGroupFk, - COMMIT; - END IF; + INSERT INTO saleGroupDetail + SET saleFk = vSaleFk, + saleGroupFk = vSaleGroupFk; + COMMIT; + END IF; + END IF ; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_reserve.sql b/db/routines/vn/procedures/itemShelvingSale_reserve.sql index afe65bd78..803059423 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reserve.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reserve.sql @@ -52,6 +52,7 @@ BEGIN FROM tmp.sale ts JOIN sale s ON s.id = ts.saleFk JOIN itemShelving ish ON ish.itemFk = s.itemFk + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id LEFT JOIN ( SELECT itemShelvingFk, SUM(quantity) reservedQuantity FROM itemShelvingSale @@ -64,6 +65,7 @@ BEGIN JOIN productionConfig pc WHERE w.id = vWarehouseFk AND NOT sc.isHideForPickers + AND iss.id IS NULL ORDER BY s.id, p.pickingOrder >= vLastPickingOrder, diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql index 52d83a75d..b8387d20c 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql @@ -8,6 +8,8 @@ BEGIN * * @param vSectorCollectionFk Identificador de sectorCollection */ + DECLARE vHasSales BOOL; + CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk)) ENGINE = MEMORY @@ -18,9 +20,18 @@ BEGIN JOIN saleTracking str ON str.saleFk = s.id JOIN `state` st ON st.id = str.stateFk AND st.code = 'PREVIOUS_PREPARATION' + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id WHERE sc.sectorCollectionFk = vSectorCollectionFk - AND str.workerFk = account.myUser_getId(); + AND str.workerFk = account.myUser_getId() + AND iss.id IS NULL; - CALL itemShelvingSale_reserve(); + SELECT COUNT(*)INTO vHasSales + FROM tmp.sale; + + IF vHasSales THEN + CALL itemShelvingSale_reserve(); + ELSE + CALL util.throw ('There are not sales to reserve'); + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/sectorCollection_getPartial.sql b/db/routines/vn/procedures/sectorCollection_getPartial.sql new file mode 100644 index 000000000..2f59f591a --- /dev/null +++ b/db/routines/vn/procedures/sectorCollection_getPartial.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_getPartial`() +BEGIN +/** + * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas + * + */ + SELECT DISTINCT sc.id collectionFk, sc.created + FROM vn.sectorCollection sc + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + LEFT JOIN vn.sale sl ON sl.id = sgd.saleFk + LEFT JOIN itemShelvingSale iss ON iss.saleFk = sl.id + WHERE sc.userFk = account.myUser_getId() + AND (ISNULL(scsg.sectorCollectionFk) + OR (NOT iss.isPicked)) + AND sc.created > util.VN_CURDATE() - INTERVAL 1 DAY; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql new file mode 100644 index 000000000..e0ef46a86 --- /dev/null +++ b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql @@ -0,0 +1,28 @@ +CREATE DEFINER=`root`@`localhost` FUNCTION vn.sectorCollection_hasSalesReserved(vSelf INT) RETURNS tinyint(1) +DETERMINISTIC +BEGIN + +/** +* Devuelve si sectorCollection tiene reservas +* @param vSelf Id de sectorCollection +* +* returns BOOLEAN +*/ + + DECLARE vHasSalesReserved BOOLEAN; + + + SELECT DISTINCT COUNT(*)>0 INTO vHasSalesReserved + FROM vn.sectorCollection sc + JOIN vn.sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk + JOIN vn.saleGroup sg ON sg.id = scsg.saleGroupFk + JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id + JOIN vn.sale s ON s.id = sgd.saleFk + JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + JOIN vn.saleTracking st ON st.saleFk = s.id + WHERE sc.id = vSelf; + + RETURN vHasSalesReserved; + +END$$ +DELIMITER ; diff --git a/db/versions/10852-pinkOak/00-firstScript.sql b/db/versions/10852-pinkOak/00-firstScript.sql index 7af48148c..369e32e92 100644 --- a/db/versions/10852-pinkOak/00-firstScript.sql +++ b/db/versions/10852-pinkOak/00-firstScript.sql @@ -3,6 +3,8 @@ ALTER TABLE vn.itemShelvingSale DROP COLUMN IF EXISTS isPicked; ALTER TABLE vn.itemShelvingSale ADD isPicked TINYINT(1) DEFAULT FALSE NOT NULL; +UPDATE vn.itemShelvingSale SET isPicked = TRUE; + ALTER TABLE vn.productionConfig DROP COLUMN IF EXISTS orderMode; ALTER TABLE vn.productionConfig From 679f9a1b9b6427ac55982d489ca20c80f14968ff Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 9 May 2024 07:07:10 +0200 Subject: [PATCH 19/81] refs #6861 feat:sectoCollection reserve --- .../vn/procedures/sectorCollection_hasSalesReserved.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql index e0ef46a86..0de49e90c 100644 --- a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql +++ b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql @@ -1,4 +1,5 @@ -CREATE DEFINER=`root`@`localhost` FUNCTION vn.sectorCollection_hasSalesReserved(vSelf INT) RETURNS tinyint(1) +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION vn.sectorCollection_hasSalesReserved(vSelf INT) RETURNS tinyint(1) DETERMINISTIC BEGIN From 22a6c3695c25958fc8c91ecbd19af3d4bfdedac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 22 May 2024 18:05:16 +0200 Subject: [PATCH 20/81] feat:concurrency issue refs #6861 --- .../vn/procedures/itemShelvingSale_addBySale.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 3ad581b15..7e836859a 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -37,12 +37,12 @@ proc: BEGIN IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; -/* DECLARE EXIT HANDLER FOR SQLEXCEPTION + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; -*/ + SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)) INTO vLastPickingOrder, vOutStanding FROM sale s @@ -67,6 +67,8 @@ proc: BEGIN LEAVE l; END IF; + START TRANSACTION; + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk @@ -76,7 +78,6 @@ proc: BEGIN SET vOutStanding = vOutStanding - vReservedQuantity; IF vReservedQuantity > 0 THEN - -- START TRANSACTION; INSERT INTO itemShelvingSale( itemShelvingFk, @@ -92,8 +93,9 @@ proc: BEGIN SET available = available - vReservedQuantity WHERE id = vItemShelvingFk; - -- COMMIT; END IF; + + COMMIT; END LOOP; CLOSE vItemShelvingAvailable; END$$ From ea4f70f460b4186c4e7d97171a023f116fc5511d Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 23 May 2024 16:35:36 +0200 Subject: [PATCH 21/81] refs #6861 feat: previas a reservas --- .../vn/procedures/collection_getTickets.sql | 52 +++++----- ...temShelvingSale_addBySectorCollection.sql} | 34 ++++--- .../procedures/itemShelvingSale_reserve.sql | 94 ------------------- .../itemShelvingSale_reserveByCollection.sql | 29 ------ .../itemShelvingSale_reserveBySale.sql | 21 ----- 5 files changed, 45 insertions(+), 185 deletions(-) rename db/routines/vn/procedures/{itemShelvingSale_reserveBySectorCollection.sql => itemShelvingSale_addBySectorCollection.sql} (64%) delete mode 100644 db/routines/vn/procedures/itemShelvingSale_reserve.sql delete mode 100644 db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql delete mode 100644 db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 3f1239e9b..09624acd2 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -19,9 +19,9 @@ BEGIN WITH observation AS ( SELECT tob.ticketFk, tob.description - FROM vn.ticketObservation tob - JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk - LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk + FROM ticketObservation tob + JOIN ticketCollection tc ON tc.ticketFk = tob.ticketFk + LEFT JOIN observationType ot ON ot.id = tob.observationTypeFk WHERE ot.`code` = 'itemPicker' AND tc.collectionFk = vParamFk ) @@ -32,17 +32,17 @@ BEGIN w.id salesPersonFk, IFNULL(ob.description,'') observation, cc.rgb - FROM vn.ticket t - LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk - LEFT JOIN vn.collectionColors cc + FROM ticket t + LEFT JOIN ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN collection c2 ON c2.id = tc.collectionFk + LEFT JOIN collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN vn.client c ON c.id = t.clientFk - LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE t.id = vParamFk AND t.shipped >= vDated @@ -54,17 +54,17 @@ BEGIN w.id salesPersonFk, ob.description, IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb` - FROM vn.ticket t - JOIN vn.ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk - LEFT JOIN vn.collectionColors cc + FROM ticket t + JOIN ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN collection c2 ON c2.id = tc.collectionFk + LEFT JOIN collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN vn.client c ON c.id = t.clientFk - LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE tc.collectionFk = vParamFk UNION ALL @@ -75,14 +75,14 @@ BEGIN c.salesPersonFk, ob.description, NULL `rgb` - FROM vn.sectorCollection sc - JOIN vn.sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id - JOIN vn.saleGroup sg ON sg.id = ss.saleGroupFk - JOIN vn.ticket t ON t.id = sg.ticketFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id + JOIN saleGroup sg ON sg.id = ss.saleGroupFk + JOIN ticket t ON t.id = sg.ticketFk + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN agencyMode am ON am.id = z.agencyModeFk LEFT JOIN observation ob ON ob.ticketFk = t.id - LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN client c ON c.id = t.clientFk WHERE sc.id = vParamFk AND t.shipped >= vDated; END$$ diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql similarity index 64% rename from db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql rename to db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql index b8387d20c..442abcf5d 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reserveBySectorCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySectorCollection.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE - `vn`.`itemShelvingSale_reserveBySectorCollection`(vSectorCollectionFk INT(11)) + `vn`.`itemShelvingSale_addBySectorCollection`(vSectorCollectionFk INT(11)) BEGIN /** * Reserva cantidades con ubicaciones para el contenido de una preparación previa @@ -8,12 +8,10 @@ BEGIN * * @param vSectorCollectionFk Identificador de sectorCollection */ - DECLARE vHasSales BOOL; - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) - ENGINE = MEMORY - SELECT s.id saleFk, str.workerFk userFK + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vSaleFk INT; + DECLARE vSales CURSOR FOR + SELECT s.id FROM sectorCollectionSaleGroup sc JOIN saleGroupDetail sg ON sg.saleGroupFk = sc.saleGroupFk JOIN sale s ON sg.saleFk = s.id @@ -25,13 +23,19 @@ BEGIN AND str.workerFk = account.myUser_getId() AND iss.id IS NULL; - SELECT COUNT(*)INTO vHasSales - FROM tmp.sale; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - IF vHasSales THEN - CALL itemShelvingSale_reserve(); - ELSE - CALL util.throw ('There are not sales to reserve'); - END IF; + OPEN vSales; + l: LOOP + SET vDone = FALSE; + FETCH vSales INTO vSaleFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL itemShelvingSale_addBySale(vSaleFk); + END LOOP; + CLOSE vSales; END$$ -DELIMITER ; +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_reserve.sql b/db/routines/vn/procedures/itemShelvingSale_reserve.sql deleted file mode 100644 index 803059423..000000000 --- a/db/routines/vn/procedures/itemShelvingSale_reserve.sql +++ /dev/null @@ -1,94 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserve`() -BEGIN -/** - * Reserva cantidades con ubicaciones para un conjunto de sales del mismo - * almacen. - * - * @table tmp.sale(saleFk, userFk) - */ - DECLARE vCalcFk INT; - DECLARE vWarehouseFk INT; - DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); - DECLARE vLastPickingOrder INT; - - SELECT t.warehouseFk, MAX(p.pickingOrder) - INTO vWarehouseFk, vLastPickingOrder - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN tmp.sale ts ON ts.saleFk = s.id - LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk - LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - LEFT JOIN shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = sh.parkingFk - WHERE t.warehouseFk IS NOT NULL; - - IF vWarehouseFk IS NULL THEN - CALL util.throw('Warehouse not set'); - END IF; - - CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - - SET @outstanding = 0; - SET @oldsaleFk = 0; - - CREATE OR REPLACE TEMPORARY TABLE tSalePlacementQuantity - (INDEX(saleFk)) - ENGINE = MEMORY - SELECT saleFk, userFk, quantityToReserve, itemShelvingFk - FROM( SELECT saleFk, - sub.userFk, - itemShelvingFk , - IF(saleFk <> @oldsaleFk, @outstanding := quantity, @outstanding), - @qtr := LEAST(@outstanding, available) quantityToReserve, - @outStanding := @outStanding - @qtr, - @oldsaleFk := saleFk - FROM( - SELECT ts.saleFk, - ts.userFk, - s.quantity, - ish.id itemShelvingFk, - ish.visible - IFNULL(ishr.reservedQuantity, 0) available - FROM tmp.sale ts - JOIN sale s ON s.id = ts.saleFk - JOIN itemShelving ish ON ish.itemFk = s.itemFk - LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id - LEFT JOIN ( - SELECT itemShelvingFk, SUM(quantity) reservedQuantity - FROM itemShelvingSale - WHERE NOT isPicked - GROUP BY itemShelvingFk) ishr ON ishr.itemShelvingFk = ish.id - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector sc ON sc.id = p.sectorFk - JOIN warehouse w ON w.id = sc.warehouseFk - JOIN productionConfig pc - WHERE w.id = vWarehouseFk - AND NOT sc.isHideForPickers - AND iss.id IS NULL - ORDER BY - s.id, - p.pickingOrder >= vLastPickingOrder, - sh.priority DESC, - ish.visible >= s.quantity DESC, - s.quantity MOD ish.grouping = 0 DESC, - ish.grouping DESC, - IF(pc.orderMode = 'Location', p.pickingOrder, ish.created) - )sub - )sub2 - WHERE quantityToReserve > 0; - - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk) - SELECT itemShelvingFk, - saleFk, - quantityToReserve, - IFNULL(userFk, getUser()) - FROM tSalePlacementQuantity spl; - - DROP TEMPORARY TABLE tmp.sale; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql deleted file mode 100644 index 9a97130dd..000000000 --- a/db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql +++ /dev/null @@ -1,29 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserveByCollection`( - vCollectionFk INT(11) -) -BEGIN -/** - * Reserva cantidades con ubicaciones para el contenido de una colección - * - * @param vCollectionFk Identificador de collection - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) - ENGINE = MEMORY - SELECT s.id saleFk, NULL userFk - FROM ticketCollection tc - JOIN sale s ON s.ticketFk = tc.ticketFk - LEFT JOIN ( - SELECT DISTINCT saleFk - FROM saleTracking st - JOIN state s ON s.id = st.stateFk - WHERE st.isChecked - AND s.semaphore = 1)st ON st.saleFk = s.id - WHERE tc.collectionFk = vCollectionFk - AND st.saleFk IS NULL - AND NOT s.isPicked; - - CALL itemShelvingSale_reserve(); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql b/db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql deleted file mode 100644 index fb245062e..000000000 --- a/db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserveBySale`( - vSelf INT , - vQuantity INT, - vUserFk INT -) -BEGIN -/** - * Reserva cantida y ubicación para una saleFk - * - * @param vSelf Identificador de la venta - * @param vQuantity Cantidad a reservar - * @param vUserFk Id de usuario que realiza la reserva - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - ENGINE = MEMORY - SELECT vSelf saleFk, vUserFk userFk; - - CALL itemShelvingSale_reserve(); -END$$ -DELIMITER ; From 723327918b4c479c095e0702b95fb072c3887636 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 24 May 2024 15:55:23 +0200 Subject: [PATCH 22/81] refs #7406 worker formation --- db/dump/fixtures.before.sql | 15 ++++- .../worker/back/models/trainingCenter.json | 21 ++++++ .../worker/back/models/trainingCourse.json | 67 +++++++++++++++++++ .../back/models/trainingCourseType.json | 39 +++++++++++ 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 modules/worker/back/models/trainingCenter.json create mode 100644 modules/worker/back/models/trainingCourse.json create mode 100644 modules/worker/back/models/trainingCourseType.json diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index b8094471a..7765edc9f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3788,14 +3788,23 @@ INSERT INTO vn.workerTeam(id, team, workerFk) VALUES (8, 1, 19); -INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) +INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL); -UPDATE vn.locker SET workerFk = 1110 WHERE id = 147; +UPDATE vn.locker SET workerFk = 1110 WHERE id = 147; INSERT INTO `vn`.`ledgerCompany` SET fiscalYear = YEAR(util.VN_CURDATE()), bookEntry = 2; -INSERT INTO `vn`.`ledgerConfig` SET +INSERT INTO `vn`.`ledgerConfig` SET maxTolerance = 0.01; + + +INSERT INTO vn.trainingCourse (workerFk,trainingCourseTypeFk,centerFk,started,ended,hasDiscount,hasDiploma) + VALUES (9,2,1,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',0,1); +INSERT INTO vn.trainingCourse (workerFk,trainingCourseTypeFk,centerFk,started,ended,hasDiscount,hasDiploma) + VALUES (9,1,2,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',1,0); +INSERT INTO vn.trainingCourse (workerFk,trainingCourseTypeFk,centerFk,started,ended,hasDiscount,hasDiploma) + VALUES (9,2,2,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',1,1); + diff --git a/modules/worker/back/models/trainingCenter.json b/modules/worker/back/models/trainingCenter.json new file mode 100644 index 000000000..8c5e47873 --- /dev/null +++ b/modules/worker/back/models/trainingCenter.json @@ -0,0 +1,21 @@ +{ + "name": "TrainingCenter", + "base": "VnModel", + "options": { + "mysql": { + "table": "trainingCenter" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string", + "required": true + } + + } +} diff --git a/modules/worker/back/models/trainingCourse.json b/modules/worker/back/models/trainingCourse.json new file mode 100644 index 000000000..7a44ad419 --- /dev/null +++ b/modules/worker/back/models/trainingCourse.json @@ -0,0 +1,67 @@ +{ + "name": "TrainingCourse", + "description": "List of workers who have completed training", + "base": "VnModel", + "options": { + "mysql": { + "table": "trainingCourse" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "workerFk": { + "type": "number", + "required": true + }, + "trainingCourseTypeFk": { + "type": "number", + "required": true + }, + "centerFk": { + "type" : "number" + }, + "started": { + "type" : "date" + }, + "ended": { + "type" : "date" + }, + "invoice": { + "type" : "string" + }, + "amount": { + "type" : "number" + }, + "remark": { + "type" : "boolean" + }, + "hasDiscount": { + "type" : "boolean" + }, + "hasDiploma": { + "type" : "boolean" + } + + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "trainingCourseType": { + "type": "belongsTo", + "model": "trainingCourseType", + "foreignKey": "trainingCourseTypeFk" + }, + "centerFk": { + "type": "belongsTo", + "model": "Center", + "foreignKey": "centerFk" + } + } +} diff --git a/modules/worker/back/models/trainingCourseType.json b/modules/worker/back/models/trainingCourseType.json new file mode 100644 index 000000000..1dc708f2f --- /dev/null +++ b/modules/worker/back/models/trainingCourseType.json @@ -0,0 +1,39 @@ +{ + "name": "trainingCourseType", + "description": "List of trainings", + "base": "VnModel", + "options": { + "mysql": { + "table": "trainingCourseType" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string", + "required": true + } + + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "trainingCourseType": { + "type": "belongsTo", + "model": "trainingCourseType", + "foreignKey": "trainingCourseTypeFk" + }, + "centerFk": { + "type": "belongsTo", + "model": "Center", + "foreignKey": "centerFk" + } + } +} From d770cd8d48a8785a20b70bab93bca0a98d2d841c Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 27 May 2024 07:33:33 +0200 Subject: [PATCH 23/81] refs #6861 feat: getLock --- .../vn/procedures/collection_getAssigned.sql | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/collection_getAssigned.sql b/db/routines/vn/procedures/collection_getAssigned.sql index dead563ac..63805e701 100644 --- a/db/routines/vn/procedures/collection_getAssigned.sql +++ b/db/routines/vn/procedures/collection_getAssigned.sql @@ -10,13 +10,27 @@ proc:BEGIN * @param vCollectionFk Id de colección */ DECLARE vHasTooMuchCollections BOOL; - DECLARE vLockTime INT DEFAULT 15; + DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE vWarehouseFk INT; + DECLARE vLockName VARCHAR(215); + DECLARE vLockTime INT DEFAULT 30; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + IF vLockName IS NOT NULL THEN + DO RELEASE_LOCK(vLockName); + END IF; + + RESIGNAL; + END; -- Si hay colecciones sin terminar, sale del proceso CALL collection_get(vUserFk); - SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 - INTO vHasTooMuchCollections + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, + collection_assign_lockname + INTO vHasTooMuchCollections, + vLockName FROM tCollection JOIN productionConfig pc ; @@ -27,8 +41,19 @@ proc:BEGIN LEAVE proc; END IF; - IF NOT GET_LOCK('collection_getAssigned', vLockTime) THEN - LEAVE proc; + SELECT warehouseFk, itemPackingTypeFk + INTO vWarehouseFk, vItemPackingTypeFk + FROM operator + WHERE workerFk = vUserFk; + + SET vLockName = CONCAT_WS('/', + vLockName, + vWarehouseFk, + vItemPackingTypeFk + ); + + IF NOT GET_LOCK(vLockName, vLockTime) THEN + CALL util.throw(CONCAT('Cannot get lock: ', vLockName)); END IF; -- Se eliminan las colecciones sin asignar que estan obsoletas @@ -72,6 +97,6 @@ proc:BEGIN CALL itemShelvingSale_addByCollection(vCollectionFk); - DO RELEASE_LOCK('collection_getAssigned'); + DO RELEASE_LOCK(vLockName); END$$ DELIMITER ; \ No newline at end of file From 2cd7133a8cd25098228dfeda73a7b6e1e8281e08 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 27 May 2024 08:15:57 +0200 Subject: [PATCH 24/81] refs #6861 feat: skipTest --- back/methods/collection/spec/assignCollection.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/collection/spec/assignCollection.spec.js b/back/methods/collection/spec/assignCollection.spec.js index 340bd6a93..e8f3882a3 100644 --- a/back/methods/collection/spec/assignCollection.spec.js +++ b/back/methods/collection/spec/assignCollection.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -fdescribe('ticket assignCollection()', () => { +describe('ticket assignCollection()', () => { let ctx; let options; let tx; From 74b71079f26f0ceda927500e5ae5fa84e3cd86ba Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 27 May 2024 11:33:04 +0200 Subject: [PATCH 25/81] refs #6861 feat: obsrevation --- back/methods/collection/getSales.js | 2 +- .../collection/spec/getTickets.spec.js | 4 +- .../vn/procedures/collection_getTickets.sql | 54 +++++++++---------- .../triggers/itemShelvingSale_afterInsert.sql | 12 +++++ db/versions/10852-pinkOak/00-firstScript.sql | 4 +- 5 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 db/routines/vn/triggers/itemShelvingSale_afterInsert.sql diff --git a/back/methods/collection/getSales.js b/back/methods/collection/getSales.js index 1ea5dcc3c..8f5bfaeef 100644 --- a/back/methods/collection/getSales.js +++ b/back/methods/collection/getSales.js @@ -60,7 +60,7 @@ module.exports = Self => { if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions); for (let ticket of tickets) { - let observations = ticket.observation.split(' '); + let observations = ticket.observaciones.split(' '); for (let observation of observations) { const salesPerson = ticket.salesPersonFk; diff --git a/back/methods/collection/spec/getTickets.spec.js b/back/methods/collection/spec/getTickets.spec.js index e6b9e6a17..969800839 100644 --- a/back/methods/collection/spec/getTickets.spec.js +++ b/back/methods/collection/spec/getTickets.spec.js @@ -26,8 +26,8 @@ describe('collection getTickets()', () => { expect(collectionTickets.tickets[1].ticketFk).toEqual(2); expect(collectionTickets.tickets[2].ticketFk).toEqual(23); expect(collectionTickets.tickets[0].sales[0].ticketFk).toEqual(1); - expect(collectionTickets.tickets[0].sales[1].ticketFk).toEqual(1); - expect(collectionTickets.tickets[0].sales[2].ticketFk).toEqual(1); + expect(collectionTickets.tickets[1].sales.length).toEqual(0); + expect(collectionTickets.tickets[2].sales.length).toEqual(0); expect(collectionTickets.tickets[0].sales[0].Barcodes.length).toBeTruthy(); await tx.rollback(); diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 09624acd2..8be8c8654 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -19,9 +19,9 @@ BEGIN WITH observation AS ( SELECT tob.ticketFk, tob.description - FROM ticketObservation tob - JOIN ticketCollection tc ON tc.ticketFk = tob.ticketFk - LEFT JOIN observationType ot ON ot.id = tob.observationTypeFk + FROM vn.ticketObservation tob + JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk + LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk WHERE ot.`code` = 'itemPicker' AND tc.collectionFk = vParamFk ) @@ -30,19 +30,19 @@ BEGIN am.name agencyName, t.warehouseFk, w.id salesPersonFk, - IFNULL(ob.description,'') observation, + IFNULL(ob.description,'') observaciones, cc.rgb - FROM ticket t - LEFT JOIN ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN collection c2 ON c2.id = tc.collectionFk - LEFT JOIN collectionColors cc + FROM vn.ticket t + LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk + LEFT JOIN vn.collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE t.id = vParamFk AND t.shipped >= vDated @@ -54,17 +54,17 @@ BEGIN w.id salesPersonFk, ob.description, IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb` - FROM ticket t - JOIN ticketCollection tc ON t.id = tc.ticketFk - LEFT JOIN collection c2 ON c2.id = tc.collectionFk - LEFT JOIN collectionColors cc + FROM vn.ticket t + JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk + LEFT JOIN vn.collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE tc.collectionFk = vParamFk UNION ALL @@ -75,14 +75,14 @@ BEGIN c.salesPersonFk, ob.description, NULL `rgb` - FROM sectorCollection sc - JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id - JOIN saleGroup sg ON sg.id = ss.saleGroupFk - JOIN ticket t ON t.id = sg.ticketFk - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN agencyMode am ON am.id = z.agencyModeFk + FROM vn.sectorCollection sc + JOIN vn.sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id + JOIN vn.saleGroup sg ON sg.id = ss.saleGroupFk + JOIN vn.ticket t ON t.id = sg.ticketFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN observation ob ON ob.ticketFk = t.id - LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN vn.client c ON c.id = t.clientFk WHERE sc.id = vParamFk AND t.shipped >= vDated; END$$ diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql new file mode 100644 index 000000000..71ede88f7 --- /dev/null +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` + AFTER INSERT ON `itemShelving` + FOR EACH ROW +BEGIN + + UPDATE sale s + JOIN operator o ON o.workerFk = account.myUser_getId() + SET isPicked = IF(o.isOnReservationMode, isPicked, TRUE) + WHERE id = NEW.saleFk; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/10852-pinkOak/00-firstScript.sql b/db/versions/10852-pinkOak/00-firstScript.sql index 369e32e92..7739976e6 100644 --- a/db/versions/10852-pinkOak/00-firstScript.sql +++ b/db/versions/10852-pinkOak/00-firstScript.sql @@ -27,4 +27,6 @@ CREATE TABLE vn.itemShelvingSaleReserv ( INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) VALUES - ('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file + ('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'); + +ALTER TABLE vn.operator ADD IF NOT EXISTS isOnReservationMode TINYINT(1) NOT NULL DEFAULT FALSE; \ No newline at end of file From 208409acb2118e69e0485d7b2d6914bac0b45ddf Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 May 2024 11:50:15 +0200 Subject: [PATCH 26/81] refs #7406 add relation --- modules/worker/back/models/worker.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 4e7617aab..3eab43650 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -115,6 +115,11 @@ "type": "hasMany", "model": "Locker", "foreignKey": "workerFk" + }, + "trainingCourse": { + "type": "hasMany", + "model": "TrainingCourse", + "foreignKey": "workerFk" } }, "acls":[ From e133dec514fef4a8e34757f0ba9419147d055af7 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 27 May 2024 11:55:42 +0200 Subject: [PATCH 27/81] refs #6861 feat: trigger --- db/routines/vn/triggers/itemShelvingSale_afterInsert.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index 71ede88f7..f5bd88b1b 100644 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -1,6 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` - AFTER INSERT ON `itemShelving` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterInsert` + AFTER INSERT ON `itemShelvingSale` FOR EACH ROW BEGIN From 32aafc35453d4acdc44241814c3367c97f7b936b Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 27 May 2024 12:21:22 +0200 Subject: [PATCH 28/81] feat: refs #6861 trigger --- db/routines/vn/triggers/itemShelving_afterInsert.sql | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/triggers/itemShelving_afterInsert.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql index 86f149473..819e3e790 100644 --- a/db/routines/vn/triggers/itemShelving_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelving_afterInsert.sql @@ -3,8 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterIns AFTER INSERT ON `itemShelving` FOR EACH ROW BEGIN - - INSERT INTO vn.itemShelvingLog( + INSERT INTO vn.itemShelvingLog( itemShelvingFk, workerFk, accion, @@ -13,8 +12,10 @@ BEGIN visible, `grouping`, packing, - available) - VALUES( NEW.id, + available + ) + VALUES ( + NEW.id, NEW.userFk, 'CREA REGISTRO', NEW.itemFk, @@ -22,6 +23,7 @@ BEGIN NEW.visible, NEW.`grouping`, NEW.packing, - NEW.available); + NEW.available + ); END$$ DELIMITER ; \ No newline at end of file From 578b8a2c71348188a4da17cc568ecc2d9fa511e9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 May 2024 14:28:13 +0200 Subject: [PATCH 29/81] refs #7406 changes sql, modelconfig model --- db/versions/11073-crimsonBirch/00-firstScript.sql | 9 +++++++++ modules/worker/back/model-config.json | 9 +++++++++ modules/worker/back/models/trainingCourseType.json | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 db/versions/11073-crimsonBirch/00-firstScript.sql diff --git a/db/versions/11073-crimsonBirch/00-firstScript.sql b/db/versions/11073-crimsonBirch/00-firstScript.sql new file mode 100644 index 000000000..2ad04468f --- /dev/null +++ b/db/versions/11073-crimsonBirch/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values. +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('TrainingCourse','*','*','ALLOW','ROLE','employee'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('TrainingCourseType','*','*','ALLOW','ROLE','employee'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('TrainingCenter','*','*','ALLOW','ROLE','employee'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Worker','__get_trainingCourse','*','ALLOW','ROLE','employee'); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index b7c355511..9bf2f014f 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -124,6 +124,15 @@ }, "Locker": { "dataSource": "vn" + }, + "TrainingCourse": { + "dataSource": "vn" + }, + "TrainingCourseType": { + "dataSource": "vn" + }, + "TrainingCenter": { + "dataSource": "vn" } } diff --git a/modules/worker/back/models/trainingCourseType.json b/modules/worker/back/models/trainingCourseType.json index 1dc708f2f..1a2a45bc7 100644 --- a/modules/worker/back/models/trainingCourseType.json +++ b/modules/worker/back/models/trainingCourseType.json @@ -1,5 +1,5 @@ { - "name": "trainingCourseType", + "name": "TrainingCourseType", "description": "List of trainings", "base": "VnModel", "options": { @@ -27,7 +27,7 @@ }, "trainingCourseType": { "type": "belongsTo", - "model": "trainingCourseType", + "model": "TrainingCourseType", "foreignKey": "trainingCourseTypeFk" }, "centerFk": { From eb2dd5ba5bbd3a21777137e1da4fc1fcaf2a2a98 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 May 2024 16:17:44 +0200 Subject: [PATCH 30/81] refs #7406 acls --- db/versions/11073-crimsonBirch/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11073-crimsonBirch/00-firstScript.sql b/db/versions/11073-crimsonBirch/00-firstScript.sql index 2ad04468f..7d76a75cd 100644 --- a/db/versions/11073-crimsonBirch/00-firstScript.sql +++ b/db/versions/11073-crimsonBirch/00-firstScript.sql @@ -6,4 +6,4 @@ INSERT INTO salix.ACL (model,property,accessType,permission,principalType,princi INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) VALUES ('TrainingCenter','*','*','ALLOW','ROLE','employee'); INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Worker','__get_trainingCourse','*','ALLOW','ROLE','employee'); + VALUES ('Worker','__get__trainingCourse','*','ALLOW','ROLE','employee'); From b95009899ca6c2a68d106c426282d57dedd70b5b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 28 May 2024 12:22:11 +0200 Subject: [PATCH 31/81] refs #7406 fix back --- modules/worker/back/models/trainingCourse.json | 7 +++---- .../worker/back/models/trainingCourseType.json | 18 ------------------ 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/modules/worker/back/models/trainingCourse.json b/modules/worker/back/models/trainingCourse.json index 7a44ad419..af466e13e 100644 --- a/modules/worker/back/models/trainingCourse.json +++ b/modules/worker/back/models/trainingCourse.json @@ -45,7 +45,6 @@ "hasDiploma": { "type" : "boolean" } - }, "relations": { "worker": { @@ -55,12 +54,12 @@ }, "trainingCourseType": { "type": "belongsTo", - "model": "trainingCourseType", + "model": "TrainingCourseType", "foreignKey": "trainingCourseTypeFk" }, - "centerFk": { + "trainingCenter": { "type": "belongsTo", - "model": "Center", + "model": "TrainingCenter", "foreignKey": "centerFk" } } diff --git a/modules/worker/back/models/trainingCourseType.json b/modules/worker/back/models/trainingCourseType.json index 1a2a45bc7..9bf8fc671 100644 --- a/modules/worker/back/models/trainingCourseType.json +++ b/modules/worker/back/models/trainingCourseType.json @@ -17,23 +17,5 @@ "type": "string", "required": true } - - }, - "relations": { - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "trainingCourseType": { - "type": "belongsTo", - "model": "TrainingCourseType", - "foreignKey": "trainingCourseTypeFk" - }, - "centerFk": { - "type": "belongsTo", - "model": "Center", - "foreignKey": "centerFk" - } } } From 4703ebbdf3ce7922f16a52d852d90ee3abd94cbe Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 11:38:09 +0200 Subject: [PATCH 32/81] refactor: refs #7519 Minor change --- db/dump/fixtures.before.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6b8166caa..8bcedeb8d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -831,9 +831,9 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) VALUES (1, 'Diff', 'diff'), - (2, 'Recobro', 'recovery'), - (3, 'Maná', 'mana'), - (4, 'Reclamación', 'claim'), + (2, 'Recovery', 'recovery'), + (3, 'Mana', 'mana'), + (4, 'Claim', 'claim'), (5, 'Heritage', 'heritage'), (6, 'Miscellaneous', 'miscellaneous'), (7, 'Freight Pickup', 'freightPickUp'); From 8cef8eace7a92a8fb96fd124dd720fd07a455304 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 11:41:09 +0200 Subject: [PATCH 33/81] refactor: refs #7519 Minor change --- db/routines/vn/procedures/claimRatio_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 36b9023da..2e999f738 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -79,7 +79,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - SET c.isChargedToMana = TRUE + SET ce.isGreuge = TRUE WHERE cd.description NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge AND cs.code = 'resolved'; From b8e95c02840358fb279008df97e0b4fed160bc0f Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 11:46:52 +0200 Subject: [PATCH 34/81] refactor: refs #7519 Minor change --- db/routines/vn/procedures/claimRatio_add.sql | 6 ++---- db/versions/11028-silverCarnation/00-firstScript.sql | 10 ---------- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 db/versions/11028-silverCarnation/00-firstScript.sql diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 2e999f738..7def0837f 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -172,16 +172,14 @@ BEGIN GROUP BY clientFk ) sub ON sub.clientFk = cr.clientFk SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) / - (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)) - WHERE cr.dated = util.VN_CURDATE(); + (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)); -- Protección neonatos UPDATE claimRatio cr JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk SET cr.priceIncreasing = 0, cr.claimingRate = 0 - WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH - AND cr.dated = util.VN_CURDATE(); + WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH; DROP TEMPORARY TABLE tTicketList; END$$ diff --git a/db/versions/11028-silverCarnation/00-firstScript.sql b/db/versions/11028-silverCarnation/00-firstScript.sql deleted file mode 100644 index 9d291f451..000000000 --- a/db/versions/11028-silverCarnation/00-firstScript.sql +++ /dev/null @@ -1,10 +0,0 @@ -UPDATE IGNORE bs.nightTask - SET `procedure` = 'claimRatio_add', - `schema` = 'vn' - WHERE `procedure` = 'claim_ratio_routine'; - -ALTER TABLE vn.claimRatio ADD dated DATE DEFAULT current_timestamp() NOT NULL; -ALTER TABLE vn.claimRatio CHANGE dated dated DATE DEFAULT current_timestamp() NOT NULL FIRST; -ALTER TABLE vn.claimRatio DROP FOREIGN KEY claimRatio_ibfk_1; -ALTER TABLE vn.claimRatio DROP PRIMARY KEY; -ALTER TABLE vn.claimRatio ADD CONSTRAINT claimRatio_pk PRIMARY KEY (dated,clientFk); From 9b21cd5eb1e52712e34d0a7ae3941ff3c8dad612 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 08:38:58 +0200 Subject: [PATCH 35/81] refactor: refs #7490 Deleted update duaInvoiceInBooking --- .../vn/procedures/duaInvoiceInBooking.sql | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 8b4df6a73..018c72e0e 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -1,5 +1,7 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`( + vDuaFk INT +) BEGIN /** * Genera el asiento de un DUA y marca las entradas como confirmadas @@ -22,18 +24,6 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - UPDATE invoiceIn ii - JOIN entry e ON e.invoiceInFk = ii.id - JOIN duaEntry de ON de.entryFk = e.id - JOIN dua d ON d.id = de.duaFk - SET ii.booked = IFNULL(ii.booked, d.booked), - ii.operated = IFNULL(ii.operated, d.operated), - ii.issued = IFNULL(ii.issued, d.issued), - ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried), - e.isBooked = TRUE, - e.isConfirmed = TRUE - WHERE d.id = vDuaFk; - SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk; IF vBookEntry IS NULL THEN From fb4be69cf12737ef71bc29a2ee24a20f9e3b32ee Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 08:47:02 +0200 Subject: [PATCH 36/81] refactor: refs #7490 Added final update --- .../vn/procedures/duaInvoiceInBooking.sql | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 018c72e0e..9cbf54b4a 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -4,10 +4,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking ) BEGIN /** - * Genera el asiento de un DUA y marca las entradas como confirmadas - * - * @param vDuaFk Id del dua a recalcular - */ +* Genera el asiento de un DUA y marca las entradas como confirmadas +* +* @param vDuaFk Id del dua a recalcular +*/ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; DECLARE vBookEntry INT; @@ -29,7 +29,7 @@ BEGIN IF vBookEntry IS NULL THEN SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear FROM invoiceIn ii - JOIN entry e ON e.invoiceInFk = ii.id + JOIN `entry` e ON e.invoiceInFk = ii.id JOIN duaEntry de ON de.entryFk = e.id JOIN dua d ON d.id = de.duaFk WHERE d.id = vDuaFk @@ -60,5 +60,28 @@ l: LOOP JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id SET ii.isBooked = TRUE WHERE dii.duaFk = vDuaFk; + + UPDATE `entry` e + JOIN ( + WITH entries AS ( + SELECT e.id, de.duaFk + FROM `entry` e + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk + AND (NOT e.isBooked OR NOT e.isConfirmed) + ), + notBookedEntries AS ( + SELECT e.id + FROM entries e + JOIN duaEntry de ON de.entryFk = e.id + JOIN dua d ON d.id = de.duaFk + WHERE d.ASIEN IS NULL) + SELECT e.id + FROM entries e + LEFT JOIN notBookedEntries nbe ON nbe.id = e.id + WHERE nbe.id IS NULL + ) sub ON sub.id = e.id + SET e.isBooked = TRUE, + e.isConfirmed = TRUE; END$$ DELIMITER ; From 317f898c2eb1a63fea6bd0f024c1b136251b92ca Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 08:48:56 +0200 Subject: [PATCH 37/81] refactor: refs #7490 Minor changes --- db/routines/vn/procedures/duaInvoiceInBooking.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 9cbf54b4a..efaf29b41 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -4,10 +4,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking ) BEGIN /** -* Genera el asiento de un DUA y marca las entradas como confirmadas -* -* @param vDuaFk Id del dua a recalcular -*/ + * Genera el asiento de un DUA y marca las entradas como confirmadas + * + * @param vDuaFk Id del dua a recalcular + */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; DECLARE vBookEntry INT; @@ -39,7 +39,7 @@ BEGIN OPEN vInvoicesIn; -l: LOOP + l: LOOP SET vDone = FALSE; FETCH vInvoicesIn INTO vInvoiceFk; From ed7218c1332d4d8c752e6816e07b111ec0100127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 11 Jun 2024 12:44:25 +0200 Subject: [PATCH 38/81] feat: previas con sitema de reservas refs #6861 --- .../collection_addWithReservation.sql | 24 ++++----- .../vn/procedures/collection_getAssigned.sql | 16 +++--- .../itemShelvingSale_addByCollection.sql | 2 +- .../itemShelvingSale_moveReserv.sql | 50 +++++++++++++++++++ ...oup.sql => itemShelvingSale_setPicked.sql} | 2 +- .../itemShelvingSale_setQuantity.sql | 45 +++-------------- ...Transfer.sql => itemShelving_transfer.sql} | 5 +- ....sql => sectorCollection_getMyPartial.sql} | 2 +- .../sectorCollection_hasSalesReserved.sql | 30 +++++------ .../vn/triggers/itemShelving_afterInsert.sql | 29 ----------- 10 files changed, 94 insertions(+), 111 deletions(-) create mode 100644 db/routines/vn/procedures/itemShelvingSale_moveReserv.sql rename db/routines/vn/procedures/{itemShelvingSale_setSaleGroup.sql => itemShelvingSale_setPicked.sql} (91%) rename db/routines/vn/procedures/{itemShelvingTransfer.sql => itemShelving_transfer.sql} (95%) rename db/routines/vn/procedures/{sectorCollection_getPartial.sql => sectorCollection_getMyPartial.sql} (95%) delete mode 100644 db/routines/vn/triggers/itemShelving_afterInsert.sql diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index cc207b572..faa00477e 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -23,7 +23,7 @@ BEGIN DECLARE vConcept VARCHAR(50); DECLARE vItemName VARCHAR(50); DECLARE vHasThrow BOOLEAN DEFAULT FALSE; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; @@ -48,21 +48,14 @@ BEGIN IF vAvailable < vQuantity THEN SET vHasThrow = TRUE; - SELECT vAvailable, vQuantity; ELSE - START TRANSACTION; - SELECT `name`, CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) INTO vItemName, vConcept FROM item WHERE id = vItemFk; - INSERT INTO ticketLog - SET originFk = vTicketFk, - userFk = getUser(), - `action` = 'update', - `description` = CONCAT('Añadido articulo ', vItemName, ' cantidad:', vQuantity); + START TRANSACTION; INSERT INTO sale SET itemFk = vItemFk, @@ -84,12 +77,13 @@ BEGIN IF vHasThrow THEN CALL util.throw("No hay disponibilidad para el artículo seleccionado"); ELSE - IF vSaleGroupFk THEN - INSERT INTO saleGroupDetail - SET saleFk = vSaleFk, - saleGroupFk = vSaleGroupFk; - COMMIT; + IF vSaleGroupFk THEN + INSERT INTO saleGroupDetail + SET saleFk = vSaleFk, + saleGroupFk = vSaleGroupFk; END IF; - END IF ; + COMMIT; + END IF; + END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/collection_getAssigned.sql b/db/routines/vn/procedures/collection_getAssigned.sql index 63805e701..575032e2e 100644 --- a/db/routines/vn/procedures/collection_getAssigned.sql +++ b/db/routines/vn/procedures/collection_getAssigned.sql @@ -1,11 +1,14 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getAssigned`( vUserFk INT, - OUT vCollectionFk INT) -proc:BEGIN -/* Comprueba si existen colecciones libres que se ajustan al perfil del usuario + OUT vCollectionFk INT +) +BEGIN +/** + * Comprueba si existen colecciones libres que se ajustan al perfil del usuario * y le asigna la más antigua. * Añade un registro al semillero de colecciones y hace la reserva para la colección + * * @param vUserFk Id de usuario * @param vCollectionFk Id de colección */ @@ -28,17 +31,16 @@ proc:BEGIN CALL collection_get(vUserFk); SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, - collection_assign_lockname + pc.collection_assign_lockname INTO vHasTooMuchCollections, vLockName - FROM tCollection - JOIN productionConfig pc ; + FROM tCollection tc + JOIN productionConfig pc; DROP TEMPORARY TABLE tCollection; IF vHasTooMuchCollections THEN CALL util.throw('Hay colecciones pendientes'); - LEAVE proc; END IF; SELECT warehouseFk, itemPackingTypeFk diff --git a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql index 9bc549235..7f9cc6616 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addByCollection.sql @@ -26,7 +26,7 @@ BEGIN JOIN vn.saleTracking st ON st.saleFk = sa.saleFk JOIN vn.`state` s ON s.id = st.stateFk WHERE st.isChecked - AND s.semaphore = 1 + AND s.`code` IN ('PREVIOUS_PREPARATION', 'OK PREVIOUS', 'OK STOWAWAY') GROUP BY sa.saleFk ) SELECT s.saleFk FROM sales s diff --git a/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql b/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql new file mode 100644 index 000000000..7001ee4b8 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_moveReserv`( + vItemShelvingFk INT(10), + vItemFk INT(10) +) +BEGIN +/** + * Elimina reservas de un itemShelvingSale e intenta reservar en otra ubicación + * + * @param vItemShelvingFk Id itemShelving + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT id INTO vItemShelvingFk + FROM itemShelving + WHERE id = vItemShelvingFk + AND FALSE + FOR UPDATE; + + UPDATE itemShelving + SET visible = 0, + available = 0 + WHERE id = vItemShelvingFk + AND itemFk = vItemFk; + + INSERT INTO itemShelvingSaleReserv (saleFk) + SELECT DISTINCT iss.saleFk + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + + DELETE iss + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + COMMIT; + + CALL itemShelvingSale_doReserve(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql b/db/routines/vn/procedures/itemShelvingSale_setPicked.sql similarity index 91% rename from db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql rename to db/routines/vn/procedures/itemShelvingSale_setPicked.sql index 911034ed1..c1e58a9d1 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setSaleGroup.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setPicked.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setSaleGroup`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setPicked`( vSaleGroupFk INT(10) ) BEGIN diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 13b8a16ad..6f008ab33 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -46,10 +46,8 @@ BEGIN CALL util.throw('La cantidad no puede distinta a la reserva'); END IF; - START TRANSACTION; - UPDATE itemShelvingSale SET isPicked = TRUE, quantity = vQuantity @@ -62,41 +60,10 @@ BEGIN FOR UPDATE; UPDATE itemShelving - SET visible = IF(vIsItemShelvingSaleEmpty, 0, GREATEST(0, visible - vQuantity)) + SET visible = GREATEST(0, visible - vQuantity) WHERE id = vItemShelvingFk; - COMMIT; - IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - - UPDATE itemShelving - SET visible = 0, - available = 0 - WHERE id = vItemShelvingFk - AND itemFk = vItemFk; - - CALL itemShelvingSale_addBySale(vSaleFk); - - START TRANSACTION; - - INSERT INTO itemShelvingSaleReserv (saleFk) - SELECT DISTINCT iss.saleFk - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND ish.itemFk = vItemFk - AND NOT iss.isPicked; - - DELETE iss - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND ish.itemFk = vItemFk - AND NOT iss.isPicked; - COMMIT; - - CALL itemShelvingSale_doReserve(); - END IF; SELECT SUM(IF(isPicked, 0, quantity)), SUM(quantity) INTO vRemainingQuantity, vTotalQuantity @@ -104,8 +71,6 @@ BEGIN WHERE saleFk = vSaleFk; IF vRemainingQuantity = 0 THEN - START TRANSACTION; - CALL saleTracking_new( vSaleFk, TRUE, @@ -119,8 +84,12 @@ BEGIN SET s.quantity = vTotalQuantity, isPicked = TRUE WHERE s.id = vSaleFk; - - COMMIT; + END IF; + + COMMIT; + + IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN + CALL itemShelvingSale_moveReserv(vItemShelvingFk, vQuantity); END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingTransfer.sql b/db/routines/vn/procedures/itemShelving_transfer.sql similarity index 95% rename from db/routines/vn/procedures/itemShelvingTransfer.sql rename to db/routines/vn/procedures/itemShelving_transfer.sql index 07012a654..47a9a7cf0 100644 --- a/db/routines/vn/procedures/itemShelvingTransfer.sql +++ b/db/routines/vn/procedures/itemShelving_transfer.sql @@ -1,7 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingTransfer`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_transfer`( vItemShelvingFk INT, - vShelvingFk VARCHAR(3)) + vShelvingFk VARCHAR(10) +) BEGIN /** * Transfiere producto de una ubicación a otra, fusionando si coincide el diff --git a/db/routines/vn/procedures/sectorCollection_getPartial.sql b/db/routines/vn/procedures/sectorCollection_getMyPartial.sql similarity index 95% rename from db/routines/vn/procedures/sectorCollection_getPartial.sql rename to db/routines/vn/procedures/sectorCollection_getMyPartial.sql index 2f59f591a..23e21d2f3 100644 --- a/db/routines/vn/procedures/sectorCollection_getPartial.sql +++ b/db/routines/vn/procedures/sectorCollection_getMyPartial.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_getPartial`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_getMyPartial`() BEGIN /** * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas diff --git a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql index 0de49e90c..acb460190 100644 --- a/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql +++ b/db/routines/vn/procedures/sectorCollection_hasSalesReserved.sql @@ -2,28 +2,24 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION vn.sectorCollection_hasSalesReserved(vSelf INT) RETURNS tinyint(1) DETERMINISTIC BEGIN - /** -* Devuelve si sectorCollection tiene reservas -* @param vSelf Id de sectorCollection -* -* returns BOOLEAN -*/ - + * Devuelve si sectorCollection tiene reservas + * @param vSelf Id de sectorCollection + * + * returns BOOLEAN + */ DECLARE vHasSalesReserved BOOLEAN; - - SELECT DISTINCT COUNT(*)>0 INTO vHasSalesReserved - FROM vn.sectorCollection sc - JOIN vn.sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk - JOIN vn.saleGroup sg ON sg.id = scsg.saleGroupFk - JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id - JOIN vn.sale s ON s.id = sgd.saleFk - JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id - JOIN vn.saleTracking st ON st.saleFk = s.id + SELECT DISTINCT COUNT(*) INTO vHasSalesReserved + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup scsg ON sc.id = scsg.sectorCollectionFk + JOIN saleGroup sg ON sg.id = scsg.saleGroupFk + JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id + JOIN sale s ON s.id = sgd.saleFk + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN saleTracking st ON st.saleFk = s.id WHERE sc.id = vSelf; RETURN vHasSalesReserved; - END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_afterInsert.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql deleted file mode 100644 index 819e3e790..000000000 --- a/db/routines/vn/triggers/itemShelving_afterInsert.sql +++ /dev/null @@ -1,29 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` - AFTER INSERT ON `itemShelving` - FOR EACH ROW -BEGIN - INSERT INTO vn.itemShelvingLog( - itemShelvingFk, - workerFk, - accion, - itemFk, - shelvingFk, - visible, - `grouping`, - packing, - available - ) - VALUES ( - NEW.id, - NEW.userFk, - 'CREA REGISTRO', - NEW.itemFk, - NEW.shelvingFk, - NEW.visible, - NEW.`grouping`, - NEW.packing, - NEW.available - ); -END$$ -DELIMITER ; \ No newline at end of file From d75e008a23d14675cec169e478cc03d8ad44732a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 11 Jun 2024 12:49:33 +0200 Subject: [PATCH 39/81] feat: previas con sitema de reservas refs #6861 --- .../procedures/collection_addWithReservation.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index faa00477e..b483eff39 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -76,14 +76,14 @@ BEGIN IF vHasThrow THEN CALL util.throw("No hay disponibilidad para el artículo seleccionado"); - ELSE - IF vSaleGroupFk THEN - INSERT INTO saleGroupDetail - SET saleFk = vSaleFk, - saleGroupFk = vSaleGroupFk; - END IF; - COMMIT; END IF; - + + IF vSaleGroupFk THEN + INSERT INTO saleGroupDetail + SET saleFk = vSaleFk, + saleGroupFk = vSaleGroupFk; + END IF; + + COMMIT; END$$ DELIMITER ; From b9d1c3228b016fe52483faf669963d00b66e3d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 11 Jun 2024 18:43:26 +0200 Subject: [PATCH 40/81] feat: previas con sitema de reservas refs #6861 --- .../vn/procedures/collection_addWithReservation.sql | 2 +- db/routines/vn/procedures/collection_getAssigned.sql | 2 +- db/routines/vn/procedures/collection_getTickets.sql | 8 ++++---- .../vn/procedures/itemShelvingSale_setQuantity.sql | 6 +++--- ...ingSale_moveReserv.sql => itemShelving_moveReserv.sql} | 7 +++---- .../vn/procedures/sectorCollection_getMyPartial.sql | 3 +-- db/routines/vn/triggers/itemShelvingSale_afterInsert.sql | 6 +++--- 7 files changed, 16 insertions(+), 18 deletions(-) rename db/routines/vn/procedures/{itemShelvingSale_moveReserv.sql => itemShelving_moveReserv.sql} (82%) diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index b483eff39..e3f4eb8d2 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -75,7 +75,7 @@ BEGIN END IF; IF vHasThrow THEN - CALL util.throw("No hay disponibilidad para el artículo seleccionado"); + CALL util.throw("There is no available for the selected item"); END IF; IF vSaleGroupFk THEN diff --git a/db/routines/vn/procedures/collection_getAssigned.sql b/db/routines/vn/procedures/collection_getAssigned.sql index 575032e2e..bfaa3096b 100644 --- a/db/routines/vn/procedures/collection_getAssigned.sql +++ b/db/routines/vn/procedures/collection_getAssigned.sql @@ -40,7 +40,7 @@ BEGIN DROP TEMPORARY TABLE tCollection; IF vHasTooMuchCollections THEN - CALL util.throw('Hay colecciones pendientes'); + CALL util.throw('There are pending collections'); END IF; SELECT warehouseFk, itemPackingTypeFk diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql index 8be8c8654..7ecff571a 100644 --- a/db/routines/vn/procedures/collection_getTickets.sql +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -7,7 +7,7 @@ BEGIN * @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observation */ DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE vDated DATE; + DECLARE vYesterday DATE; -- Si los sacadores son los de pruebas, pinta los colores SELECT itemPackingTypeFk @@ -15,7 +15,7 @@ BEGIN FROM collection WHERE id = vParamFk; - SET vDated = util.yesterday(); + SET vYesterday = util.yesterday(); WITH observation AS ( SELECT tob.ticketFk, tob.description @@ -45,7 +45,7 @@ BEGIN LEFT JOIN vn.worker w ON w.id = c.salesPersonFk LEFT JOIN observation ob ON ob.ticketFk = t.id WHERE t.id = vParamFk - AND t.shipped >= vDated + AND t.shipped >= vYesterday UNION ALL SELECT t.id ticketFk, IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, @@ -84,6 +84,6 @@ BEGIN LEFT JOIN observation ob ON ob.ticketFk = t.id LEFT JOIN vn.client c ON c.id = t.clientFk WHERE sc.id = vParamFk - AND t.shipped >= vDated; + AND t.shipped >= vYesterday; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 6f008ab33..aed4053bf 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -29,7 +29,7 @@ BEGIN END; IF (SELECT isPicked FROM itemShelvingSale WHERE id = vItemShelvingSaleFk) THEN - CALL util.throw('Reserva completada'); + CALL util.throw('Reservation completed'); END IF; SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)) @@ -43,7 +43,7 @@ BEGIN OR (vQuantity < vReservedQuantity AND (NOT vIsItemShelvingSaleEmpty OR vIsItemShelvingSaleEmpty IS NULL)) OR (vIsItemShelvingSaleEmpty IS NOT NULL AND vQuantity = vReservedQuantity) THEN - CALL util.throw('La cantidad no puede distinta a la reserva'); + CALL util.throw('The quantity cannot be different from the reserved'); END IF; START TRANSACTION; @@ -89,7 +89,7 @@ BEGIN COMMIT; IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - CALL itemShelvingSale_moveReserv(vItemShelvingFk, vQuantity); + CALL itemShelving_moveReserv(vItemShelvingFk, vQuantity); END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql b/db/routines/vn/procedures/itemShelving_moveReserv.sql similarity index 82% rename from db/routines/vn/procedures/itemShelvingSale_moveReserv.sql rename to db/routines/vn/procedures/itemShelving_moveReserv.sql index 7001ee4b8..cff8f6e92 100644 --- a/db/routines/vn/procedures/itemShelvingSale_moveReserv.sql +++ b/db/routines/vn/procedures/itemShelving_moveReserv.sql @@ -1,11 +1,11 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_moveReserv`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_moveReserv`( vItemShelvingFk INT(10), vItemFk INT(10) ) BEGIN /** - * Elimina reservas de un itemShelvingSale e intenta reservar en otra ubicación + * Elimina reservas de un itemShelving e intenta reservar en otra ubicación * * @param vItemShelvingFk Id itemShelving */ @@ -17,10 +17,9 @@ BEGIN START TRANSACTION; - SELECT id INTO vItemShelvingFk + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk - AND FALSE FOR UPDATE; UPDATE itemShelving diff --git a/db/routines/vn/procedures/sectorCollection_getMyPartial.sql b/db/routines/vn/procedures/sectorCollection_getMyPartial.sql index 23e21d2f3..21f26770a 100644 --- a/db/routines/vn/procedures/sectorCollection_getMyPartial.sql +++ b/db/routines/vn/procedures/sectorCollection_getMyPartial.sql @@ -12,8 +12,7 @@ BEGIN LEFT JOIN vn.sale sl ON sl.id = sgd.saleFk LEFT JOIN itemShelvingSale iss ON iss.saleFk = sl.id WHERE sc.userFk = account.myUser_getId() - AND (ISNULL(scsg.sectorCollectionFk) - OR (NOT iss.isPicked)) + AND (scsg.sectorCollectionFk IS NULL OR NOT iss.isPicked) AND sc.created > util.VN_CURDATE() - INTERVAL 1 DAY; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index f5bd88b1b..0c609d328 100644 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -5,8 +5,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_afte BEGIN UPDATE sale s - JOIN operator o ON o.workerFk = account.myUser_getId() - SET isPicked = IF(o.isOnReservationMode, isPicked, TRUE) - WHERE id = NEW.saleFk; + JOIN operator o ON o.workerFk = account.myUser_getId() + SET s.isPicked = IF(o.isOnReservationMode, isPicked, TRUE) + WHERE id = NEW.saleFk; END$$ DELIMITER ; \ No newline at end of file From d0b926b2c5176685324836649ba1ed4ed3936f38 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 12 Jun 2024 14:26:26 +0200 Subject: [PATCH 41/81] feat: refs #7490 Changes --- .../vn/procedures/duaInvoiceInBooking.sql | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index efaf29b41..1f026e96b 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -24,6 +24,16 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + UPDATE invoiceIn ii + JOIN entry e ON e.invoiceInFk = ii.id + JOIN duaEntry de ON de.entryFk = e.id + JOIN dua d ON d.id = de.duaFk + SET ii.booked = IFNULL(ii.booked, d.booked), + ii.operated = IFNULL(ii.operated, d.operated), + ii.issued = IFNULL(ii.issued, d.issued), + ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried) + WHERE d.id = vDuaFk; + SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk; IF vBookEntry IS NULL THEN @@ -65,21 +75,21 @@ BEGIN JOIN ( WITH entries AS ( SELECT e.id, de.duaFk - FROM `entry` e + FROM `entry` e JOIN duaEntry de ON de.entryFk = e.id WHERE de.duaFk = vDuaFk AND (NOT e.isBooked OR NOT e.isConfirmed) ), notBookedEntries AS ( SELECT e.id - FROM entries e - JOIN duaEntry de ON de.entryFk = e.id - JOIN dua d ON d.id = de.duaFk - WHERE d.ASIEN IS NULL) - SELECT e.id + FROM duaEntry + WHERE duaFk = vDuaFk + AND NOT customsValue + ) + SELECT e.id FROM entries e - LEFT JOIN notBookedEntries nbe ON nbe.id = e.id - WHERE nbe.id IS NULL + LEFT JOIN notBookedEntries nbe ON nbe.entryFk = e.id + WHERE nbe.entryFk IS NULL ) sub ON sub.id = e.id SET e.isBooked = TRUE, e.isConfirmed = TRUE; From 30caf79490e5ecdf3e10fe7204b62352e0efc468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 12 Jun 2024 16:12:06 +0200 Subject: [PATCH 42/81] feat: previas con sitema de reservas refs #6861 --- ...mShelving_moveReserv.sql => itemShelvingSale_reallocate.sql} | 2 +- db/routines/vn/procedures/itemShelvingSale_setQuantity.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename db/routines/vn/procedures/{itemShelving_moveReserv.sql => itemShelvingSale_reallocate.sql} (92%) diff --git a/db/routines/vn/procedures/itemShelving_moveReserv.sql b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql similarity index 92% rename from db/routines/vn/procedures/itemShelving_moveReserv.sql rename to db/routines/vn/procedures/itemShelvingSale_reallocate.sql index cff8f6e92..ab898bdd4 100644 --- a/db/routines/vn/procedures/itemShelving_moveReserv.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_moveReserv`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`( vItemShelvingFk INT(10), vItemFk INT(10) ) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index aed4053bf..700821592 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -89,7 +89,7 @@ BEGIN COMMIT; IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - CALL itemShelving_moveReserv(vItemShelvingFk, vQuantity); + CALL itemShelvingSale_reallocate(vItemShelvingFk, vQuantity); END IF; END$$ DELIMITER ; \ No newline at end of file From cfc5e327154fdc7e5a680395c7ccfce22bde4199 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 13 Jun 2024 13:11:50 +0200 Subject: [PATCH 43/81] feat: refs #6701 Fix error --- db/routines/vn/procedures/claimRatio_add.sql | 43 ++++++++++--------- .../11101-limeCordyline/00-firstScript.sql | 4 ++ 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 db/versions/11101-limeCordyline/00-firstScript.sql diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 7def0837f..8d94805db 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -44,7 +44,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') + WHERE cd.description NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge AND cs.code = 'resolved'; @@ -86,20 +86,20 @@ BEGIN -- Recobros CREATE OR REPLACE TEMPORARY TABLE tTicketList - (PRIMARY KEY (ticketFk)) - SELECT DISTINCT s.ticketFk - FROM saleComponent sc - JOIN sale s ON sc.saleFk = s.id - JOIN ticket t ON t.id = s.ticketFk - JOIN ticketLastState ts ON ts.ticketFk = t.id - JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk - JOIN state st ON st.id = tt.stateFk - JOIN alertLevel al ON al.id = st.alertLevel - WHERE sc.componentFk = vDebtComponentType - AND NOT sc.isGreuge - AND t.shipped >= '2016-10-01' - AND t.shipped < util.VN_CURDATE() - AND al.code = 'DELIVERED'; + (PRIMARY KEY (ticketFk)) + SELECT DISTINCT s.ticketFk + FROM saleComponent sc + JOIN sale s ON sc.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN ticketLastState ts ON ts.ticketFk = t.id + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state st ON st.id = tt.stateFk + JOIN alertLevel al ON al.id = st.alertLevel + WHERE sc.componentFk = vDebtComponentType + AND NOT sc.isGreuge + AND t.shipped >= '2016-10-01' + AND t.shipped < util.VN_CURDATE() + AND al.code = 'DELIVERED'; DELETE g.* FROM greuge g @@ -133,20 +133,21 @@ BEGIN JOIN tTicketList tl ON tl.ticketFk = s.ticketFk SET sc.isGreuge = TRUE WHERE sc.componentFk = vDebtComponentType; - - INSERT INTO claimRatio( + + REPLACE claimRatio( clientFk, yearSale, claimAmount, claimingRate, priceIncreasing ) - SELECT cac.clientFk, + SELECT c.id, 12 * cac.invoiced, totalClaims, ROUND(totalClaims / (12 * cac.invoiced), 4), 0 - FROM bs.clientAnnualConsumption cac + FROM client c + LEFT JOIN bs.clientAnnualConsumption cac ON cac.clientFk = c.id LEFT JOIN ( SELECT c.clientFk, ROUND(SUM(-1 * ((c.responsibility - 1) / 4) * @@ -157,11 +158,11 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') + WHERE cd.description NOT IN ('Bueno', 'Corregido') AND cs.code = 'resolved' AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR GROUP BY c.clientFk - ) sub ON sub.clientFk = cac.clientFk; + ) sub ON sub.clientFk = c.id; -- Calculamos el porcentaje del recobro para añadirlo al precio de venta UPDATE claimRatio cr diff --git a/db/versions/11101-limeCordyline/00-firstScript.sql b/db/versions/11101-limeCordyline/00-firstScript.sql new file mode 100644 index 000000000..e9ffa1b12 --- /dev/null +++ b/db/versions/11101-limeCordyline/00-firstScript.sql @@ -0,0 +1,4 @@ +UPDATE IGNORE bs.nightTask + SET `schema` = 'vn', + `procedure` = 'claimRatio_add' + WHERE `procedure` = 'claim_ratio_routine'; From c2e4e187d689333e43b353269707383937bf93b8 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 13 Jun 2024 14:21:59 +0200 Subject: [PATCH 44/81] feat itemShelvingSale refs #6861 --- db/routines/vn/procedures/itemShelvingSale_setQuantity.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 700821592..6c556f1ff 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -70,7 +70,7 @@ BEGIN FROM itemShelvingSale WHERE saleFk = vSaleFk; - IF vRemainingQuantity = 0 THEN + IF vRemainingQuantity = 0 AND NOT vIsItemShelvingSaleEmpty THEN CALL saleTracking_new( vSaleFk, TRUE, @@ -89,7 +89,9 @@ BEGIN COMMIT; IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - CALL itemShelvingSale_reallocate(vItemShelvingFk, vQuantity); + INSERT INTO itemShelvingSaleReserv (saleFk) + SELECT vSaleFk; + CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk); END IF; END$$ DELIMITER ; \ No newline at end of file From 1d0b89ed526b03bf5f40b85705dcb0550b848b21 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 17 Jun 2024 09:42:16 +0200 Subject: [PATCH 45/81] refs #7519 Requested changes --- db/dump/fixtures.before.sql | 4 ++-- db/routines/vn/procedures/claimRatio_add.sql | 9 ++++++--- db/versions/11101-limeCordyline/00-firstScript.sql | 8 ++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 60ef58861..eb165aeec 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1885,9 +1885,9 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina (1, 31, 4, 21, 2), (2, 32, 3, 21, 3); -INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`) +INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`) VALUES - (1, 50); + (1, 5, 4, '2016-10-01'); INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`) VALUES diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 8d94805db..c375f8736 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -5,7 +5,8 @@ BEGIN * Añade a la tabla greuges todos los cargos necesario y * que luego lo utilizamos para calcular el recobro. */ - DECLARE vMonthToRefund INT DEFAULT 4; + DECLARE vMonthToRefund INT + DEFAULT (SELECT monthsToRefund FROM claimConfig); DECLARE vRecoveryGreugeType INT DEFAULT (SELECT id FROM greugeType WHERE code = 'recovery'); DECLARE vManaGreugeType INT @@ -15,7 +16,8 @@ BEGIN DECLARE vDebtComponentType INT DEFAULT (SELECT id FROM component WHERE code = 'debtCollection'); - IF vRecoveryGreugeType IS NULL + IF vMonthToRefund IS NULL + OR vRecoveryGreugeType IS NULL OR vManaGreugeType IS NULL OR vClaimGreugeType IS NULL OR vDebtComponentType IS NULL THEN @@ -87,6 +89,7 @@ BEGIN -- Recobros CREATE OR REPLACE TEMPORARY TABLE tTicketList (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY SELECT DISTINCT s.ticketFk FROM saleComponent sc JOIN sale s ON sc.saleFk = s.id @@ -97,7 +100,7 @@ BEGIN JOIN alertLevel al ON al.id = st.alertLevel WHERE sc.componentFk = vDebtComponentType AND NOT sc.isGreuge - AND t.shipped >= '2016-10-01' + AND t.shipped >= (SELECT minShipped FROM claimConfig) AND t.shipped < util.VN_CURDATE() AND al.code = 'DELIVERED'; diff --git a/db/versions/11101-limeCordyline/00-firstScript.sql b/db/versions/11101-limeCordyline/00-firstScript.sql index e9ffa1b12..d6f30ce3f 100644 --- a/db/versions/11101-limeCordyline/00-firstScript.sql +++ b/db/versions/11101-limeCordyline/00-firstScript.sql @@ -2,3 +2,11 @@ UPDATE IGNORE bs.nightTask SET `schema` = 'vn', `procedure` = 'claimRatio_add' WHERE `procedure` = 'claim_ratio_routine'; + +ALTER TABLE vn.claimConfig + ADD monthsToRefund int(11) DEFAULT NULL NULL, + ADD minShipped date DEFAULT NULL NULL; + +UPDATE IGNORE vn.claimConfig + SET monthsToRefund = 4, + minShipped = '2016-10-01'; From 49e01218e9d9dfffb71c9715339e482db6bf2759 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 19 Jun 2024 10:45:37 +0200 Subject: [PATCH 46/81] Warehouse name --- .../vn/procedures/supplierPackaging_ReportSource.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql index 7cc72848f..a8e506244 100644 --- a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql +++ b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql @@ -68,7 +68,7 @@ BEGIN DATE(t.shipped), -LEAST(s.quantity,0) `in`, GREATEST(s.quantity,0) `out`, - t.warehouseFk, + w.name, s.price * (100 - s.discount) / 100 FROM sale s JOIN item i ON i.id = s.itemFk @@ -76,6 +76,7 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi + JOIN warehouse w ON w.id = t.warehouseFk WHERE su.id = vSupplierFk AND t.shipped >= vFromDated AND p.isPackageReturnable @@ -110,7 +111,7 @@ BEGIN DATE(t.shipped), -LEAST(tp.quantity,0) `in`, GREATEST(tp.quantity,0) `out`, - t.warehouseFk, + w.name, 0 FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk @@ -118,6 +119,7 @@ BEGIN JOIN ticket t ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi + JOIN warehouse w ON w.id = t.warehouseFk WHERE su.id = vSupplierFk AND t.shipped >= vFromDated AND p.isPackageReturnable From c87f060d5166807a93642ad8a9d3655a21269829 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 20 Jun 2024 09:21:27 +0200 Subject: [PATCH 47/81] feat boxPicking refs #7357 --- back/model-config.json | 5 ++++- back/models/expedition_PrintOut.json | 24 ++++++++++++++++++++++++ db/dump/fixtures.before.sql | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 back/models/expedition_PrintOut.json diff --git a/back/model-config.json b/back/model-config.json index b643ab54f..58fa86797 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -64,6 +64,9 @@ "EmailUser": { "dataSource": "vn" }, + "Expedition_PrintOut": { + "dataSource": "vn" + }, "Image": { "dataSource": "vn" }, @@ -190,4 +193,4 @@ "RouteConfig": { "dataSource": "vn" } -} +} \ No newline at end of file diff --git a/back/models/expedition_PrintOut.json b/back/models/expedition_PrintOut.json new file mode 100644 index 000000000..6f521cda3 --- /dev/null +++ b/back/models/expedition_PrintOut.json @@ -0,0 +1,24 @@ +{ + "name": "Expedition_PrintOut", + "base": "VnModel", + "options": { + "mysql": { + "table": "dipole.expedition_PrintOut" + } + }, + "properties": { + "expeditionFk": { + "type": "number", + "id": true, + "description": "id expeditionFk" + }, + "itemFk": { + "type": "number", + "required": true + }, + "shelvingFk": { + "type": "string", + "required": true + } + } +} \ No newline at end of file diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 058c5cd2a..dc9efacf1 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3882,3 +3882,11 @@ INSERT INTO `vn`.`calendarHolidays` (calendarHolidaysTypeFk, dated, calendarHoli (1, '2001-05-17', 1, 5), (1, '2001-05-18', 1, 5); + +INSERT INTO dipole.printer (id, description) + VALUES(1, ''); + + INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, + truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) + VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); + From 5a40952547c1bea9453dfcf9c45ec4004c5dce56 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 20 Jun 2024 09:34:13 +0200 Subject: [PATCH 48/81] fix: refs #195937 icoterms --- .../templates/reports/invoice-incoterms/sql/incoterms.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index 81c0ec189..363de0b16 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -1,7 +1,7 @@ SELECT pack.packages, a.incotermsFk, ic.name incotermsName, - t.weight, + wei.weight, ca.fiscalName customsAgentName, ca.street customsAgentStreet, ca.nif customsAgentNif, @@ -48,5 +48,10 @@ SELECT pack.packages, FROM ticket WHERE refFk = ? ) pack + JOIN ( + SELECT SUM(weight) weight + FROM ticket + WHERE refFk = ? + ) wei WHERE t.refFk = ? LIMIT 1 From c1c01df3c3f05f5402335143e752d93809b1d595 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 20 Jun 2024 09:37:22 +0200 Subject: [PATCH 49/81] feat itemShelving_filterBuyer refs #7023 --- db/routines/vn/procedures/itemShelving_filterBuyer.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql index 7112aa48e..894a14464 100644 --- a/db/routines/vn/procedures/itemShelving_filterBuyer.sql +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -15,7 +15,7 @@ proc:BEGIN SELECT * FROM (SELECT sub.itemFk, sub.longName, - CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT('Hoy quedan por sacar ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer, sub.upstairs, sub.downstairs, @@ -52,7 +52,7 @@ proc:BEGIN UNION ALL SELECT v.item_id, i.longName, - CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT('Hoy quedan por sacar ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, 0, 0, From 46792ba30e792441689df3f081e7495d957afc96 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 20 Jun 2024 11:04:42 +0200 Subject: [PATCH 50/81] fix: refs #195937 changes requerid --- .../reports/invoice-incoterms/sql/incoterms.sql | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index 363de0b16..2a041fce0 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -1,7 +1,7 @@ -SELECT pack.packages, +SELECT calc.packages, a.incotermsFk, ic.name incotermsName, - wei.weight, + calc.weight, ca.fiscalName customsAgentName, ca.street customsAgentStreet, ca.nif customsAgentNif, @@ -44,14 +44,9 @@ SELECT pack.packages, WHERE t.refFk = ? ) intr JOIN ( - SELECT SUM(packages) packages + SELECT SUM(packages) packages, SUM(weight) weight FROM ticket WHERE refFk = ? - ) pack - JOIN ( - SELECT SUM(weight) weight - FROM ticket - WHERE refFk = ? - ) wei + ) calc WHERE t.refFk = ? LIMIT 1 From 182cd3fa8e79423f5cf28c0b13931ee2ceb48e55 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 20 Jun 2024 11:34:51 +0200 Subject: [PATCH 51/81] feat boxPicking refs #7357 --- db/dump/fixtures.before.sql | 2 +- loopback/locale/es.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index dc9efacf1..9cd470dab 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3883,7 +3883,7 @@ INSERT INTO `vn`.`calendarHolidays` (calendarHolidaysTypeFk, dated, calendarHoli (1, '2001-05-18', 1, 5); -INSERT INTO dipole.printer (id, description) + INSERT INTO dipole.printer (id, description) VALUES(1, ''); INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 714475374..047774684 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -365,5 +365,6 @@ "You can only have one PDA": "Solo puedes tener un PDA", "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", - "Payment method is required": "El método de pago es obligatorio" + "Payment method is required": "El método de pago es obligatorio", + "CLIENT_NOT_ESPECIFIED": "CLIENT_NOT_ESPECIFIED" } \ No newline at end of file From 7d3c07aaaecc61fd1caa83221af430185b235b42 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Thu, 20 Jun 2024 10:44:31 +0000 Subject: [PATCH 52/81] Actualizar README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b052bd8bf..2ad83c2e4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Pull from repository. Run this commands on project root directory to install Node dependencies. ``` -$ npm install +$ pnpm install $ gulp install ``` From 9a4ec460733faf283b6a31789bca1d7e5ebdc0de Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 20 Jun 2024 13:09:40 +0200 Subject: [PATCH 53/81] hotfix: refs #6820 Deleted km validation --- modules/route/back/models/route.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index bf1f26e74..0fde335b3 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -20,21 +20,4 @@ module.exports = Self => { require('../methods/route/cmrEmail')(Self); require('../methods/route/getExpeditionSummary')(Self); require('../methods/route/getByWorker')(Self); - - Self.validate('kmStart', validateDistance, { - message: 'Distance must be lesser than 4000' - }); - - Self.validate('kmEnd', validateDistance, { - message: 'Distance must be lesser than 4000' - }); - - function validateDistance(err) { - if (this.kmEnd) { - const routeTotalKm = this.kmEnd - this.kmStart; - const routeMaxKm = 4000; - if (routeTotalKm > routeMaxKm || this.kmStart > this.kmEnd) - err(); - } - } }; From 852785b4c1ccb4aecc2efdc654a28f77bfc037ba Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 20 Jun 2024 13:45:38 +0200 Subject: [PATCH 54/81] fix: refs #195937 refactor incoterms --- .../invoice-incoterms/invoice-incoterms.js | 2 +- .../invoice-incoterms/sql/incoterms.sql | 89 ++++++++----------- 2 files changed, 38 insertions(+), 53 deletions(-) diff --git a/print/templates/reports/invoice-incoterms/invoice-incoterms.js b/print/templates/reports/invoice-incoterms/invoice-incoterms.js index cfe29169b..ebeaf4d7c 100755 --- a/print/templates/reports/invoice-incoterms/invoice-incoterms.js +++ b/print/templates/reports/invoice-incoterms/invoice-incoterms.js @@ -9,7 +9,7 @@ module.exports = { this.checkMainEntity(this.invoice); this.client = await this.findOneFromDef('client', [this.reference]); this.incoterms = - await this.findOneFromDef('incoterms', [this.reference, this.reference, this.reference, this.reference]); + await this.findOneFromDef('incoterms', [this.reference]); if (!this.incoterms) throw new UserError(`The address of the customer must have information about Incoterms and Customs Agent`); }, diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index 2a041fce0..b7c42a951 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -1,52 +1,37 @@ -SELECT calc.packages, - a.incotermsFk, - ic.name incotermsName, - calc.weight, - ca.fiscalName customsAgentName, - ca.street customsAgentStreet, - ca.nif customsAgentNif, - ca.phone customsAgentPhone, - ca.email customsAgentEmail, - CAST(vol.volume AS DECIMAL (10,2)) volume, - intr.intrastat - FROM vn.invoiceOut io - JOIN vn.supplier su ON su.id = io.companyFk - JOIN vn.client c ON c.id = io.clientFk - LEFT JOIN vn.province p ON p.id = c.provinceFk - JOIN vn.ticket t ON t.refFk = io.ref - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.incoterms ic ON ic.code = a.incotermsFk - LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN ( - SELECT SUM(volume) volume, COUNT(*) packages - FROM vn.invoiceOut io - JOIN vn.ticket t ON t.refFk = io.ref - JOIN vn.saleVolume sv ON sv.ticketFk = t.id - WHERE t.refFk = ? - ) vol - JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk - AND itc.itemFk = s.itemFk - JOIN vn.taxClass tc ON tc.id = itc.taxClassFk - JOIN vn.invoiceOutSerial ios ON ios.code = io.serial - AND ios.taxAreaFk = 'WORLD' - JOIN vn.country cty ON cty.id = c.countryFk - JOIN vn.payMethod pm ON pm.id = c .payMethodFk - JOIN vn.company co ON co.id=io.companyFk - JOIN vn.supplierAccount sa ON sa.id=co.supplierAccountFk - JOIN ( - SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) intrastat - FROM vn.ticket t - JOIN vn.invoiceOut io ON io.ref = t.refFk - JOIN vn.sale s ON t.id = s.ticketFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.intrastat ir ON ir.id = i.intrastatFk - WHERE t.refFk = ? - ) intr - JOIN ( - SELECT SUM(packages) packages, SUM(weight) weight - FROM ticket - WHERE refFk = ? - ) calc - WHERE t.refFk = ? - LIMIT 1 +WITH tickets AS( +SELECT id, packages, addressFk, weight + FROM ticket + WHERE refFk='E12400228' +) , weight AS( +SELECT weight + FROM tickets + WHERE weight + LIMIT 1 +), volume AS( +SELECT SUM(volume) volume + FROM tickets t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id +), intrastat AS( +SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) intrastat + FROM tickets t + JOIN vn.sale s ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.intrastat ir ON ir.id = i.intrastatFk +)SELECT SUM(t.packages), + a.incotermsFk, + ic.name incotermsName, + w.weight, + ca.fiscalName customsAgentName, + ca.street customsAgentStreet, + ca.nif customsAgentNif, + ca.phone customsAgentPhone, + ca.email customsAgentEmail, + CAST(v.volume AS DECIMAL (10,2)) volume, + i.intrastat + FROM tickets t + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.incoterms ic ON ic.code = a.incotermsFk + LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk + JOIN volume v + JOIN intrastat i + LEFT JOIN weight w ON TRUE From 8fc231da2ffefb8fa2c8ecc851217f068de34cef Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 20 Jun 2024 14:03:31 +0200 Subject: [PATCH 55/81] feat: refs #195937 --- print/templates/reports/invoice-incoterms/sql/incoterms.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index b7c42a951..f3566ae30 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -1,7 +1,7 @@ WITH tickets AS( SELECT id, packages, addressFk, weight FROM ticket - WHERE refFk='E12400228' + WHERE refFk= ? ) , weight AS( SELECT weight FROM tickets From e0d105313d4d34b2fb2b768efd8a601f86d1e095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 20 Jun 2024 14:27:11 +0200 Subject: [PATCH 56/81] feat: sincro client supplier sage refs #7595 --- .../procedures/accountingMovements_add.sql | 73 ++++++++++++------- .../sage/procedures/clientSupplier_add.sql | 34 +++++---- .../vn/triggers/client_afterUpdate.sql | 25 ++++++- .../vn/triggers/client_beforeUpdate.sql | 4 +- .../vn/triggers/supplier_afterUpdate.sql | 26 +++++++ .../00-firstScript.sql | 9 +++ 6 files changed, 128 insertions(+), 43 deletions(-) create mode 100644 db/routines/vn/triggers/supplier_afterUpdate.sql create mode 100644 db/versions/11105-bronzeChrysanthemum/00-firstScript.sql diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index 575c63f6c..88c599b09 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -21,7 +21,8 @@ BEGIN DECLARE vTransactionExportTaxFreeFk INT; DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; DECLARE vInvoiceTypeInformativeCode VARCHAR(1); - DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2) ; + DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); + DECLARE vCompanyCode INT; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -31,9 +32,6 @@ BEGIN FROM Naciones WHERE Nacion ='CEUTA Y MELILLA'; - SELECT pendingServiceTransactionTypeFk INTO vDuaTransactionFk - FROM config; - SELECT id INTO vTaxImportFk FROM taxType WHERE code = 'import21'; @@ -46,10 +44,14 @@ BEGIN FROM taxType WHERE code = 'import4'; - SELECT definitiveExportTransactionTypeFk INTO vTransactionExportFk - FROM config; - - SELECT shipmentTransactionTypeFk INTO vTransactionExportTaxFreeFk + SELECT shipmentTransactionTypeFk, + definitiveExportTransactionTypeFk, + pendingServiceTransactionTypeFk, + company_getCode(vCompanyFk) + INTO vTransactionExportTaxFreeFk, + vTransactionExportFk, + vDuaTransactionFk, + vCompanyCode FROM config; SELECT codeSage INTO vInvoiceTypeInformativeCode @@ -64,8 +66,6 @@ BEGIN WHERE enlazadoSage = FALSE AND Asiento <> 1 ; - CALL clientSupplier_add(vCompanyFk); - CALL pgc_add(vCompanyFk); CALL invoiceOut_manager(vYear, vCompanyFk); CALL invoiceIn_manager(vYear, vCompanyFk); @@ -158,7 +158,7 @@ BEGIN ) SELECT 'EN' TipoEntrada, YEAR(x.FECHA) Ejercicio, - company_getCode(vCompanyFk) AS CodigoEmpresa, + vCompanyCode CodigoEmpresa, x.ASIEN Asiento, IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL), 'D', 'H') CargoAbono, @@ -291,20 +291,6 @@ BEGIN WHERE m.CargoAbono = 'D' AND m.enlazadoSage = FALSE; --- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación - DELETE cp - FROM clientesProveedores cp - LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - --- Elimina cuentas contables que no se utilizarán en la importación - DELETE pc - FROM planCuentasPGC pc - LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - -- DUAS UPDATE movConta mci JOIN vn.XDiario x ON x.ASIEN = mci.Asiento @@ -411,5 +397,42 @@ BEGIN AND importeDivisa > 0 AND ImporteAsiento < 0; + CREATE OR REPLACE TEMPORARY TABLE tmp.clientSupplier + (INDEX(idClientSupplier, `type`)) + ENGINE = MEMORY + WITH client AS( + SELECT DISTINCT c.id + FROM sage.movConta mc + JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta + WHERE NOT enlazadoSage + ),supplier AS( + SELECT DISTINCT s.id + FROM sage.movConta mc + JOIN vn.supplier s ON s.account = mc.CodigoCuenta + WHERE NOT enlazadoSage + )SELECT idClientSupplier, `type` + FROM sage.clientSupplier cs + WHERE NOT isSync + UNION + SELECT id, 'C' + FROM client + UNION + SELECT id, 'P' + FROM supplier; + + CALL clientSupplier_add(vCompanyFk); + + INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) + SELECT vCompanyCode, `type`, idClientSupplier, FALSE + FROM tmp.clientSupplier; + + CALL pgc_add(vCompanyFk); +-- Elimina cuentas contables que no se utilizarán en la importación + DELETE pc + FROM planCuentasPGC pc + LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta + AND mc.enlazadoSage = FALSE + WHERE mc.codigoCuenta IS NULL; + END$$ DELIMITER ; diff --git a/db/routines/sage/procedures/clientSupplier_add.sql b/db/routines/sage/procedures/clientSupplier_add.sql index 70f3ef3d0..2c4b4db9d 100644 --- a/db/routines/sage/procedures/clientSupplier_add.sql +++ b/db/routines/sage/procedures/clientSupplier_add.sql @@ -1,11 +1,16 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`( + vCompanyFk INT +) BEGIN /** - * Prepara los datos de clientes y proveedores para exportarlos a Sage - * @vCompanyFk Empresa dela que se quiere trasladar datos + * Inserta en la tabla sage.clientesProveedores los datos de clientes y proveedores + * que se actualizaran o se daran de alta en Sage + * @vCompanyFk Id de empresa + * @table tmp.clientSupplier(idClientSupplier, `type`) */ DECLARE vCountryCeutaMelillaFk INT; + DECLARE vCompanyCode INT DEFAULT company_getCode(vCompanyFk); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); SELECT SiglaNacion INTO vCountryCanariasCode @@ -45,7 +50,7 @@ BEGIN Email1, iban) SELECT - company_getCode(vCompanyFk), + vCompanyCode, 'C', c.id, c.socialName, @@ -53,7 +58,7 @@ BEGIN IFNULL(c.street, ''), c.accountingAccount, @fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)), - IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)), + IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)), IFNULL(c.postcode, ''), IFNULL(c.city, ''), IFNULL(pr.CodigoProvincia, ''), @@ -75,15 +80,14 @@ BEGIN IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''), IFNULL(c.iban, '') FROM vn.`client` c - JOIN clientLastTwoMonths clm ON clm.clientFk = c.id + JOIN tmp.clientSupplier cs ON cs.idClientSupplier = c.id LEFT JOIN vn.country cu ON cu.id = c.countryFk LEFT JOIN Naciones n ON n.countryFk = cu.id LEFT JOIN vn.province p ON p.id = c.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id - WHERE c.isRelevant - AND clm.companyFk = vCompanyFk + WHERE cs.type = 'C' UNION ALL - SELECT company_getCode(vCompanyFk), + SELECT vCompanyCode, 'P', s.id, s.name, @@ -107,18 +111,18 @@ BEGIN IFNULL(s.transactionTypeSageFk, 0), IFNULL(s.withholdingSageFk, '0'), IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''), - IFNULL(iban, '') + IFNULL(sa.iban, '') FROM vn.supplier s - JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id + JOIN tmp.clientSupplier cs ON cs.idClientSupplier = s.id LEFT JOIN vn.country co ON co.id = s.countryFk LEFT JOIN Naciones n ON n.countryFk = co.id LEFT JOIN vn.province p ON p.id = s.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - WHERE pl.companyFk = vCompanyFk AND - s.isActive AND - s.nif <> '' - GROUP BY pl.supplierFk, pl.companyFk; + WHERE cs.type = 'P' + GROUP BY s.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientSupplier; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/client_afterUpdate.sql b/db/routines/vn/triggers/client_afterUpdate.sql index e316fb08a..a2a3e48e3 100644 --- a/db/routines/vn/triggers/client_afterUpdate.sql +++ b/db/routines/vn/triggers/client_afterUpdate.sql @@ -3,12 +3,35 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterUpdate` AFTER UPDATE ON `client` FOR EACH ROW BEGIN - IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN + IF NOT (NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN UPDATE `address` SET isDefaultAddress = FALSE WHERE clientFk = NEW.id; UPDATE `address` SET isDefaultAddress = TRUE WHERE id = NEW.defaultAddressFk; END IF; + + IF NEW.id <> OLD.id + OR NOT (NEW.provinceFk <=> OLD.provinceFk) + OR NOT (NEW.socialName <=> OLD.socialName) + OR NOT (NEW.street <=> OLD.street) + OR NOT (NEW.accountingAccount <=> OLD.accountingAccount) + OR NOT (NEW.isVies <=> OLD.isVies) + OR NOT (NEW.fi <=> OLD.fi) + OR NOT (NEW.postcode <=> OLD.postcode) + OR NOT (NEW.city <=> OLD.city) + OR NOT (NEW.countryFk <=> OLD.countryFk) + OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk) + OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk) + OR NOT (NEW.email <=> OLD.email) + OR NOT (NEW.iban <=> OLD.iban) + OR NOT (NEW.phone <=> OLD.phone) + OR NOT (NEW.mobile <=> OLD.mobile) THEN + + UPDATE sage.clientSupplier + SET isSync = FALSE + WHERE idClientSupplier IN (NEW.id, OLD.id) + AND `type` = 'C'; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/client_beforeUpdate.sql b/db/routines/vn/triggers/client_beforeUpdate.sql index 2f384c535..914ae5b8a 100644 --- a/db/routines/vn/triggers/client_beforeUpdate.sql +++ b/db/routines/vn/triggers/client_beforeUpdate.sql @@ -65,11 +65,11 @@ BEGIN END IF; END IF; - IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN + IF NOT (NEW.salesPersonFk <=> OLD.salesPersonFk) THEN SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); END IF; - IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN + IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN SET NEW.isTaxDataChecked = 0; END IF; END$$ diff --git a/db/routines/vn/triggers/supplier_afterUpdate.sql b/db/routines/vn/triggers/supplier_afterUpdate.sql new file mode 100644 index 000000000..e89df037f --- /dev/null +++ b/db/routines/vn/triggers/supplier_afterUpdate.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_afterUpdate` + BEFORE UPDATE ON `supplier` + FOR EACH ROW +BEGIN + IF NEW.id <> OLD.id + OR NOT (NEW.name <=> OLD.name) + OR NOT (NEW.street <=> OLD.street) + OR NOT (NEW.account <=> OLD.account) + OR NOT (NEW.nif <=> OLD.nif) + OR NOT (NEW.isVies <=> OLD.isVies) + OR NOT (NEW.provinceFk <=> OLD.provinceFk) + OR NOT (NEW.countryFk <=> OLD.countryFk) + OR NOT (NEW.postCode <=> OLD.postCode) + OR NOT (NEW.city <=> OLD.city) + OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk) + OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk) + OR NOT (NEW.withholdingSageFk <=> OLD.withholdingSageFk) THEN + + UPDATE sage.clientSupplier + SET isSync = FALSE + WHERE idClientSupplier IN (NEW.id, OLD.id) + AND `type` = 'P'; + END IF; +END$$ +DELIMITER ; diff --git a/db/versions/11105-bronzeChrysanthemum/00-firstScript.sql b/db/versions/11105-bronzeChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..685cd8f75 --- /dev/null +++ b/db/versions/11105-bronzeChrysanthemum/00-firstScript.sql @@ -0,0 +1,9 @@ + +CREATE OR REPLACE TABLE sage.clientSupplier ( + `companyFk` smallint(6) NOT NULL, + `type` ENUM('C','P') NOT NULL, + `idClientSupplier` INT NOT NULL, + `isSync` TINYINT(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`companyFk`,`idClientSupplier`,`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci + COMMENT='Clients and suppliers present in Sage and their synchronization status'; \ No newline at end of file From 414bf9eb03a72329ffe7f5ef296b7a28d30214c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 20 Jun 2024 14:48:32 +0200 Subject: [PATCH 57/81] feat: sincro client supplier sage refs #7595 --- db/routines/sage/procedures/accountingMovements_add.sql | 2 ++ db/routines/sage/procedures/clientSupplier_add.sql | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index 88c599b09..ada954334 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -425,6 +425,8 @@ BEGIN INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) SELECT vCompanyCode, `type`, idClientSupplier, FALSE FROM tmp.clientSupplier; + + DROP TEMPORARY TABLE tmp.clientSupplier; CALL pgc_add(vCompanyFk); -- Elimina cuentas contables que no se utilizarán en la importación diff --git a/db/routines/sage/procedures/clientSupplier_add.sql b/db/routines/sage/procedures/clientSupplier_add.sql index 2c4b4db9d..2d1a51882 100644 --- a/db/routines/sage/procedures/clientSupplier_add.sql +++ b/db/routines/sage/procedures/clientSupplier_add.sql @@ -122,7 +122,5 @@ BEGIN LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id WHERE cs.type = 'P' GROUP BY s.id; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientSupplier; END$$ DELIMITER ; From 31a75956c040bf44665cf1ba3a9d0e153e479172 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 20 Jun 2024 11:49:25 +0000 Subject: [PATCH 58/81] feat: add CALL util.debugAdd --- back/methods/vn-user/renew-token.js | 66 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/back/methods/vn-user/renew-token.js b/back/methods/vn-user/renew-token.js index 5581d19ac..ae554d398 100644 --- a/back/methods/vn-user/renew-token.js +++ b/back/methods/vn-user/renew-token.js @@ -16,36 +16,50 @@ module.exports = Self => { accessScopes: ['DEFAULT', 'read:multimedia']}); Self.renewToken = async function(ctx) { - const {accessToken: token} = ctx.req; + let accessToken; + let token; + try { + token = ctx.req.accessToken; + const {courtesyTime} = await models.AccessTokenConfig.findOne({ + fields: ['courtesyTime'] + }); + const isNotExceeded = await Self.validateToken(ctx); + if (isNotExceeded) + return token; - const {courtesyTime} = await models.AccessTokenConfig.findOne({ - fields: ['courtesyTime'] - }); - const isNotExceeded = await Self.validateToken(ctx); - if (isNotExceeded) - return token; - - // Schedule to remove current token - setTimeout(async() => { - try { - const exists = await models.AccessToken.findById(token.id); - exists && await Self.logout(token.id); - } catch (err) { + // Schedule to remove current token + setTimeout(async() => { + try { + const exists = await models.AccessToken.findById(token.id); + exists && await Self.logout(token.id); + } catch (error) { // eslint-disable-next-line no-console - console.error(err); - } - }, courtesyTime * 1000); + console.error(error); + const body = JSON.stringify({err: error, token}); + await handleError(body); + throw new Error(error); + } + }, courtesyTime * 1000); - // Get scopes + // Get scopes - let createTokenOptions = {}; - const {scopes} = token; - if (scopes) - createTokenOptions = {scopes: [scopes[0]]}; - // Create new accessToken - const user = await Self.findById(token.userId); - const accessToken = await user.accessTokens.create(createTokenOptions); + let createTokenOptions = {}; + const {scopes} = token; + if (scopes) + createTokenOptions = {scopes: [scopes[0]]}; + // Create new accessToken + const user = await Self.findById(token.userId); + accessToken = await user.accessTokens.create(createTokenOptions); - return {id: accessToken.id, ttl: accessToken.ttl}; + return {id: accessToken.id, ttl: accessToken.ttl}; + } catch (error) { + const body = JSON.stringify({error: error.message, token, accessToken}); + await handleError(body); + throw new Error(error); + } }; }; + +async function handleError(body, tag = 'renewToken') { + await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]); +} From bfb6689835359d72cd9e6806f1c81d8dab044f92 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 20 Jun 2024 11:50:10 +0000 Subject: [PATCH 59/81] test: add CALL util.debugAdd --- back/methods/vn-user/specs/renew-token.spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/back/methods/vn-user/specs/renew-token.spec.js b/back/methods/vn-user/specs/renew-token.spec.js index 70e7473d1..8f1bb54c1 100644 --- a/back/methods/vn-user/specs/renew-token.spec.js +++ b/back/methods/vn-user/specs/renew-token.spec.js @@ -61,4 +61,21 @@ describe('Renew Token', () => { expect(error).toBeUndefined(); expect(response.id).toEqual(ctx.req.accessToken.id); }); + + it('throw error', async() => { + let error; + + try { + await models.VnUser.renewToken({req: {token: null}}); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + const query = 'SELECT * FROM util.debug'; + + const debugLog = await models.Application.rawSql(query, null); + + expect(debugLog.length).toEqual(1); + }); }); From 833a7c87db39ef0bdd10b13f2b2d060098b2fcdb Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 20 Jun 2024 16:26:56 +0200 Subject: [PATCH 60/81] feat boxPicking refs #7357 --- loopback/locale/es.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 047774684..714475374 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -365,6 +365,5 @@ "You can only have one PDA": "Solo puedes tener un PDA", "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", - "Payment method is required": "El método de pago es obligatorio", - "CLIENT_NOT_ESPECIFIED": "CLIENT_NOT_ESPECIFIED" + "Payment method is required": "El método de pago es obligatorio" } \ No newline at end of file From 68f48de6f0b6564b53fae47c08dcf6bd0c7041dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 20 Jun 2024 17:14:38 +0200 Subject: [PATCH 61/81] feat: sincro client supplier sage refs #7595 --- .../sage/procedures/accountingMovements_add.sql | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index ada954334..8c129beb2 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -410,15 +410,26 @@ BEGIN FROM sage.movConta mc JOIN vn.supplier s ON s.account = mc.CodigoCuenta WHERE NOT enlazadoSage - )SELECT idClientSupplier, `type` + ),clientSupplierSync AS( + SELECT idClientSupplier, `type` + FROM sage.clientSupplier cs + WHERE isSync + ) + SELECT idClientSupplier, `type` FROM sage.clientSupplier cs WHERE NOT isSync UNION SELECT id, 'C' - FROM client + FROM client c + LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id + AND cs.Type ='C' + WHERE cs.idClientSupplier IS NULL UNION SELECT id, 'P' - FROM supplier; + FROM supplier s + LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id + AND cs.Type ='P' + WHERE cs.idClientSupplier IS NULL; CALL clientSupplier_add(vCompanyFk); From ed49c98c1c51ee5f7848e4a7d7ca811b1d93640e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 20 Jun 2024 18:18:03 +0200 Subject: [PATCH 62/81] fnpmeat: previas con sitema de reservas refs #6861 --- db/routines/vn/procedures/itemShelvingSale_setQuantity.sql | 5 +---- db/routines/vn/triggers/itemShelvingSale_afterInsert.sql | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 700821592..f3fed7c44 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -55,16 +55,13 @@ BEGIN SELECT id INTO vItemShelvingFk FROM itemShelving - WHERE id = vItemShelvingFk - AND FALSE + WHERE id = vItemShelvingFk FOR UPDATE; UPDATE itemShelving SET visible = GREATEST(0, visible - vQuantity) WHERE id = vItemShelvingFk; - - SELECT SUM(IF(isPicked, 0, quantity)), SUM(quantity) INTO vRemainingQuantity, vTotalQuantity FROM itemShelvingSale diff --git a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index 0c609d328..ef0048b34 100644 --- a/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -6,7 +6,7 @@ BEGIN UPDATE sale s JOIN operator o ON o.workerFk = account.myUser_getId() - SET s.isPicked = IF(o.isOnReservationMode, isPicked, TRUE) + SET s.isPicked = IF(o.isOnReservationMode, s.isPicked, TRUE) WHERE id = NEW.saleFk; END$$ DELIMITER ; \ No newline at end of file From ba48d93c1e97cd94f8ef2e5a60f1e9dc8bd89c88 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 20 Jun 2024 23:28:11 +0200 Subject: [PATCH 63/81] perf(salix): refs #6264 #6264 remove save token as debug row --- back/methods/vn-user/renew-token.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/back/methods/vn-user/renew-token.js b/back/methods/vn-user/renew-token.js index ae554d398..ae2d36e3e 100644 --- a/back/methods/vn-user/renew-token.js +++ b/back/methods/vn-user/renew-token.js @@ -16,44 +16,44 @@ module.exports = Self => { accessScopes: ['DEFAULT', 'read:multimedia']}); Self.renewToken = async function(ctx) { - let accessToken; - let token; + let createTokenOptions = {}; + let token; let isNotExceeded; try { token = ctx.req.accessToken; + const {courtesyTime} = await models.AccessTokenConfig.findOne({ fields: ['courtesyTime'] }); - const isNotExceeded = await Self.validateToken(ctx); + isNotExceeded = await Self.validateToken(ctx); if (isNotExceeded) return token; // Schedule to remove current token setTimeout(async() => { + let exists; try { - const exists = await models.AccessToken.findById(token.id); + exists = await models.AccessToken.findById(token.id); exists && await Self.logout(token.id); } catch (error) { // eslint-disable-next-line no-console console.error(error); - const body = JSON.stringify({err: error, token}); + const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, exists}; await handleError(body); throw new Error(error); } }, courtesyTime * 1000); // Get scopes - - let createTokenOptions = {}; const {scopes} = token; if (scopes) createTokenOptions = {scopes: [scopes[0]]}; // Create new accessToken const user = await Self.findById(token.userId); - accessToken = await user.accessTokens.create(createTokenOptions); + const accessToken = await user.accessTokens.create(createTokenOptions); return {id: accessToken.id, ttl: accessToken.ttl}; } catch (error) { - const body = JSON.stringify({error: error.message, token, accessToken}); + const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, createTokenOptions, isNotExceeded}; await handleError(body); throw new Error(error); } @@ -61,5 +61,6 @@ module.exports = Self => { }; async function handleError(body, tag = 'renewToken') { + body = JSON.stringify(body); await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]); } From 13952f60e178ef6a147fe8f98cdd5e84aafce9c0 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 21 Jun 2024 07:18:10 +0200 Subject: [PATCH 64/81] feat boxPicking refs #7357 --- back/models/expedition_PrintOut.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/back/models/expedition_PrintOut.json b/back/models/expedition_PrintOut.json index 6f521cda3..23a2fdbc4 100644 --- a/back/models/expedition_PrintOut.json +++ b/back/models/expedition_PrintOut.json @@ -13,12 +13,7 @@ "description": "id expeditionFk" }, "itemFk": { - "type": "number", - "required": true - }, - "shelvingFk": { - "type": "string", - "required": true + "type": "number" } } } \ No newline at end of file From fe154b9ee84f9db7c5e4edaa0ffd25b9156a7e4b Mon Sep 17 00:00:00 2001 From: Pako Date: Fri, 21 Jun 2024 08:32:22 +0200 Subject: [PATCH 65/81] sref --- .../supplierPackaging_ReportSource.sql | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql index a8e506244..63285203b 100644 --- a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql +++ b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql @@ -22,7 +22,7 @@ BEGIN landed, `in`, `out`, - warehouse, + sref, buyingValue, IF ( NOT (@vItemFk <=> sub.itemFk), @@ -31,19 +31,20 @@ BEGIN ) balance, @vItemFk := sub.itemFk previousItemFk FROM ( - SELECT supplierFk, - itemFk, - longName, - supplier, - CONCAT('E',entryFk) entryFk, - landed, - `in`, - `out`, - warehouse, - buyingValue - FROM supplierPackaging - WHERE supplierFk = vSupplierFk - AND landed >= vFromDated + SELECT sp.supplierFk, + sp.itemFk, + sp.longName, + sp.supplier, + CONCAT('E',sp.entryFk) entryFk, + sp.landed, + sp.`in`, + sp.`out`, + e.invoiceNumber sref, + sp.buyingValue + FROM supplierPackaging sp + JOIN entry e ON e.id = sp.entryFk + WHERE sp.supplierFk = vSupplierFk + AND sp.landed >= vFromDated UNION ALL SELECT vSupplierFk, itemFk, @@ -68,7 +69,7 @@ BEGIN DATE(t.shipped), -LEAST(s.quantity,0) `in`, GREATEST(s.quantity,0) `out`, - w.name, + t.cmrFk, s.price * (100 - s.discount) / 100 FROM sale s JOIN item i ON i.id = s.itemFk @@ -76,7 +77,6 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi - JOIN warehouse w ON w.id = t.warehouseFk WHERE su.id = vSupplierFk AND t.shipped >= vFromDated AND p.isPackageReturnable @@ -111,7 +111,7 @@ BEGIN DATE(t.shipped), -LEAST(tp.quantity,0) `in`, GREATEST(tp.quantity,0) `out`, - w.name, + t.cmrFk, 0 FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk @@ -119,7 +119,6 @@ BEGIN JOIN ticket t ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi - JOIN warehouse w ON w.id = t.warehouseFk WHERE su.id = vSupplierFk AND t.shipped >= vFromDated AND p.isPackageReturnable @@ -157,7 +156,7 @@ BEGIN landed, CAST(`in` AS DECIMAL(10,0)) `in`, CAST(`out` AS DECIMAL(10,0)) `out`, - warehouse, + sref, buyingValue, balance FROM tSupplierPackaging From 42b483e27e28878722206ee07cea699d4575cb43 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 21 Jun 2024 08:35:35 +0200 Subject: [PATCH 66/81] feat: refs #7555 remove account.password__ --- db/versions/11111-tealAralia/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11111-tealAralia/00-firstScript.sql diff --git a/db/versions/11111-tealAralia/00-firstScript.sql b/db/versions/11111-tealAralia/00-firstScript.sql new file mode 100644 index 000000000..4ef10d5f2 --- /dev/null +++ b/db/versions/11111-tealAralia/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE account.`user` DROP COLUMN password__; From c42a21bc6f8ed7fd42dd4eb28d7e4ebdb2fa09ec Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 21 Jun 2024 11:47:34 +0200 Subject: [PATCH 67/81] fix: refs #19537 changes required --- .../templates/reports/invoice-incoterms/sql/incoterms.sql | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/print/templates/reports/invoice-incoterms/sql/incoterms.sql b/print/templates/reports/invoice-incoterms/sql/incoterms.sql index f3566ae30..bbe4b2a0d 100644 --- a/print/templates/reports/invoice-incoterms/sql/incoterms.sql +++ b/print/templates/reports/invoice-incoterms/sql/incoterms.sql @@ -2,11 +2,6 @@ WITH tickets AS( SELECT id, packages, addressFk, weight FROM ticket WHERE refFk= ? -) , weight AS( -SELECT weight - FROM tickets - WHERE weight - LIMIT 1 ), volume AS( SELECT SUM(volume) volume FROM tickets t @@ -20,7 +15,7 @@ SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR ' )SELECT SUM(t.packages), a.incotermsFk, ic.name incotermsName, - w.weight, + MAX(t.weight) weight, ca.fiscalName customsAgentName, ca.street customsAgentStreet, ca.nif customsAgentNif, @@ -34,4 +29,3 @@ SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR ' LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk JOIN volume v JOIN intrastat i - LEFT JOIN weight w ON TRUE From 3fa7eb1d2aa03ca39289bb9836f5b997c0de0ca5 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 21 Jun 2024 13:01:19 +0200 Subject: [PATCH 68/81] feat itemShelving_filterBuyer refs #7023 --- db/routines/vn/procedures/itemShelving_filterBuyer.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql index 894a14464..2fdf21ee1 100644 --- a/db/routines/vn/procedures/itemShelving_filterBuyer.sql +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -15,13 +15,14 @@ proc:BEGIN SELECT * FROM (SELECT sub.itemFk, sub.longName, - CONCAT('Hoy quedan por sacar ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer, sub.upstairs, sub.downstairs, sub.visible, CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho, - sub.name itemColour + sub.name itemColour, + CAST(sub2.pendiente AS DECIMAL(10,0)) pendingAmount FROM (SELECT iss.itemFk, CONCAT(i.longName, ' ', IFNULL(i.size, ''),' ', IFNULL(i.subName, '') ) longName, '' size, @@ -52,13 +53,14 @@ proc:BEGIN UNION ALL SELECT v.item_id, i.longName, - CONCAT('Hoy quedan por sacar ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, 0, 0, v.visible, v.visible nicho, - ik.name itemColour + ik.name itemColour, + CAST(sub5.pendiente AS DECIMAL(10,0) pendingAmount FROM cache.visible v JOIN item i ON i.id = v.item_id LEFT JOIN ink ik ON ik.id = i.inkFk From 41316537006c336064476cadd7add125ed74bbe9 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 21 Jun 2024 13:02:36 +0200 Subject: [PATCH 69/81] feat itemShelving_filterBuyer refs #7023 --- db/routines/vn/procedures/itemShelving_filterBuyer.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql index 2fdf21ee1..d4675ea0e 100644 --- a/db/routines/vn/procedures/itemShelving_filterBuyer.sql +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -60,7 +60,7 @@ proc:BEGIN v.visible, v.visible nicho, ik.name itemColour, - CAST(sub5.pendiente AS DECIMAL(10,0) pendingAmount + CAST(sub5.pendiente AS DECIMAL(10,0)) pendingAmount FROM cache.visible v JOIN item i ON i.id = v.item_id LEFT JOIN ink ik ON ik.id = i.inkFk From 24cf23dddc0ef4c42407ef7576689fff1767132f Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 21 Jun 2024 13:16:01 +0200 Subject: [PATCH 70/81] feat: refs #62add travelKgPercentage table and model --- .../11114-goldenDracena/00-firstScript.sql | 18 ++++++++++++++++ .../methods/travel/extraCommunityFilter.js | 14 ++++++++++++- modules/travel/back/model-config.json | 5 ++++- .../back/models/travel-kg-percentage.json | 21 +++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 db/versions/11114-goldenDracena/00-firstScript.sql create mode 100644 modules/travel/back/models/travel-kg-percentage.json diff --git a/db/versions/11114-goldenDracena/00-firstScript.sql b/db/versions/11114-goldenDracena/00-firstScript.sql new file mode 100644 index 000000000..0b6581faf --- /dev/null +++ b/db/versions/11114-goldenDracena/00-firstScript.sql @@ -0,0 +1,18 @@ +-- Place your SQL code here +CREATE TABLE IF NOT EXISTS travelKgPercentage ( + value INT(3) PRIMARY KEY, + className VARCHAR(50) +); + +INSERT IGNORE INTO travelKgPercentage (value, className) + VALUES + (80, 'primary'), + (100, 'alert'); + +INSERT IGNORE INTO salix.ACL + SET model = 'TravelKgPercentage', + property = '*', + accessType = 'READ', + permission = 'ALLOW', + principalType = 'ROLE', + principalId = 'employee'; \ No newline at end of file diff --git a/modules/travel/back/methods/travel/extraCommunityFilter.js b/modules/travel/back/methods/travel/extraCommunityFilter.js index 488297318..dcb704ff5 100644 --- a/modules/travel/back/methods/travel/extraCommunityFilter.js +++ b/modules/travel/back/methods/travel/extraCommunityFilter.js @@ -138,7 +138,19 @@ module.exports = Self => { b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0) - ) as volumeKg + ) as volumeKg, + GREATEST( + CAST(SUM(b.weight * b.stickers) AS INT), + CAST( + SUM(vc.aerealVolumetricDensity * + b.stickers * + IF(pkg.volume, + pkg.volume, + pkg.width * pkg.depth * pkg.height + ) / 1000000 + ) AS INT + ) + / t.kg * 100, 0) percentageKg FROM travel t LEFT JOIN supplier s ON s.id = t.cargoSupplierFk LEFT JOIN entry e ON e.travelFk = t.id diff --git a/modules/travel/back/model-config.json b/modules/travel/back/model-config.json index ed5c071b3..952ce0d20 100644 --- a/modules/travel/back/model-config.json +++ b/modules/travel/back/model-config.json @@ -11,6 +11,9 @@ "Thermograph": { "dataSource": "vn" }, + "TravelKgPercentage": { + "dataSource": "vn" + }, "TravelThermograph": { "dataSource": "vn" }, @@ -20,4 +23,4 @@ "Temperature": { "dataSource": "vn" } -} +} \ No newline at end of file diff --git a/modules/travel/back/models/travel-kg-percentage.json b/modules/travel/back/models/travel-kg-percentage.json new file mode 100644 index 000000000..e99a88999 --- /dev/null +++ b/modules/travel/back/models/travel-kg-percentage.json @@ -0,0 +1,21 @@ +{ + "name": "TravelKgPercentage", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "travelKgPercentage" + } + }, + "properties": { + "value": { + "type": "number", + "id": true + }, + "className": { + "type": "string" + } + } +} \ No newline at end of file From 5ef0dffa3e23d82a10a63ed26b126da05def2230 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 21 Jun 2024 13:38:00 +0200 Subject: [PATCH 71/81] fix: refs #6238 add scheme --- db/versions/11114-goldenDracena/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11114-goldenDracena/00-firstScript.sql b/db/versions/11114-goldenDracena/00-firstScript.sql index 0b6581faf..cc283f418 100644 --- a/db/versions/11114-goldenDracena/00-firstScript.sql +++ b/db/versions/11114-goldenDracena/00-firstScript.sql @@ -1,10 +1,10 @@ -- Place your SQL code here -CREATE TABLE IF NOT EXISTS travelKgPercentage ( +CREATE TABLE IF NOT EXISTS vn.travelKgPercentage ( value INT(3) PRIMARY KEY, className VARCHAR(50) ); -INSERT IGNORE INTO travelKgPercentage (value, className) +INSERT IGNORE INTO vn.travelKgPercentage (value, className) VALUES (80, 'primary'), (100, 'alert'); From ea0b0dc779f027491ce6c2eccea1ba4b3e32d493 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 24 Jun 2024 08:08:39 +0200 Subject: [PATCH 72/81] fix: business overlapping --- .../vn/triggers/business_beforeUpdate.sql | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/triggers/business_beforeUpdate.sql b/db/routines/vn/triggers/business_beforeUpdate.sql index 4b7a10041..7dc69bc75 100644 --- a/db/routines/vn/triggers/business_beforeUpdate.sql +++ b/db/routines/vn/triggers/business_beforeUpdate.sql @@ -12,23 +12,21 @@ BEGIN END IF; IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN - - SELECT COUNT(*) > 0 INTO isOverlapping - FROM business b - WHERE (util.hasDateOverlapped( - NEW.started, - IFNULL(NEW.ended, b.started), - b.started, - IFNULL(b.ended, NEW.started)) - OR (NEW.ended <=> NULL AND b.ended <=> NULL)) - AND b.id <> OLD.id - AND workerFk = OLD.workerFk; + SELECT util.hasDateOverlapped( + started, + ended, + NEW.started, + IFNULL(NEW.ended, b.started) + ) isOverlapped INTO isOverlapping + FROM vn.business b + WHERE workerFk = NEW.workerFK + AND b.id <> NEW.id + ORDER BY isOverlapped DESC + LIMIT 1; IF isOverlapping THEN CALL util.throw ('IS_OVERLAPPING'); END IF; - END IF; - END$$ DELIMITER ; From 8c5f468087cd7f50ac00d574961f1c556441c0a6 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 24 Jun 2024 10:30:25 +0200 Subject: [PATCH 73/81] tested proc --- .../supplierPackaging_ReportSource.sql | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql index a3401843a..2426417c5 100644 --- a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql +++ b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql @@ -1,14 +1,14 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`( +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`( vFromDated DATE, vSupplierFk INT ) BEGIN /** -* Selecciona los embalajes de un proveedor a partir de una fecha +* Create a report with packaging balance * -* @param vFromDated Fecha de la que partir -* @param vSupplierFk Id del proveedor +* @param vFromDated Starting date +* @param vSupplierFk Supplier ID */ SET @vBalance = 0; SET @vItemFk = NULL; @@ -22,7 +22,7 @@ BEGIN landed, `in`, `out`, - warehouse, + sref, buyingValue, IF ( NOT (@vItemFk <=> sub.itemFk), @@ -31,19 +31,20 @@ BEGIN ) balance, @vItemFk := sub.itemFk previousItemFk FROM ( - SELECT supplierFk, - itemFk, - longName, - supplier, - CONCAT('E',entryFk) entryFk, - landed, - `in`, - `out`, - warehouse, - buyingValue - FROM supplierPackaging - WHERE supplierFk = vSupplierFk - AND landed >= vFromDated + SELECT sp.supplierFk, + sp.itemFk, + sp.longName, + sp.supplier, + CONCAT('E',sp.entryFk) entryFk, + sp.landed, + sp.`in`, + sp.`out`, + e.invoiceNumber sref, + sp.buyingValue + FROM supplierPackaging sp + JOIN entry e ON e.id = sp.entryFk + WHERE sp.supplierFk = vSupplierFk + AND sp.landed >= vFromDated UNION ALL SELECT vSupplierFk, itemFk, @@ -68,7 +69,7 @@ BEGIN DATE(t.shipped), -LEAST(s.quantity,0) `in`, GREATEST(s.quantity,0) `out`, - t.warehouseFk, + t.cmrFk, s.price * (100 - s.discount) / 100 FROM sale s JOIN item i ON i.id = s.itemFk @@ -99,6 +100,7 @@ BEGIN WHERE su.id = vSupplierFk AND t.shipped < vFromDated AND p.isPackageReturnable + AND NOT t.isDeleted GROUP BY s.itemFk UNION ALL SELECT vSupplierFk, @@ -109,7 +111,7 @@ BEGIN DATE(t.shipped), -LEAST(tp.quantity,0) `in`, GREATEST(tp.quantity,0) `out`, - t.warehouseFk, + t.cmrFk, 0 FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk @@ -138,8 +140,9 @@ BEGIN JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi WHERE su.id = vSupplierFk - AND t.shipped >= vFromDated + AND t.shipped < vFromDated AND p.isPackageReturnable + AND NOT t.isDeleted GROUP BY p.itemFk ORDER BY itemFk, landed, entryFk ) sub @@ -153,7 +156,7 @@ BEGIN landed, CAST(`in` AS DECIMAL(10,0)) `in`, CAST(`out` AS DECIMAL(10,0)) `out`, - warehouse, + sref, buyingValue, balance FROM tSupplierPackaging From f999010c6c670fa20c35814e3741d8eb59f008f9 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 24 Jun 2024 10:32:12 +0200 Subject: [PATCH 74/81] tested proc --- .../supplierPackaging_ReportSource.sql | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql index a3401843a..63285203b 100644 --- a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql +++ b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql @@ -5,10 +5,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_R ) BEGIN /** -* Selecciona los embalajes de un proveedor a partir de una fecha +* Create a report with packaging balance * -* @param vFromDated Fecha de la que partir -* @param vSupplierFk Id del proveedor +* @param vFromDated Starting date +* @param vSupplierFk Supplier ID */ SET @vBalance = 0; SET @vItemFk = NULL; @@ -22,7 +22,7 @@ BEGIN landed, `in`, `out`, - warehouse, + sref, buyingValue, IF ( NOT (@vItemFk <=> sub.itemFk), @@ -31,19 +31,20 @@ BEGIN ) balance, @vItemFk := sub.itemFk previousItemFk FROM ( - SELECT supplierFk, - itemFk, - longName, - supplier, - CONCAT('E',entryFk) entryFk, - landed, - `in`, - `out`, - warehouse, - buyingValue - FROM supplierPackaging - WHERE supplierFk = vSupplierFk - AND landed >= vFromDated + SELECT sp.supplierFk, + sp.itemFk, + sp.longName, + sp.supplier, + CONCAT('E',sp.entryFk) entryFk, + sp.landed, + sp.`in`, + sp.`out`, + e.invoiceNumber sref, + sp.buyingValue + FROM supplierPackaging sp + JOIN entry e ON e.id = sp.entryFk + WHERE sp.supplierFk = vSupplierFk + AND sp.landed >= vFromDated UNION ALL SELECT vSupplierFk, itemFk, @@ -68,7 +69,7 @@ BEGIN DATE(t.shipped), -LEAST(s.quantity,0) `in`, GREATEST(s.quantity,0) `out`, - t.warehouseFk, + t.cmrFk, s.price * (100 - s.discount) / 100 FROM sale s JOIN item i ON i.id = s.itemFk @@ -99,6 +100,7 @@ BEGIN WHERE su.id = vSupplierFk AND t.shipped < vFromDated AND p.isPackageReturnable + AND NOT t.isDeleted GROUP BY s.itemFk UNION ALL SELECT vSupplierFk, @@ -109,7 +111,7 @@ BEGIN DATE(t.shipped), -LEAST(tp.quantity,0) `in`, GREATEST(tp.quantity,0) `out`, - t.warehouseFk, + t.cmrFk, 0 FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk @@ -138,8 +140,9 @@ BEGIN JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi WHERE su.id = vSupplierFk - AND t.shipped >= vFromDated + AND t.shipped < vFromDated AND p.isPackageReturnable + AND NOT t.isDeleted GROUP BY p.itemFk ORDER BY itemFk, landed, entryFk ) sub @@ -153,7 +156,7 @@ BEGIN landed, CAST(`in` AS DECIMAL(10,0)) `in`, CAST(`out` AS DECIMAL(10,0)) `out`, - warehouse, + sref, buyingValue, balance FROM tSupplierPackaging From 5f329fde38055a153436297a05f9145c8c82959c Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 24 Jun 2024 10:32:51 +0200 Subject: [PATCH 75/81] or replace --- db/routines/vn/procedures/supplierPackaging_ReportSource.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql index 2426417c5..63285203b 100644 --- a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql +++ b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`( vFromDated DATE, vSupplierFk INT ) From cf79711f6aa2e0c675fedd11bc61cf67e3b87b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 24 Jun 2024 13:30:03 +0200 Subject: [PATCH 76/81] feat: previas con sitema de reservas refs #6861 --- db/routines/vn/procedures/itemShelvingSale_doReserve.sql | 6 +++--- db/routines/vn/procedures/itemShelvingSale_reallocate.sql | 2 +- db/routines/vn/procedures/itemShelvingSale_setQuantity.sql | 2 +- db/versions/10852-pinkOak/00-firstScript.sql | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_doReserve.sql b/db/routines/vn/procedures/itemShelvingSale_doReserve.sql index d7bf4b181..629e303b3 100644 --- a/db/routines/vn/procedures/itemShelvingSale_doReserve.sql +++ b/db/routines/vn/procedures/itemShelvingSale_doReserve.sql @@ -2,7 +2,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_doReserve`() proc: BEGIN /** - * Genera reservas de la tabla itemShelvingSaleReserv + * Genera reservas de la tabla vn.itemShelvingSaleReserve */ DECLARE vDone BOOL; DECLARE vSaleFk INT; @@ -26,7 +26,7 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tSale ENGINE = MEMORY - SELECT id, saleFk FROM itemShelvingSaleReserv; + SELECT id, saleFk FROM itemShelvingSaleReserve; OPEN vSales; @@ -43,7 +43,7 @@ proc: BEGIN CLOSE vSales; - DELETE iss FROM itemShelvingSaleReserv iss JOIN tSale s ON s.id = iss.id; + DELETE iss FROM itemShelvingSaleReserve iss JOIN tSale s ON s.id = iss.id; DROP TEMPORARY TABLE tSale; diff --git a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql index ab898bdd4..85230a386 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql @@ -28,7 +28,7 @@ BEGIN WHERE id = vItemShelvingFk AND itemFk = vItemFk; - INSERT INTO itemShelvingSaleReserv (saleFk) + INSERT INTO itemShelvingSaleReserve (saleFk) SELECT DISTINCT iss.saleFk FROM itemShelvingSale iss JOIN itemShelving ish ON ish.id = iss.itemShelvingFk diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 00427039a..42f915ead 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -86,7 +86,7 @@ BEGIN COMMIT; IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - INSERT INTO itemShelvingSaleReserv (saleFk) + INSERT INTO itemShelvingSaleReserve (saleFk) SELECT vSaleFk; CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk); END IF; diff --git a/db/versions/10852-pinkOak/00-firstScript.sql b/db/versions/10852-pinkOak/00-firstScript.sql index 7739976e6..41b75c7e1 100644 --- a/db/versions/10852-pinkOak/00-firstScript.sql +++ b/db/versions/10852-pinkOak/00-firstScript.sql @@ -16,11 +16,11 @@ ALTER TABLE vn.itemShelving ADD available INT NULL; UPDATE vn.itemShelving SET available = visible; -CREATE TABLE vn.itemShelvingSaleReserv ( +CREATE TABLE vn.itemShelvingSaleReserve ( `id` int(11) NOT NULL AUTO_INCREMENT, `saleFk` int(11) NOT NULL, PRIMARY KEY (`id`), - KEY `itemShelvingSaleReserv_ibfk_1` (`saleFk`) + KEY `itemShelvingSaleReserve_ibfk_1` (`saleFk`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue of changed itemShelvingSale to reserve'; From 134c38b9fdb7df7dcb237b625c5f68b020fdccfb Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 25 Jun 2024 08:57:21 +0200 Subject: [PATCH 77/81] refs #6753 Hotfix --- modules/ticket/back/methods/ticket/saveSign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index b5c662089..ed54a5074 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -140,7 +140,7 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions); if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); From cf0f80142fed798c3307565a69158d7dba9276c4 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 25 Jun 2024 09:24:34 +0200 Subject: [PATCH 78/81] hotFix: create view vn.expeditionTruck --- db/routines/vn/views/expeditionTruck.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/routines/vn/views/expeditionTruck.sql diff --git a/db/routines/vn/views/expeditionTruck.sql b/db/routines/vn/views/expeditionTruck.sql new file mode 100644 index 000000000..065869de0 --- /dev/null +++ b/db/routines/vn/views/expeditionTruck.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionTruck` +AS SELECT `rs`.`id` AS `id`, + `rs`.`roadmapFk` AS `roadmapFk`, + `rs`.`eta` AS `eta`, + `rs`.`description` AS `description`, + `rs`.`bufferFk` AS `bufferFk`, + `rs`.`created` AS `created`, + `rs`.`userFk` AS `userFk` +FROM `vn`.`roadmapStop` `rs`; From 6150f64e88853ce330ebef47ba42d96cc9b677d8 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 25 Jun 2024 09:29:42 +0200 Subject: [PATCH 79/81] build: db dump --- db/dump/.dump/data.sql | 97 ++-- db/dump/.dump/privileges.sql | 61 +- db/dump/.dump/structure.sql | 1057 ++++++++++++++++++---------------- db/dump/.dump/triggers.sql | 207 +++++-- 4 files changed, 809 insertions(+), 613 deletions(-) diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 18e3fd4b5..c979ea1a2 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -3,7 +3,7 @@ USE `util`; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -INSERT INTO `version` VALUES ('vn-database','11090','7adf4a373d19ce126adbc7b1077f69a74559c09a','2024-06-11 08:32:36','11094'); +INSERT INTO `version` VALUES ('vn-database','11114','cf0f80142fed798c3307565a69158d7dba9276c4','2024-06-25 09:25:54','11115'); INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL); @@ -834,19 +834,34 @@ INSERT INTO `versionLog` VALUES ('vn-database','11058','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','11059','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:34',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11060','00-createRoleReviewer.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:34',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11061','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-05-28 07:32:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11063','00-roadmapAddress.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11063','01-roadmapStop.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11063','02-roadmapStopGrants.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11064','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11065','00-modifyInvoiceInPrivileges.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:34',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11065','01-modifyInvoiceInAcls.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:34',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11068','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:34',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11069','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11070','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11071','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-05-28 07:32:48',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11074','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:35',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11075','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-05-28 12:54:13',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11078','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:35',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11079','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-05-31 08:22:10',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11080','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-05-31 12:01:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11082','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11083','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-03 10:46:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11084','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11087','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:38:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11089','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:39:16',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11090','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 08:32:35',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','11092','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-07 08:21:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11093','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:39:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11096','00-addBuyerAcl.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-11 12:48:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11105','00-firstScript.sql','jenkins@db-proxy1.servers.dc.verdnatura.es','2024-06-20 15:36:07',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11106','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:39:49',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11109','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-18 19:09:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','11114','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-06-25 08:39:49',NULL,NULL); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; @@ -930,7 +945,7 @@ INSERT INTO `role` VALUES (109,'salesTeamBoss','Jefe de equipo de comerciales',1 INSERT INTO `role` VALUES (110,'palletizer','Paletizadores',1,'2022-12-02 13:56:22','2022-12-02 13:56:30',NULL); INSERT INTO `role` VALUES (111,'entryEditor','Entry editor',1,'2023-01-13 12:21:55','2023-01-13 12:21:55',NULL); INSERT INTO `role` VALUES (112,'maintenance','Personal de mantenimiento',1,'2023-01-19 07:23:35','2023-01-19 07:23:35',NULL); -INSERT INTO `role` VALUES (114,'maintenanceBos','Jefe de mantenimiento',1,'2023-01-19 07:31:16','2023-05-17 13:07:21',NULL); +INSERT INTO `role` VALUES (114,'maintenanceBoss','Jefe de mantenimiento',1,'2023-01-19 07:31:16','2024-06-14 08:56:41',19295); INSERT INTO `role` VALUES (115,'itManagement','TI management',1,'2023-03-29 09:27:55','2023-03-29 09:28:04',NULL); INSERT INTO `role` VALUES (119,'palletizerBoss','Jefe de paletizadores',1,'2023-06-07 13:51:54','2023-06-07 13:51:54',NULL); INSERT INTO `role` VALUES (120,'developerBoss','Jefe de proyecto de desarrollo',1,'2023-06-19 09:07:21','2023-06-19 09:07:21',21709); @@ -1212,6 +1227,7 @@ INSERT INTO `roleInherit` VALUES (367,30,73,NULL); INSERT INTO `roleInherit` VALUES (368,130,49,10578); INSERT INTO `roleInherit` VALUES (369,50,130,10578); INSERT INTO `roleInherit` VALUES (370,72,130,10578); +INSERT INTO `roleInherit` VALUES (371,36,35,NULL); INSERT INTO `userPassword` VALUES (1,7,1,0,2,1); @@ -1535,7 +1551,7 @@ INSERT INTO `ACL` VALUES (383,'Sector','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (384,'Sector','*','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (386,'Route','driverRouteEmail','WRITE','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','customer'); +INSERT INTO `ACL` VALUES (387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','$owner'); INSERT INTO `ACL` VALUES (388,'Supplier','newSupplier','WRITE','ALLOW','ROLE','administrative'); INSERT INTO `ACL` VALUES (389,'ClaimRma','*','READ','ALLOW','ROLE','claimManager'); INSERT INTO `ACL` VALUES (390,'ClaimRma','*','WRITE','ALLOW','ROLE','claimManager'); @@ -1791,10 +1807,6 @@ INSERT INTO `ACL` VALUES (686,'MailForward','*','*','ALLOW','ROLE','hr'); INSERT INTO `ACL` VALUES (687,'ClientSms','find','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (688,'ClientSms','create','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'); -INSERT INTO `ACL` VALUES (691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'); -INSERT INTO `ACL` VALUES (692,'RoadmapStop','*','*','ALLOW','ROLE','production'); -INSERT INTO `ACL` VALUES (693,'RoadmapStop','*','*','ALLOW','ROLE','productionBoss'); INSERT INTO `ACL` VALUES (695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'); @@ -1863,7 +1875,7 @@ INSERT INTO `ACL` VALUES (761,'Route','downloadZip','READ','ALLOW','ROLE','emplo INSERT INTO `ACL` VALUES (762,'Route','filter','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (763,'Route','getByWorker','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (764,'Route','getDeliveryPoint','READ','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (765,'Route','getExternalCmrs','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (765,'Route','cmrs','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (766,'Route','getSuggestedTickets','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (767,'Route','getTickets','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (768,'Route','guessPriority','WRITE','ALLOW','ROLE','employee'); @@ -1939,8 +1951,6 @@ INSERT INTO `ACL` VALUES (840,'Locker','*','*','ALLOW','ROLE','hr'); INSERT INTO `ACL` VALUES (841,'Locker','*','*','ALLOW','ROLE','productionBoss'); INSERT INTO `ACL` VALUES (842,'Worker','__get__locker','READ','ALLOW','ROLE','hr'); INSERT INTO `ACL` VALUES (843,'Worker','__get__locker','READ','ALLOW','ROLE','productionBoss'); -INSERT INTO `ACL` VALUES (844,'RoadmapStop','*','*','ALLOW','ROLE','production'); -INSERT INTO `ACL` VALUES (845,'RoadmapStop','*','*','ALLOW','ROLE','productionBoss'); INSERT INTO `ACL` VALUES (846,'Ticket','refund','WRITE','ALLOW','ROLE','logistic'); INSERT INTO `ACL` VALUES (847,'RouteConfig','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (848,'InvoiceIn','updateInvoiceIn','WRITE','ALLOW','ROLE','administrative'); @@ -1960,6 +1970,19 @@ INSERT INTO `ACL` VALUES (861,'InvoiceIn','toBook','WRITE','ALLOW','ROLE','buyer INSERT INTO `ACL` VALUES (862,'InvoiceIn','deleteById','WRITE','ALLOW','ROLE','buyer'); INSERT INTO `ACL` VALUES (863,'InvoiceIn','create','WRITE','ALLOW','ROLE','administrative'); INSERT INTO `ACL` VALUES (864,'InvoiceIn','create','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (865,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (866,'InvoiceOut','download','READ','ALLOW','ROLE','$owner'); +INSERT INTO `ACL` VALUES (867,'InvoiceIn','*','READ','ALLOW','ROLE','maintenanceBoss'); +INSERT INTO `ACL` VALUES (868,'InvoiceIn','*','READ','ALLOW','ROLE','maintenanceBos'); +INSERT INTO `ACL` VALUES (869,'Ticket','editZone','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (870,'Entry','find','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (871,'RoadmapAddress','*','WRITE','ALLOW','ROLE','palletizerBoss'); +INSERT INTO `ACL` VALUES (872,'RoadmapAddress','*','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (873,'Roadmap','*','WRITE','ALLOW','ROLE','palletizerBoss'); +INSERT INTO `ACL` VALUES (874,'Roadmap','*','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (875,'RoadmapStop','*','WRITE','ALLOW','ROLE','palletizerBoss'); +INSERT INTO `ACL` VALUES (876,'RoadmapStop','*','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (877,'TravelKgPercentage','*','READ','ALLOW','ROLE','employee'); INSERT INTO `fieldAcl` VALUES (1,'Client','name','update','employee'); INSERT INTO `fieldAcl` VALUES (2,'Client','contact','update','employee'); @@ -2280,7 +2303,7 @@ INSERT INTO `continent` VALUES (3,'África','AF'); INSERT INTO `continent` VALUES (4,'Europa','EU'); INSERT INTO `continent` VALUES (5,'Oceanía','OC'); -INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,110,763,0,0,0,0,25,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,110,763,0,0,0,0,26,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (22,'shopping','COMPRAS',2,3,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (23,'CMA','CAMARA',13,14,NULL,72,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (31,'it','INFORMATICA',4,5,NULL,72,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL,NULL,NULL,NULL); @@ -2291,49 +2314,49 @@ INSERT INTO `department` VALUES (37,'PROD','PRODUCCION',12,35,NULL,72,1,1,1,11,1 INSERT INTO `department` VALUES (38,'picking','SACADO',15,16,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,1,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (39,'packing','ENCAJADO',17,18,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,1,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (41,'administration','ADMINISTRACION',36,37,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (43,'VT','VENTAS',38,71,NULL,0,0,0,1,16,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (44,'management','GERENCIA',72,73,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (45,'logistic','LOGISTICA',74,75,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (46,'delivery','REPARTO',76,77,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (48,'storage','ALMACENAJE',78,79,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (49,NULL,'PROPIEDAD',80,81,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (52,NULL,'CARGA AEREA',82,83,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (43,'VT','VENTAS',38,69,NULL,0,0,0,1,15,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (44,'management','GERENCIA',70,71,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (45,'logistic','LOGISTICA',72,73,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (46,'delivery','REPARTO',74,75,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (48,'storage','ALMACENAJE',76,77,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (49,NULL,'PROPIEDAD',78,79,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (52,NULL,'CARGA AEREA',80,81,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (53,'marketing','MARKETING Y COMUNICACIÓN',39,40,NULL,72,0,0,2,0,43,'/1/43/',NULL,1,NULL,1,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (54,NULL,'ORNAMENTALES',84,85,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (54,NULL,'ORNAMENTALES',82,83,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (55,NULL,'TALLER NATURAL',19,20,14548,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1118,NULL,NULL,NULL); INSERT INTO `department` VALUES (56,NULL,'TALLER ARTIFICIAL',21,22,8470,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1927,NULL,NULL,NULL); -INSERT INTO `department` VALUES (58,'CMP','CAMPOS',86,89,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (59,'maintenance','MANTENIMIENTO',90,91,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (58,'CMP','CAMPOS',84,87,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (59,'maintenance','MANTENIMIENTO',88,89,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (60,'claims','RECLAMACIONES',41,42,NULL,72,0,0,2,0,43,'/1/43/',NULL,1,NULL,1,1,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (61,NULL,'VNH',92,95,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (66,NULL,'VERDNAMADRID',96,97,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (61,NULL,'VNH',90,93,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (66,NULL,'VERDNAMADRID',94,95,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (68,NULL,'COMPLEMENTOS',23,24,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (69,NULL,'VERDNABARNA',98,99,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (69,NULL,'VERDNABARNA',96,97,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (80,'spainTeam5','EQUIPO ESPAÑA 5',43,44,4250,0,0,0,2,0,43,'/1/43/','es5_equipo',1,'es5@verdnatura.es',0,0,0,0,NULL,NULL,'5300',NULL); -INSERT INTO `department` VALUES (86,NULL,'LIMPIEZA',100,101,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (89,NULL,'COORDINACION',102,103,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (90,NULL,'TRAILER',93,94,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (86,NULL,'LIMPIEZA',98,99,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (89,NULL,'COORDINACION',100,101,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (90,NULL,'TRAILER',91,92,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (91,'artificial','ARTIFICIAL',25,26,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (92,NULL,'EQUIPO SILVERIO',45,46,1203,0,0,0,2,0,43,'/1/43/','sdc_equipo',0,'gestioncomercial@verdnatura.es',0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (94,'spainTeam2','EQUIPO ESPAÑA 2',47,48,3797,0,0,0,2,0,43,'/1/43/','es2_equipo',0,'es2@verdnatura.es',0,0,0,0,NULL,NULL,'5100',NULL); -INSERT INTO `department` VALUES (95,'spainTeam1','EQUIPO ESPAÑA 1',49,50,24065,0,0,0,2,0,43,'/1/43/','es1_equipo',0,'es1@verdnatura.es',0,0,0,0,NULL,NULL,'5000',NULL); +INSERT INTO `department` VALUES (94,'spainTeam2','EQUIPO ESPAÑA 2',47,48,3797,0,0,0,2,0,43,'/1/43/','es2_equipo',1,'es2@verdnatura.es',0,0,0,0,NULL,NULL,'5100',NULL); +INSERT INTO `department` VALUES (95,'spainTeam1','EQUIPO ESPAÑA 1',49,50,24065,0,0,0,2,0,43,'/1/43/','es1_equipo',1,'es1@verdnatura.es',0,0,0,0,NULL,NULL,'5000',NULL); INSERT INTO `department` VALUES (96,NULL,'EQUIPO C LOPEZ',51,52,4661,0,0,0,2,0,43,'/1/43/','cla_equipo',0,'gestioncomercial@verdnatura.es',0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (115,NULL,'EQUIPO CLAUDI',53,54,3810,0,0,0,2,0,43,'/1/43/','csr_equipo',0,'gestioncomercial@verdnatura.es',0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (123,NULL,'EQUIPO ELENA BASCUÑANA',55,56,7102,0,0,0,2,0,43,'/1/43/','ebt_equipo',0,'gestioncomercial@verdnatura.es',0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (124,NULL,'CONTROL INTERNO',57,58,NULL,72,0,0,2,0,43,'/1/43/',NULL,0,NULL,1,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (125,'spainTeam3','EQUIPO ESPAÑA 3',59,60,1118,0,0,0,2,0,43,'/1/43/','es3_equipo',0,'es3@verdnatura.es',0,0,0,0,NULL,NULL,'5200',NULL); +INSERT INTO `department` VALUES (124,NULL,'CONTROL INTERNO',102,103,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (125,'spainTeam3','EQUIPO ESPAÑA 3',57,58,1118,0,0,0,2,0,43,'/1/43/','es3_equipo',1,'es3@verdnatura.es',0,0,0,0,NULL,NULL,'5200',NULL); INSERT INTO `department` VALUES (126,NULL,'PRESERVADO',27,28,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (128,NULL,'PALETIZADO',29,30,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (130,NULL,'REVISION',31,32,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,1,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (131,'greenhouse','INVERNADERO',87,88,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (132,NULL,'EQUIPO DC',61,62,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (133,'franceTeam','EQUIPO FRANCIA',63,64,1731,72,0,0,2,0,43,'/1/43/','fr_equipo',1,'gestionfrancia@verdnatura.es',0,0,0,0,NULL,NULL,'3300',NULL); -INSERT INTO `department` VALUES (134,'portugalTeam','EQUIPO PORTUGAL',65,66,6264,0,0,0,2,0,43,'/1/43/','pt_equipo',1,'portugal@verdnatura.es',0,0,0,0,NULL,NULL,'3500',NULL); +INSERT INTO `department` VALUES (131,'greenhouse','INVERNADERO',85,86,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (132,NULL,'EQUIPO DC',59,60,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (133,'franceTeam','EQUIPO FRANCIA',61,62,1731,72,0,0,2,0,43,'/1/43/','fr_equipo',1,'gestionfrancia@verdnatura.es',0,0,0,0,NULL,NULL,'3300',NULL); +INSERT INTO `department` VALUES (134,'portugalTeam','EQUIPO PORTUGAL',63,64,6264,0,0,0,2,0,43,'/1/43/','pt_equipo',1,'portugal@verdnatura.es',0,0,0,0,NULL,NULL,'3500',NULL); INSERT INTO `department` VALUES (135,'routers','ENRUTADORES',104,105,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (136,'heavyVehicles','VEHICULOS PESADOS',106,107,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (137,'sorter','SORTER',108,109,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL,NULL,NULL); -INSERT INTO `department` VALUES (139,'spainTeam4','EQUIPO ESPAÑA 4',67,68,3803,0,0,0,2,0,43,'/1/43/','es4_equipo',1,'es4@verdnatura.es',0,0,0,0,NULL,NULL,'5400',NULL); -INSERT INTO `department` VALUES (140,'hollandTeam','EQUIPO HOLANDA',69,70,NULL,0,0,0,2,0,43,'/1/43/','nl_equipo',1,NULL,0,0,0,0,NULL,NULL,NULL,NULL); +INSERT INTO `department` VALUES (139,'spainTeam4','EQUIPO ESPAÑA 4',65,66,3803,0,0,0,2,0,43,'/1/43/','es4_equipo',1,'es4@verdnatura.es',0,0,0,0,NULL,NULL,'5400',NULL); +INSERT INTO `department` VALUES (140,'hollandTeam','EQUIPO HOLANDA',67,68,NULL,0,0,0,2,0,43,'/1/43/','nl_equipo',1,NULL,0,0,0,0,NULL,NULL,NULL,NULL); INSERT INTO `department` VALUES (141,NULL,'PREVIA',33,34,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,1,NULL,NULL,NULL,NULL); INSERT INTO `docuware` VALUES (1,'deliveryNote','Albaranes cliente','find','find','N__ALBAR_N',NULL); diff --git a/db/dump/.dump/privileges.sql b/db/dump/.dump/privileges.sql index 00ef1018b..b99a60395 100644 --- a/db/dump/.dump/privileges.sql +++ b/db/dump/.dump/privileges.sql @@ -647,7 +647,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','pgcMaster',' INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemBarcode','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','host','alexm@%','0000-00-00 00:00:00','Select,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticket','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceIn','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceIn','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','invoiceIn','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select','Update'); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','invoiceIn','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert','Update'); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','inventoryFailure','alexm@%','0000-00-00 00:00:00','Select',''); @@ -982,7 +982,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceCorre INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ink','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','zone','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','XDiario','alexm@%','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','XDiario','jgallego@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','workerTimeControlMail','alexm@%','0000-00-00 00:00:00','Select,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerTimeControl','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','bi','financial','Greuge_Evolution','alexm@%','0000-00-00 00:00:00','Select',''); @@ -1048,7 +1048,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','grafana','userSession','j INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','receipt','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','buy','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','calendarHolidays','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','parking','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','parking','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','role','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','errorLogApp','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','continent','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); @@ -1300,7 +1300,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','itemShelving','g INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','negativeOrigin','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryBoss','Vehiculos_consumo','carlosap@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','entryOrder','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBos','project','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBoss','machineDms','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','ink','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','supplierDms','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','supplierDms','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); @@ -1350,7 +1350,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','warehouse INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','component','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','config','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','','Select'); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','componentType','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBos','machineDms','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','priceFixed','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','itemShelvingSale','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logisticAssist','tagAbbreviation','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','ticketTracking','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert',''); @@ -1361,7 +1361,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','sale_freight INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','accounting','jgallego@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','accounting','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerActivity','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBos','machineDetail','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketRequest','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryBoss','vehicleState','jgallego@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','expeditionState','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','specialPrice','jgallego@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); @@ -1384,6 +1384,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','professionalCategor INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','ticketObservation','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deliveryNoteState','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deliveryNote','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','comparative','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','invoiceOutExpense','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','delivery','carlosap@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','entry','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Update',''); @@ -1398,23 +1399,29 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','grafana','visit','root@lo INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerActivity','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','bankPolicy','alexm@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','bankPolicyDetail','alexm@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','bankPolicyReview','alexm@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','bankPolicyReview','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','roadmapStop','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','roadmapStop','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','agencyWorkCenter','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','roadmapStop','guillermo@10.5.1.3','0000-00-00 00:00:00','Insert,Update,Delete',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','antenna','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','bufferPool','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','enteringLog','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','expeditionLoading','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','failureLog','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','movingLog','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','sorterLog','guillermo@10.5.1.3','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','entryEditor','Entradas','guillermo@10.5.1.3','0000-00-00 00:00:00','Insert','Update'); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','clientInforma','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','solunionCAP','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','clientUnpaid','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','pay_dem','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','invoiceOut','guillermo@10.5.1.3','0000-00-00 00:00:00','Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financialBoss','invoiceOut','guillermo@10.5.1.3','0000-00-00 00:00:00','Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financialBoss','accountDetail','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','accountDetail','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBoss','project','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenanceBoss','machineDetail','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','antenna','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','bufferPool','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','enteringLog','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','expeditionLoading','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','failureLog','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','movingLog','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBoss','sorterLog','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); /*!40000 ALTER TABLE `tables_priv` ENABLE KEYS */; /*!40000 ALTER TABLE `columns_priv` DISABLE KEYS */; @@ -1474,28 +1481,6 @@ INSERT IGNORE INTO `columns_priv` VALUES ('','pbx','grafana','sip','user_id','0 INSERT IGNORE INTO `columns_priv` VALUES ('','pbx','grafana','sip','extension','0000-00-00 00:00:00','Select'); INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','name','0000-00-00 00:00:00','Select'); INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','active','0000-00-00 00:00:00','Select'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','editorFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','expenseFkDeductible','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','withholdingSageFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','isVatDeductible','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','bookEntried','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','siiTrascendencyInvoiceInFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','cplusTaxBreakFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','cplusSubjectOpFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','cplusRectificationTypeFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','siiTypeInvoiceInFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','operated','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','booked','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','docFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','companyFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','created','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','currencyFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','supplierRef','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','issued','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','supplierFk','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','serial','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','serialNumber','0000-00-00 00:00:00','Update'); -INSERT IGNORE INTO `columns_priv` VALUES ('','vn','administrative','invoiceIn','id','0000-00-00 00:00:00','Update'); INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','routeFk','0000-00-00 00:00:00','Update'); INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','name','0000-00-00 00:00:00','Update'); INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','beachFk','0000-00-00 00:00:00','Update'); @@ -1904,7 +1889,6 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','invoiceoutboo INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','ticket_gettax','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','util','productionAssi','midnight','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','dipole','employee','expedition_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); -INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticketstateupdate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerBoss','itempacking','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesPerson','ticket_clone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','cache','employee','available_refresh','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); @@ -2151,6 +2135,7 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','vn','artificialBoss','confection_co INSERT IGNORE INTO `procs_priv` VALUES ('','vn','financial','remittance_calc','PROCEDURE','alexm@db-proxy1.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','util','developer','connection_kill','PROCEDURE','jenkins@db-proxy1.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','financial','client_getRisk','PROCEDURE','jenkins@db-proxy1.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','developer','user_hasRole','FUNCTION','root@localhost','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','financialBoss','balance_create','PROCEDURE','jenkins@db-proxy2.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hrBoss','balance_create','PROCEDURE','jenkins@db-proxy2.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','buy_recalcPricesByEntry','PROCEDURE','jenkins@db-proxy2.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); @@ -2215,7 +2200,7 @@ INSERT IGNORE INTO `global_priv` VALUES ('','logisticAssist','{\"access\":0,\"v INSERT IGNORE INTO `global_priv` VALUES ('','logisticBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','maintenance','{\"access\":0,\"version_id\":101106,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','maintenanceBos','{\"access\":0,\"version_id\":101106,\"is_role\":true}'); -INSERT IGNORE INTO `global_priv` VALUES ('','maintenanceBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','maintenanceBoss','{\"access\":0,\"version_id\":101106,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','manager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','marketing','{\"access\": 0, \"is_role\": true,\"version_id\":101106}'); INSERT IGNORE INTO `global_priv` VALUES ('','marketingBoss','{\"access\":0,\"version_id\":101106,\"is_role\":true}'); diff --git a/db/dump/.dump/structure.sql b/db/dump/.dump/structure.sql index dd068cdc7..cd5b6aa3b 100644 --- a/db/dump/.dump/structure.sql +++ b/db/dump/.dump/structure.sql @@ -3240,11 +3240,12 @@ BEGIN JOIN vn.ticketLastState ts ON ts.ticketFk = t.id JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk JOIN vn.state st ON st.id = tt.stateFk + JOIN vn.alertLevel al ON al.code = 'DELIVERED' WHERE sc.componentFk = 17 AND sc.isGreuge = 0 AND t.shipped >= '2016-10-01' AND t.shipped < util.VN_CURDATE() - AND st.alertLevel >= 3; + AND st.alertLevel >= al.id; DELETE g.* FROM vn.greuge g @@ -8280,7 +8281,7 @@ BEGIN JOIN vn.address a ON a.id = t.addressFk JOIN vn.province p ON p.id = a.provinceFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk LEFT JOIN vn.beach b ON b.code = rm.beachFk LEFT JOIN vn.`zone`z ON z.id = t.zoneFk JOIN vn.agencyMode am ON t.agencyModeFk = am.id @@ -13105,7 +13106,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible`( vType INT, vPrefix VARCHAR(255)) BEGIN - + /** * Gets visible items of the specified type at specified date. * @@ -13114,7 +13115,7 @@ BEGIN * @param vType The type id * @param vPrefix The article prefix to filter or %NULL for all * @return tmp.itemVisible Visible items - */ + */ DECLARE vPrefixLen SMALLINT; DECLARE vFilter VARCHAR(255) DEFAULT NULL; DECLARE vDateInv DATE DEFAULT vn.getInventoryDate(); @@ -13123,13 +13124,13 @@ BEGIN GET DIAGNOSTICS CONDITION 1 @message = MESSAGE_TEXT; CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, + 'cau@verdnatura.es', + NULL, CONCAT('hedera.item_getVisible error: ', @message), CONCAT( - 'warehouse: ', IFNULL(vWarehouse, ''), - ', Fecha:', IFNULL(vDate, ''), - ', tipo: ', IFNULL(vType,''), + 'warehouse: ', IFNULL(vWarehouse, ''), + ', Fecha:', IFNULL(vDate, ''), + ', tipo: ', IFNULL(vType,''), ', prefijo: ', IFNULL(vPrefix,''))); RESIGNAL; END; @@ -13174,9 +13175,10 @@ BEGIN FROM vn.sale m JOIN vn.ticket t ON t.id = m.ticketFk JOIN vn.ticketState s ON s.ticketFk = t.id + JOIN vn.alertLevel al ON al.code = 'DELIVERED' WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() AND t.warehouseFk = vWarehouse - AND s.alertLevel = 3 + AND s.alertLevel = al.id ) t GROUP BY itemFk HAVING quantity > 0; @@ -13208,7 +13210,7 @@ BEGIN IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, CEIL(s.quantity / t.packing) etiquetas FROM vn.item i - JOIN `filter` f ON f.itemFk = i.id + JOIN `filter` f ON f.itemFk = i.id JOIN currentStock s ON s.itemFk = i.id LEFT JOIN tmp t ON t.itemFk = i.id LEFT JOIN vn.packaging p ON p.id = t.packagingFk @@ -14618,7 +14620,7 @@ BEGIN END; -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, + SELECT o.date_send, o.address_id, o.note, a.clientFk, o.company_id, o.agency_id, c.isTaxDataChecked INTO vDelivery, vAddress, vNotes, vClientId, vCompanyId, vAgencyModeId, vIsTaxDataChecked @@ -14677,6 +14679,7 @@ BEGIN ) SELECT t.id INTO vTicket FROM vn.ticket t + JOIN vn.alertLevel al ON al.code = 'FREE' LEFT JOIN tPrevia tp ON tp.ticketFk = t.id LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id JOIN hedera.`order` o @@ -14687,7 +14690,7 @@ BEGIN WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL - AND IFNULL(tls.alertLevel,0) = 0 + AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) LIMIT 1; -- Crea el ticket en el caso de no existir uno adecuado @@ -17013,6 +17016,22 @@ SET character_set_client = utf8; 1 AS `companyFk` */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `clientSupplier` +-- + +DROP TABLE IF EXISTS `clientSupplier`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `clientSupplier` ( + `companyFk` smallint(6) NOT NULL, + `type` enum('C','P') NOT NULL, + `idClientSupplier` int(11) NOT NULL, + `isSync` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`companyFk`,`idClientSupplier`,`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Clients and suppliers present in Sage and their synchronization status'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `clientesProveedores` -- @@ -17596,7 +17615,8 @@ BEGIN DECLARE vTransactionExportTaxFreeFk INT; DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; DECLARE vInvoiceTypeInformativeCode VARCHAR(1); - DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2) ; + DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); + DECLARE vCompanyCode INT; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -17606,9 +17626,6 @@ BEGIN FROM Naciones WHERE Nacion ='CEUTA Y MELILLA'; - SELECT pendingServiceTransactionTypeFk INTO vDuaTransactionFk - FROM config; - SELECT id INTO vTaxImportFk FROM taxType WHERE code = 'import21'; @@ -17621,10 +17638,14 @@ BEGIN FROM taxType WHERE code = 'import4'; - SELECT definitiveExportTransactionTypeFk INTO vTransactionExportFk - FROM config; - - SELECT shipmentTransactionTypeFk INTO vTransactionExportTaxFreeFk + SELECT shipmentTransactionTypeFk, + definitiveExportTransactionTypeFk, + pendingServiceTransactionTypeFk, + company_getCode(vCompanyFk) + INTO vTransactionExportTaxFreeFk, + vTransactionExportFk, + vDuaTransactionFk, + vCompanyCode FROM config; SELECT codeSage INTO vInvoiceTypeInformativeCode @@ -17639,8 +17660,6 @@ BEGIN WHERE enlazadoSage = FALSE AND Asiento <> 1 ; - CALL clientSupplier_add(vCompanyFk); - CALL pgc_add(vCompanyFk); CALL invoiceOut_manager(vYear, vCompanyFk); CALL invoiceIn_manager(vYear, vCompanyFk); @@ -17733,7 +17752,7 @@ BEGIN ) SELECT 'EN' TipoEntrada, YEAR(x.FECHA) Ejercicio, - company_getCode(vCompanyFk) AS CodigoEmpresa, + vCompanyCode CodigoEmpresa, x.ASIEN Asiento, IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL), 'D', 'H') CargoAbono, @@ -17866,20 +17885,6 @@ BEGIN WHERE m.CargoAbono = 'D' AND m.enlazadoSage = FALSE; --- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación - DELETE cp - FROM clientesProveedores cp - LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - --- Elimina cuentas contables que no se utilizarán en la importación - DELETE pc - FROM planCuentasPGC pc - LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - -- DUAS UPDATE movConta mci JOIN vn.XDiario x ON x.ASIEN = mci.Asiento @@ -17986,6 +17991,56 @@ BEGIN AND importeDivisa > 0 AND ImporteAsiento < 0; + CREATE OR REPLACE TEMPORARY TABLE tmp.clientSupplier + (INDEX(idClientSupplier, `type`)) + ENGINE = MEMORY + WITH client AS( + SELECT DISTINCT c.id + FROM sage.movConta mc + JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta + WHERE NOT enlazadoSage + ),supplier AS( + SELECT DISTINCT s.id + FROM sage.movConta mc + JOIN vn.supplier s ON s.account = mc.CodigoCuenta + WHERE NOT enlazadoSage + ),clientSupplierSync AS( + SELECT idClientSupplier, `type` + FROM sage.clientSupplier cs + WHERE isSync + ) + SELECT idClientSupplier, `type` + FROM sage.clientSupplier cs + WHERE NOT isSync + UNION + SELECT id, 'C' + FROM client c + LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id + AND cs.Type ='C' + WHERE cs.idClientSupplier IS NULL + UNION + SELECT id, 'P' + FROM supplier s + LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id + AND cs.Type ='P' + WHERE cs.idClientSupplier IS NULL; + + CALL clientSupplier_add(vCompanyFk); + + INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) + SELECT vCompanyCode, `type`, idClientSupplier, FALSE + FROM tmp.clientSupplier; + + DROP TEMPORARY TABLE tmp.clientSupplier; + + CALL pgc_add(vCompanyFk); +-- Elimina cuentas contables que no se utilizarán en la importación + DELETE pc + FROM planCuentasPGC pc + LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta + AND mc.enlazadoSage = FALSE + WHERE mc.codigoCuenta IS NULL; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -18027,13 +18082,18 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `clientSupplier_add`(vCompanyFk INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `clientSupplier_add`( + vCompanyFk INT +) BEGIN /** - * Prepara los datos de clientes y proveedores para exportarlos a Sage - * @vCompanyFk Empresa dela que se quiere trasladar datos + * Inserta en la tabla sage.clientesProveedores los datos de clientes y proveedores + * que se actualizaran o se daran de alta en Sage + * @vCompanyFk Id de empresa + * @table tmp.clientSupplier(idClientSupplier, `type`) */ DECLARE vCountryCeutaMelillaFk INT; + DECLARE vCompanyCode INT DEFAULT company_getCode(vCompanyFk); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); SELECT SiglaNacion INTO vCountryCanariasCode @@ -18073,7 +18133,7 @@ BEGIN Email1, iban) SELECT - company_getCode(vCompanyFk), + vCompanyCode, 'C', c.id, c.socialName, @@ -18081,7 +18141,7 @@ BEGIN IFNULL(c.street, ''), c.accountingAccount, @fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)), - IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)), + IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)), IFNULL(c.postcode, ''), IFNULL(c.city, ''), IFNULL(pr.CodigoProvincia, ''), @@ -18103,15 +18163,14 @@ BEGIN IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''), IFNULL(c.iban, '') FROM vn.`client` c - JOIN clientLastTwoMonths clm ON clm.clientFk = c.id + JOIN tmp.clientSupplier cs ON cs.idClientSupplier = c.id LEFT JOIN vn.country cu ON cu.id = c.countryFk LEFT JOIN Naciones n ON n.countryFk = cu.id LEFT JOIN vn.province p ON p.id = c.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id - WHERE c.isRelevant - AND clm.companyFk = vCompanyFk + WHERE cs.type = 'C' UNION ALL - SELECT company_getCode(vCompanyFk), + SELECT vCompanyCode, 'P', s.id, s.name, @@ -18135,19 +18194,17 @@ BEGIN IFNULL(s.transactionTypeSageFk, 0), IFNULL(s.withholdingSageFk, '0'), IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''), - IFNULL(iban, '') + IFNULL(sa.iban, '') FROM vn.supplier s - JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id + JOIN tmp.clientSupplier cs ON cs.idClientSupplier = s.id LEFT JOIN vn.country co ON co.id = s.countryFk LEFT JOIN Naciones n ON n.countryFk = co.id LEFT JOIN vn.province p ON p.id = s.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - WHERE pl.companyFk = vCompanyFk AND - s.isActive AND - s.nif <> '' - GROUP BY pl.supplierFk, pl.companyFk; + WHERE cs.type = 'P' + GROUP BY s.id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -20439,7 +20496,7 @@ BEGIN LEFT JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk LEFT JOIN vn.routesMonitor rm ON t.routeFk = rm.routeFk - LEFT JOIN vn.roadmapStop rs ON rm.expeditionTruckFk = rs.id + LEFT JOIN vn.roadmapStop rs ON rm.roadmapStopFk = rs.id WHERE e.id = vExpeditionFk; RETURN vDayMinute; @@ -23592,12 +23649,13 @@ BEGIN m.created, TIMESTAMPADD(DAY, tp.life, t.shipped) expired, m.quantity < 0 isIn, - m.isPicked OR s.alertLevel > 1 isPicked + m.isPicked OR s.alertLevel > al.id isPicked FROM vn.sale m JOIN vn.ticket t ON t.id = m.ticketFk JOIN vn.ticketState s ON s.ticketFk = t.id JOIN vn.item i ON i.id = m.itemFk JOIN vn.itemType tp ON tp.id = i.typeFk + JOIN vn.alertLevel al ON al.code = 'ON_PREPARATION' WHERE ( vTableId IS NULL OR (vTableName = 'ticket' AND t.id = vTableId) @@ -25637,7 +25695,10 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `debugAdd`(vVariable VARCHAR(255), vValue VARCHAR(255)) +CREATE DEFINER=`root`@`localhost` PROCEDURE `debugAdd`( + vVariable VARCHAR(255), + vValue TEXT +) MODIFIES SQL DATA BEGIN /** @@ -28592,7 +28653,7 @@ CREATE TABLE `clientLog` ( `action` set('insert','update','delete') NOT NULL, `creationDate` timestamp NULL DEFAULT current_timestamp(), `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `changedModel` enum('Client','Address','ClientContact','ClientDms','ClientObservation','ClientSample','Greuge','Recovery','TpvTransaction','WorkerDms','Sms') NOT NULL DEFAULT 'Client', + `changedModel` enum('Client','Address','ClientContact','ClientDms','ClientObservation','ClientSample','ClientUnpaid','Greuge','Recovery','TpvTransaction','WorkerDms','Sms') NOT NULL DEFAULT 'Client', `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), `changedModelId` int(11) NOT NULL, @@ -28706,6 +28767,24 @@ CREATE TABLE `clientProtected` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de clientes y comerciales que no se van a ver afectados por las desagsignaciones mensuales automaticas'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `clientRate` +-- + +DROP TABLE IF EXISTS `clientRate`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `clientRate` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `clientFk` int(11) NOT NULL, + `dated` date NOT NULL DEFAULT current_timestamp(), + `value` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `clientRate_unique` (`clientFk`,`dated`), + CONSTRAINT `clientRate_client_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `clientRisk` -- @@ -29567,7 +29646,6 @@ CREATE TABLE `country` ( `continentFk` tinyint(4) DEFAULT NULL, `a3Code` int(11) DEFAULT NULL COMMENT 'Código país para a3', `isSocialNameUnique` tinyint(1) NOT NULL DEFAULT 1, - `country` varchar(25) GENERATED ALWAYS AS (`name`) VIRTUAL, PRIMARY KEY (`id`), UNIQUE KEY `country_unique` (`code`), KEY `Id_Paisreal` (`politicalCountryFk__`), @@ -31063,7 +31141,7 @@ SET character_set_client = utf8; 1 AS `routeFk`, 1 AS `scanFk`, 1 AS `expeditionFk`, - 1 AS `expeditionTruckFk`, + 1 AS `roadmapStopFk`, 1 AS `warehouseFk`, 1 AS `lastPacked`, 1 AS `ticketFk` */; @@ -31233,6 +31311,7 @@ CREATE TABLE `expeditionState` ( `expeditionFk` int(11) NOT NULL, `typeFk` int(11) NOT NULL, `userFk` int(11) DEFAULT NULL, + `isScanned` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), KEY `expeditionState_FK` (`expeditionFk`), KEY `expeditionState_FK_1` (`typeFk`), @@ -31324,7 +31403,6 @@ SET character_set_client = utf8; /*!50001 CREATE VIEW `expeditionTruck` AS SELECT 1 AS `id`, 1 AS `roadmapFk`, - 1 AS `warehouseFk`, 1 AS `eta`, 1 AS `description`, 1 AS `bufferFk`, @@ -31332,68 +31410,6 @@ SET character_set_client = utf8; 1 AS `userFk` */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `expeditionTruck_Control` --- - -DROP TABLE IF EXISTS `expeditionTruck_Control`; -/*!50001 DROP VIEW IF EXISTS `expeditionTruck_Control`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `expeditionTruck_Control` AS SELECT - 1 AS `id`, - 1 AS `ETD`, - 1 AS `description`, - 1 AS `ticketsSinBultos`, - 1 AS `pallets`, - 1 AS `routes`, - 1 AS `scans`, - 1 AS `expeditions`, - 1 AS `fallos`, - 1 AS `lastPacked` */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `expeditionTruck_Control_Detail` --- - -DROP TABLE IF EXISTS `expeditionTruck_Control_Detail`; -/*!50001 DROP VIEW IF EXISTS `expeditionTruck_Control_Detail`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `expeditionTruck_Control_Detail` AS SELECT - 1 AS `id`, - 1 AS `eta`, - 1 AS `destino`, - 1 AS `pallet`, - 1 AS `routes`, - 1 AS `scans`, - 1 AS `destinos`, - 1 AS `fallos`, - 1 AS `lastPacked` */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `expeditionTruck_Control_Detail_Pallet` --- - -DROP TABLE IF EXISTS `expeditionTruck_Control_Detail_Pallet`; -/*!50001 DROP VIEW IF EXISTS `expeditionTruck_Control_Detail_Pallet`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `expeditionTruck_Control_Detail_Pallet` AS SELECT - 1 AS `id`, - 1 AS `eta`, - 1 AS `destino`, - 1 AS `pallet`, - 1 AS `route`, - 1 AS `scans`, - 1 AS `destinos`, - 1 AS `fallos`, - 1 AS `expeditionTruckFk`, - 1 AS `lastPacked` */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `expense` -- @@ -31628,13 +31644,13 @@ CREATE TABLE `floramondoConfig` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `forecastedBalance` +-- Table structure for table `forecastedBalance__` -- -DROP TABLE IF EXISTS `forecastedBalance`; +DROP TABLE IF EXISTS `forecastedBalance__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `forecastedBalance` ( +CREATE TABLE `forecastedBalance__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) DEFAULT NULL, `amount` double NOT NULL DEFAULT 0, @@ -31647,7 +31663,7 @@ CREATE TABLE `forecastedBalance` ( KEY `empresa_prevision_idx` (`companyFk`), CONSTRAINT `Saldos_PrevisionCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `banco_prevision` FOREIGN KEY (`accountingFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='@deprecated 2024-05-21'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33197,11 +33213,11 @@ CREATE TABLE `itemShelving` ( `buyFk` int(11) DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `itemShelving_UN` (`buyFk`,`shelvingFk`), KEY `itemShelving_fk1_idx` (`itemFk`), KEY `itemShelving_fk2_idx` (`shelvingFk`), KEY `itemShelving_fk3_idx` (`packagingFk`), KEY `itemShelving_fk3_idx1` (`userFk`), + KEY `itemShelvingBuy_FK` (`buyFk`), CONSTRAINT `itemShelvingBuy_FK` FOREIGN KEY (`buyFk`) REFERENCES `buy` (`id`), CONSTRAINT `itemShelving_fk1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelving_fk2` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -35804,13 +35820,20 @@ CREATE TABLE `productionConfig` ( `defaultSectorFk` int(10) unsigned NOT NULL DEFAULT 37 COMMENT 'Default sector', `scannableCodeType` enum('qr','barcode') NOT NULL DEFAULT 'barcode', `scannablePreviusCodeType` enum('qr','barcode') NOT NULL DEFAULT 'barcode', + `itemOlderReviewHours` int(11) NOT NULL DEFAULT 0 COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.', + `sectorFromCode` varchar(15) DEFAULT NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear', + `sectorToCode` varchar(15) DEFAULT NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear', PRIMARY KEY (`id`), KEY `productionConfig_FK` (`shortageAddressFk`), KEY `productionConfig_FK_1` (`clientSelfConsumptionFk`), KEY `productionConfig_FK_2` (`addressSelfConsumptionFk`), + KEY `productionConfig_sector_FK` (`sectorFromCode`), + KEY `productionConfig_sector_FK_1` (`sectorToCode`), CONSTRAINT `productionConfig_FK` FOREIGN KEY (`shortageAddressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, CONSTRAINT `productionConfig_FK_1` FOREIGN KEY (`clientSelfConsumptionFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `productionConfig_FK_2` FOREIGN KEY (`addressSelfConsumptionFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, + CONSTRAINT `productionConfig_sector_FK` FOREIGN KEY (`sectorFromCode`) REFERENCES `sector` (`code`) ON UPDATE CASCADE, + CONSTRAINT `productionConfig_sector_FK_1` FOREIGN KEY (`sectorToCode`) REFERENCES `sector` (`code`) ON UPDATE CASCADE, CONSTRAINT `productionConfig_check` CHECK (`id` = 1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los parámetros que condicionan la producción'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -36473,6 +36496,21 @@ CREATE TABLE `roadmap` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Troncales diarios que se contratan'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `roadmapAddress` +-- + +DROP TABLE IF EXISTS `roadmapAddress`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `roadmapAddress` ( + `addressFk` int(11) NOT NULL, + `isActive` tinyint(4) DEFAULT 1, + PRIMARY KEY (`addressFk`), + CONSTRAINT `roadmapAddress_address_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Direcciones de los troncales'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `roadmapStop` -- @@ -36483,7 +36521,7 @@ DROP TABLE IF EXISTS `roadmapStop`; CREATE TABLE `roadmapStop` ( `id` int(11) NOT NULL AUTO_INCREMENT, `roadmapFk` int(10) unsigned DEFAULT NULL, - `warehouseFk` smallint(6) unsigned DEFAULT NULL, + `addressFk` int(11) DEFAULT NULL, `eta` datetime DEFAULT NULL COMMENT 'Estimated time of arrival', `description` varchar(45) NOT NULL, `bufferFk` int(11) DEFAULT NULL COMMENT 'buffer destino de las cajas', @@ -36492,13 +36530,13 @@ CREATE TABLE `roadmapStop` ( PRIMARY KEY (`id`), KEY `expeditionTruck_idx1` (`eta`), KEY `expeditionTruck_FK` (`bufferFk`), - KEY `expeditionTruck_FK_1` (`warehouseFk`), KEY `expeditionTruck_FK_2` (`roadmapFk`), KEY `expeditionTruck_FK_3` (`userFk`), + KEY `roadmapStop_roadmapAddress_FK` (`addressFk`), CONSTRAINT `expeditionTruck_FK` FOREIGN KEY (`bufferFk`) REFERENCES `srt`.`buffer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `expeditionTruck_FK_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `expeditionTruck_FK_2` FOREIGN KEY (`roadmapFk`) REFERENCES `roadmap` (`id`) ON UPDATE CASCADE, - CONSTRAINT `expeditionTruck_FK_3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE + CONSTRAINT `expeditionTruck_FK_3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, + CONSTRAINT `roadmapStop_roadmapAddress_FK` FOREIGN KEY (`addressFk`) REFERENCES `roadmapAddress` (`addressFk`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Distintas paradas que hacen los trocales'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -36872,21 +36910,22 @@ CREATE TABLE `routesMonitor` ( `m3` decimal(10,1) DEFAULT NULL, `priority` int(11) NOT NULL DEFAULT 0, `etd` time DEFAULT NULL, - `expeditionTruckFk` int(11) DEFAULT NULL, + `roadmapStopFk` int(11) DEFAULT NULL, `m3boxes` decimal(10,1) DEFAULT NULL, `bufferFk` int(11) DEFAULT NULL COMMENT 'Buffer del sorter por el que se quiere sacar esa ruta', `isPickingAllowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Los tickets de esta ruta se pueden preparar', `editorFk` int(10) unsigned DEFAULT NULL, + `expeditionTruckFk` int(11) GENERATED ALWAYS AS (`roadmapStopFk`) VIRTUAL, PRIMARY KEY (`routeFk`), KEY `routesMonitor_FK` (`bufferFk`), KEY `routesMonitor_FK_2` (`beachFk`), KEY `routesMonitor_FK_1` (`dockFk`), - KEY `routesMonitor_FK_3` (`expeditionTruckFk`), + KEY `routesMonitor_FK_3` (`roadmapStopFk`), KEY `routesMonitor_fk_editor` (`editorFk`), CONSTRAINT `routesMonitor_FK` FOREIGN KEY (`bufferFk`) REFERENCES `srt`.`buffer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `routesMonitor_FK_1` FOREIGN KEY (`dockFk`) REFERENCES `dock` (`code`) ON UPDATE CASCADE, CONSTRAINT `routesMonitor_FK_2` FOREIGN KEY (`beachFk`) REFERENCES `beach` (`code`) ON UPDATE CASCADE, - CONSTRAINT `routesMonitor_FK_3` FOREIGN KEY (`expeditionTruckFk`) REFERENCES `roadmapStop` (`id`) ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_FK_3` FOREIGN KEY (`roadmapStopFk`) REFERENCES `roadmapStop` (`id`) ON UPDATE CASCADE, CONSTRAINT `routesMonitor_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -39160,7 +39199,7 @@ CREATE TABLE `ticketPackagingStartingStock` ( KEY `ticketPackagingStartingStock_fk2_idx` (`packagingFk`), KEY `ticketPackagingStartingStock_fk3_idx` (`itemFk`), CONSTRAINT `ticketPackagingStartingStock_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `ticketPackagingStartingStock_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `ticketPackagingStartingStock_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE, CONSTRAINT `ticketPackagingStartingStock_fk3` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -39879,6 +39918,20 @@ CREATE TABLE `travelConfig` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `travelKgPercentage` +-- + +DROP TABLE IF EXISTS `travelKgPercentage`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `travelKgPercentage` ( + `value` int(3) NOT NULL, + `className` varchar(50) DEFAULT NULL, + PRIMARY KEY (`value`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `travelLog` -- @@ -48182,7 +48235,9 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_afterUpsert`(vSelf INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_afterUpsert`( + vSelf INT +) BEGIN /** * Triggered actions when a buy is updated or inserted. @@ -48199,7 +48254,7 @@ BEGIN DECLARE vIsFeedStock BOOL; DECLARE vWeight DECIMAL(10,2); DECLARE vPacking INT; - + SELECT b.entryFk, b.itemFk, i.packingOut, @@ -48230,8 +48285,11 @@ BEGIN WHERE e.id = vEntryFk; IF vIsMerchandise THEN + IF vWarehouse IS NULL THEN + CALL util.throw('The entry does not have travel'); + END IF; - REPLACE itemCost SET + REPLACE itemCost SET itemFk = vItemFk, warehouseFk = vWarehouse, cm3 = buy_getUnitVolume(vSelf), @@ -48257,7 +48315,7 @@ BEGIN WHERE b.id = vSelf; END IF; - CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck + CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck SELECT vSelf id; CALL buy_checkItem(); END ;; @@ -51672,6 +51730,8 @@ BEGIN DECLARE vLockName VARCHAR(215); DECLARE vLockTime INT DEFAULT 30; DECLARE vFreeWagonFk INT; + DECLARE vErrorNumber INT; + DECLARE vErrorMsg TEXT; DECLARE c1 CURSOR FOR SELECT ticketFk, `lines`, m3 @@ -51691,12 +51751,18 @@ BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + GET DIAGNOSTICS CONDITION 1 + vErrorNumber = MYSQL_ERRNO, + vErrorMsg = MESSAGE_TEXT; + IF vLockName IS NOT NULL THEN DO RELEASE_LOCK(vLockName); - CALL util.debugAdd(JSON_OBJECT( - 'type', 'releaseLock', - 'userFk', vUserFk - ), vLockName); -- Tmp + CALL util.debugAdd('collection_new', JSON_OBJECT( + 'errorNumber', vErrorNumber, + 'errorMsg', vErrorMsg, + 'lockName', vLockName, + 'userFk', vUserFk + )); -- Tmp END IF; RESIGNAL; @@ -52613,7 +52679,7 @@ BEGIN LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN vn.agency a ON a.id = am.agencyFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk JOIN vn.packagingConfig pc WHERE t.warehouseFk IN (60,1,44) AND e.created BETWEEN vStarted AND vEnded @@ -55323,13 +55389,13 @@ BEGIN LIMIT 1; IF vPalletFk IS NULL THEN - SELECT expeditionTruckFk + SELECT roadmapStopFk INTO vTruckFk FROM ( - SELECT rm.expeditionTruckFk, count(*) n + SELECT rm.roadmapStopFk, count(*) n FROM vn.routesMonitor rm JOIN tExpedition e ON e.routeFk = rm.routeFk - GROUP BY expeditionTruckFk + GROUP BY roadmapStopFk ORDER BY n DESC LIMIT 1) sub; @@ -55795,53 +55861,6 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `expeditionTruck_Add` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionTruck_Add`(vHour VARCHAR(5), vDescription VARCHAR(45)) -BEGIN - - INSERT INTO vn.roadmapStop(eta,description) - VALUES(CONCAT(util.VN_CURDATE(), ' ', vHour), vDescription); - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `expeditionTruck_List` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionTruck_List`() -BEGIN - - SELECT id truckFk, - eta, - description Destino - FROM roadmapStop - WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - ORDER BY eta; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expedition_getFromRoute` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -55866,7 +55885,8 @@ BEGIN t.addressFk, a.nickname, sub2.itemPackingTypeConcat, - est.code + est.code, + es.isScanned FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = e.ticketFk @@ -55884,6 +55904,10 @@ BEGIN GROUP BY sub.ticketFk ) sub2 ON sub2.ticketFk = t.id LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk + LEFT JOIN expeditionState es ON es.id = ( + SELECT MAX(id) + FROM expeditionState es + WHERE expeditionFk = e.id) WHERE t.routeFk = vRouteFk AND e.freightItemFk <> FALSE ORDER BY r.created, t.priority DESC; END ;; @@ -55953,7 +55977,7 @@ BEGIN LEFT JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk WHERE e.id = vExpeditionFk; END ;; @@ -56040,7 +56064,7 @@ BEGIN LEFT JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk WHERE e.id = vExpeditionFk; END ;; @@ -58276,8 +58300,8 @@ BEGIN OR t.isDeleted OR c.hasToInvoice = FALSE OR itc.id IS NULL - OR a.id IS NULL - OR (vTaxArea = 'WORLD' + OR a.id IS NULL + OR (vTaxArea = 'WORLD' AND (a.customsAgentFk IS NULL OR a.incotermsFk IS NULL)); SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 @@ -58349,7 +58373,9 @@ BEGIN FROM tmp.ticketToInvoice ti LEFT JOIN ticketState ts ON ti.id = ts.ticketFk JOIN state s - WHERE IFNULL(ts.alertLevel, 0) < 3 and s.`code` = getAlert3State(ti.id); + JOIN alertLevel al ON al.code = 'DELIVERED' + WHERE (ts.alertLevel IS NULL OR ts.alertLevel < al.id) + AND s.`code` = getAlert3State(ti.id); INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT * FROM tmp.updateInter; @@ -59438,7 +59464,7 @@ BEGIN ish.isChecked, sub.isAllChecked FROM itemShelvingStock iss - JOIN itemShelving ish ON ish.shelvingFk = iss.shelvingFk + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN ( SELECT itemFk, IF( @@ -60138,9 +60164,16 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`( + vShelvingFk VARCHAR(8), + vBarcode VARCHAR(22), + vQuantity INT, + vPackagingFk VARCHAR(10), + vGrouping INT, + vPacking INT, + vWarehouseFk INT +) BEGIN - /** * Añade registro o lo actualiza si ya existe. * @@ -60162,12 +60195,7 @@ BEGIN SELECT barcodeToItem(vBarcode) INTO vItemFk; IF vBuyFk IS NULL THEN - CALL cache.last_buy_refresh(FALSE); - - SELECT buy_id INTO vBuyFk - FROM cache.last_buy - WHERE item_id = vItemFk - AND warehouse_id = vWarehouseFk; + CALL util.throw('The buy is required'); END IF; IF vPacking IS NULL @@ -62827,6 +62855,7 @@ BEGIN FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + AND t.warehouseFk AND s.quantity != 0 AND (vItemFk IS NULL OR s.itemFk = vItemFk) AND (vWarehouseFk IS NULL OR t.warehouseFk = vWarehouseFk) @@ -62837,7 +62866,7 @@ BEGIN t.warehouseInFk FROM buy b JOIN entry e ON e.id = b.entryFk - LEFT JOIN travel t ON t.id = e.travelFk + JOIN travel t ON t.id = e.travelFk WHERE t.landed BETWEEN vDatedFrom AND vDatedTo AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) AND !e.isExcludedFromAvailable @@ -62850,7 +62879,7 @@ BEGIN t.warehouseOutFk FROM buy b JOIN entry e ON e.id = b.entryFk - LEFT JOIN travel t ON t.id = e.travelFk + JOIN travel t ON t.id = e.travelFk WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk) AND !e.isExcludedFromAvailable @@ -63601,6 +63630,239 @@ BEGIN */ UPDATE item SET itemPackingTypeFk = vItemPackingTypeFk WHERE id = vItem; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_valuateInventory` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_valuateInventory`( +vDated DATE +) +BEGIN +DECLARE vInventoried DATE; +DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE; +DECLARE vInventoryClone DATE; +DECLARE vDateDayEnd DATETIME; +DECLARE vInventorySupplierFk INT; + +SELECT inventorySupplierFk INTO vInventorySupplierFk +FROM entryConfig; + +SET vDateDayEnd = util.dayEnd(vDated); + +SELECT tr.landed INTO vInventoried +FROM travel tr +JOIN `entry` e ON e.travelFk = tr.id +WHERE tr.landed <= vDateDayEnd +AND e.supplierFk = vInventorySupplierFk +ORDER BY tr.landed DESC +LIMIT 1; + +SET vHasNotInventory = (vInventoried IS NULL); + +IF vHasNotInventory THEN +SELECT landed INTO vInventoryClone +FROM travel tr +JOIN `entry` e ON e.travelFk = tr.id +WHERE tr.landed >= vDated +AND e.supplierFk = vInventorySupplierFk +ORDER BY landed ASC +LIMIT 1; + +SET vInventoried = vDated + INTERVAL 1 DAY; +SET vDateDayEnd = vInventoryClone; +END IF; + +CREATE OR REPLACE TEMPORARY TABLE tInventory( +warehouseFk SMALLINT, +itemFk BIGINT, +quantity INT, +volume DECIMAL(10,2), +cost DOUBLE DEFAULT 0, +total DOUBLE DEFAULT 0, +warehouseInventory VARCHAR(20), +PRIMARY KEY (warehouseInventory, itemFk) USING HASH +) +ENGINE = MEMORY; + + +IF vHasNotInventory THEN +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT tr.warehouseInFk, +b.itemFk, +SUM(b.quantity), +w.name +FROM buy b +JOIN item i ON i.id = b.itemFk +JOIN `entry` e ON e.id = b.entryFk +JOIN travel tr ON tr.id = e.travelFk +JOIN itemType t ON t.id = i.typeFk +JOIN warehouse w ON w.id = tr.warehouseInFk +WHERE tr.landed = vDateDayEnd +AND e.supplierFk = vInventorySupplierFk +AND w.valuatedInventory +AND t.isInventory +GROUP BY tr.warehouseInFk, b.itemFk; +ELSE +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT tr.warehouseInFk, +b.itemFk, +SUM(b.quantity), +w.name +FROM buy b +JOIN item i ON i.id = b.itemFk +JOIN `entry` e ON e.id = b.entryFk +JOIN travel tr ON tr.id = e.travelFk +JOIN itemType t ON t.id = i.typeFk +JOIN warehouse w ON w.id = tr.warehouseInFk +WHERE tr.landed = vInventoried +AND e.supplierFk = vInventorySupplierFk +AND w.valuatedInventory +AND t.isInventory +GROUP BY tr.warehouseInFk, b.itemFk; +END IF; + + +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT tr.warehouseInFk, +b.itemFk, +b.quantity * IF(vHasNotInventory, -1, 1), +w.name +FROM buy b +JOIN item i ON i.id = b.itemFk +JOIN `entry` e ON e.id = b.entryFk +JOIN travel tr ON tr.id = e.travelFk +JOIN itemType t ON t.id = i.typeFk +JOIN warehouse w ON w.id = tr.warehouseInFk +WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd +AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE) +AND NOT e.isRaid +AND w.valuatedInventory +AND t.isInventory +AND e.supplierFk <> vInventorySupplierFk +ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory, -1, 1)); + + +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT tr.warehouseOutFk, +b.itemFk, +b.quantity * IF(vHasNotInventory, 1, -1), +w.name +FROM buy b +JOIN item i ON i.id = b.itemFk +JOIN `entry` e ON e.id = b.entryFk +JOIN travel tr ON tr.id = e.travelFk +JOIN itemType t ON t.id = i.typeFk +JOIN warehouse w ON w.id = tr.warehouseOutFk +WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd +AND NOT e.isRaid +AND w.valuatedInventory +AND t.isInventory +ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory,1,-1)); + + +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT w.id, +s.itemFk, +s.quantity * IF(vHasNotInventory, 1, -1), +w.name +FROM sale s +JOIN ticket t ON t.id = s.ticketFk +JOIN `client` c ON c.id = t.clientFk +JOIN item i ON i.id = s.itemFk +JOIN itemType it ON it.id = i.typeFk +JOIN warehouse w ON w.id = t.warehouseFk +WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd +AND w.valuatedInventory +AND it.isInventory +ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 1, -1); + + +IF vDated = util.VN_CURDATE() THEN +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT w.id, +s.itemFk, +s.quantity * IF(vHasNotInventory, 0, 1), +w.name +FROM sale s +JOIN ticket t ON t.id = s.ticketFk +JOIN `client` c ON c.id = t.clientFk +JOIN item i ON i.id = s.itemFk +JOIN itemType it ON it.id = i.typeFk +JOIN warehouse w ON w.id = t.warehouseFk +WHERE t.shipped BETWEEN vDated AND vDateDayEnd +AND NOT (s.isPicked OR t.isLabeled) +AND w.valuatedInventory +AND it.isInventory +ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 0, 1); +END IF; + + +INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) +SELECT tr.warehouseInFk, +b.itemFk, +b.quantity, +CONCAT(wOut.`name`, ' - ', wIn.`name`) +FROM buy b +JOIN item i ON i.id = b.itemFk +JOIN `entry` e ON e.id = b.entryFk +JOIN travel tr ON tr.id = e.travelFk +JOIN itemType t ON t.id = i.typeFk +JOIN warehouse wIn ON wIn.id = tr.warehouseInFk +JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk +WHERE vDated >= tr.shipped AND vDated < tr.landed +AND NOT isRaid +AND wIn.valuatedInventory +AND t.isInventory +AND e.isConfirmed +ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity); + +CALL buyUltimate(NULL, vDateDayEnd); + +DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity; + +UPDATE tInventory i +JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk +JOIN buy b ON b.id = bu.buyFk +LEFT JOIN itemCost ic ON ic.itemFk = i.itemFk +AND ic.warehouseFk = i.warehouseFk +SET i.total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)), +i.cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0), +i.volume = i.quantity * ic.cm3delivery / 1000000; + +SELECT ti.warehouseFk, +i.id, +i.longName, +i.size, +ti.quantity, +ti.volume, +tp.name itemTypeName, +ic.name itemCategoryName, +ti.cost, +ti.total, +ti.warehouseInventory +FROM tInventory ti +JOIN warehouse w ON w.id = warehouseFk +JOIN item i ON i.id = ti.itemFk +JOIN itemType tp ON tp.id = i.typeFk +JOIN itemCategory ic ON ic.id = tp.categoryFk +WHERE w.valuatedInventory +AND ti.total > 0; + +DROP TEMPORARY TABLE +tmp.buyUltimate, +tInventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65248,14 +65510,16 @@ BEGIN (PRIMARY KEY (ticketFk)) ENGINE = MEMORY SELECT t.id ticketFk, t.clientFk - FROM vn.ticket t - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.client c ON c.id = t.clientFk + FROM ticket t + JOIN alertLevel al ON al.code = 'DELIVERED' + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + JOIN client c ON c.id = t.clientFk + WHERE c.typeFk IN ('normal','handMaking','internalUse') AND ( t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate OR ( - ts.alertLevel < 3 + ts.alertLevel < al.id AND t.shipped >= vStartingDate AND t.shipped < util.VN_CURDATE() ) @@ -65383,7 +65647,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `productionControl`( - vWarehouseFk INT, + vWarehouseFk INT, vScopeDays INT ) proc: BEGIN @@ -65450,7 +65714,7 @@ proc: BEGIN wk.code salesPersonCode, p.id provinceFk, tls.productionOrder, - IFNULL(tls.alertLevel, 0) alertLevel, + IFNULL(tls.alertLevel, al.id) alertLevel, t.isBoxed palletized, IF(rm.isPickingAllowed, rm.bufferFk, NULL) ubicacion, tlu.lastUpdated, @@ -65464,6 +65728,7 @@ proc: BEGIN rm.bufferFk FROM tmp.productionTicket tt JOIN ticket t ON tt.ticketFk = t.id + JOIN alertLevel al ON al.code = 'FREE' LEFT JOIN ticketStateToday tst ON tst.ticketFk = t.id LEFT JOIN `state` st ON st.id = tst.state LEFT JOIN client c ON c.id = t.clientFk @@ -65484,7 +65749,7 @@ proc: BEGIN LEFT JOIN parking pk ON pk.id = tp.parkingFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); - + UPDATE tmp.productionBuffer pb JOIN ( SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking @@ -65492,12 +65757,12 @@ proc: BEGIN JOIN sale s ON s.ticketFk = pb.ticketFk JOIN saleGroupDetail sgd ON sgd.saleFk = s.id JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - JOIN parking p ON p.id = sg.parkingFk + JOIN parking p ON p.id = sg.parkingFk GROUP BY pb.ticketFk ) t ON t.ticketFk = pb.ticketFk SET pb.previaParking = t.previaParking; - -- Problemas por ticket + -- Problemas por ticket ALTER TABLE tmp.productionBuffer CHANGE COLUMN `problem` `problem` VARCHAR(255), ADD COLUMN `collectionH` INT, @@ -66406,7 +66671,7 @@ BEGIN LEFT JOIN ticketTrolley tt ON tt.ticket = t.id LEFT JOIN zone zo ON t.zoneFk = zo.id LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN roadmapStop rs ON rs.id = rm.roadmapStopFk WHERE IF(vIsCollection, tc.collectionFk = vParam, tc.ticketFk = vParam) GROUP BY t.id ORDER BY cc.code; @@ -66708,7 +66973,7 @@ BEGIN SET rm.m3boxes = sub.m3boxes; UPDATE routesMonitor rm - JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk SET rm.etd = rs.eta; DROP TEMPORARY TABLE tmp.routesMonitor; @@ -70065,10 +70330,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `supplierPackaging_ReportSource`( ) BEGIN /** -* Selecciona los embalajes de un proveedor a partir de una fecha +* Create a report with packaging balance * -* @param vFromDated Fecha de la que partir -* @param vSupplierFk Id del proveedor +* @param vFromDated Starting date +* @param vSupplierFk Supplier ID */ SET @vBalance = 0; SET @vItemFk = NULL; @@ -70082,7 +70347,7 @@ BEGIN landed, `in`, `out`, - warehouse, + sref, buyingValue, IF ( NOT (@vItemFk <=> sub.itemFk), @@ -70091,19 +70356,20 @@ BEGIN ) balance, @vItemFk := sub.itemFk previousItemFk FROM ( - SELECT supplierFk, - itemFk, - longName, - supplier, - CONCAT('E',entryFk) entryFk, - landed, - `in`, - `out`, - warehouse, - buyingValue - FROM supplierPackaging - WHERE supplierFk = vSupplierFk - AND landed >= vFromDated + SELECT sp.supplierFk, + sp.itemFk, + sp.longName, + sp.supplier, + CONCAT('E',sp.entryFk) entryFk, + sp.landed, + sp.`in`, + sp.`out`, + e.invoiceNumber sref, + sp.buyingValue + FROM supplierPackaging sp + JOIN entry e ON e.id = sp.entryFk + WHERE sp.supplierFk = vSupplierFk + AND sp.landed >= vFromDated UNION ALL SELECT vSupplierFk, itemFk, @@ -70128,7 +70394,7 @@ BEGIN DATE(t.shipped), -LEAST(s.quantity,0) `in`, GREATEST(s.quantity,0) `out`, - t.warehouseFk, + t.cmrFk, s.price * (100 - s.discount) / 100 FROM sale s JOIN item i ON i.id = s.itemFk @@ -70159,6 +70425,7 @@ BEGIN WHERE su.id = vSupplierFk AND t.shipped < vFromDated AND p.isPackageReturnable + AND NOT t.isDeleted GROUP BY s.itemFk UNION ALL SELECT vSupplierFk, @@ -70169,7 +70436,7 @@ BEGIN DATE(t.shipped), -LEAST(tp.quantity,0) `in`, GREATEST(tp.quantity,0) `out`, - t.warehouseFk, + t.cmrFk, 0 FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk @@ -70198,8 +70465,9 @@ BEGIN JOIN client c ON c.id = t.clientFk JOIN supplier su ON su.nif = c.fi WHERE su.id = vSupplierFk - AND t.shipped >= vFromDated + AND t.shipped < vFromDated AND p.isPackageReturnable + AND NOT t.isDeleted GROUP BY p.itemFk ORDER BY itemFk, landed, entryFk ) sub @@ -70213,7 +70481,7 @@ BEGIN landed, CAST(`in` AS DECIMAL(10,0)) `in`, CAST(`out` AS DECIMAL(10,0)) `out`, - warehouse, + sref, buyingValue, balance FROM tSupplierPackaging @@ -71253,13 +71521,16 @@ BEGIN DECLARE vShipped DATE; DECLARE vWarehouse TINYINT; DECLARE vAlertLevel INT; + DECLARE vAlertLevelFree INT; - SELECT t.warehouseFk, t.shipped, ts.alertLevel INTO vWarehouse, vShipped, vAlertLevel + SELECT t.warehouseFk, t.shipped, ts.alertLevel, al.id + INTO vWarehouse, vShipped, vAlertLevel, vAlertLevelFree FROM ticket t + JOIN alertLevel al ON al.code = 'FREE' LEFT JOIN ticketState ts ON ts.ticketFk = vTicket WHERE t.id = vTicket; - IF vAlertLevel IS NULL OR vAlertLevel = 0 THEN + IF vAlertLevel IS NULL OR vAlertLevel = vAlertLevelFree THEN IF vShipped >= util.VN_CURDATE() THEN CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped); END IF; @@ -71283,68 +71554,6 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketMissed_List` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketMissed_List`(vTicketFk INT) -BEGIN - - DECLARE vParkingFk INT; - DECLARE vParked DATETIME; - DECLARE vLevel INT; - DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) - INTO vLevel, vCollectionFk - FROM vn.ticketCollection - WHERE ticketFk = vTicketFk - LIMIT 1; - - SELECT created, parkingFk - INTO vParked, vParkingFk - FROM vn.ticketParking - WHERE ticketFk = vTicketFk; - - SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia - FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector sc ON sc.id = p.sectorFk - LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.zone z ON z.id = t.zoneFk - JOIN vn.agencyMode am ON am.id = z.agencyModeFk - JOIN vn.state s ON s.id = tst.state - WHERE (s.alertLevel < 2 - AND tp.parkingFk = vParkingFk - AND sc.isPackagingArea - AND ( - ( - ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) - OR - ( tc.collectionFk = vCollectionFk AND LEFT(tc.level,1) < LEFT(vLevel,1) ) - ) - )) -- Etiquetas que no se han escaneado y ya estamos con una posterior - OR - (s.alertLevel > 1 - AND tp.parkingFk = vParkingFk - AND sc.isPackagingArea - AND tp.created < vParked - AND t.packages <=> 0); - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketNotInvoicedByClient` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71585,64 +71794,66 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1)) BEGIN - + /** * Averigua los tickets que se han saltado por un error en el proceso encajado * @param vTicketFk Ticket * @param vItemPackingTypeFk Modo de encajado * @return un select con los tickets afectados - */ + */ DECLARE vParkingFk INT; DECLARE vParked DATETIME; DECLARE vLevel INT; DECLARE vWagon INT; DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) + + SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) INTO vLevel, vWagon, vCollectionFk FROM vn.ticketCollection tc JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk WHERE ticketFk = vTicketFk ORDER BY c.id DESC LIMIT 1; - - SELECT created, parkingFk + + SELECT created, parkingFk INTO vParked, vParkingFk FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk WHERE ticketFk = vTicketFk AND s.itemPackingTypeFk = vItemPackingTypeFk AND s.isPackagingArea ; - + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector sc ON sc.id = p.sectorFk - LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.zone z ON z.id = t.zoneFk - JOIN vn.agencyMode am ON am.id = z.agencyModeFk - JOIN vn.state s ON s.id = tst.state - WHERE (s.alertLevel < 2 + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.zone z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + JOIN vn.state s ON s.id = tst.state + JOIN vn.alertLevel alPacked ON alPacked.code = 'PACKED' + JOIN vn.alertLevel alOnPreparation ON alOnPreparation.code = 'ON_PREPARATION' + WHERE (s.alertLevel < alPacked.id AND tp.parkingFk = vParkingFk AND sc.isPackagingArea AND ( ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) OR - ( tc.collectionFk = vCollectionFk + ( tc.collectionFk = vCollectionFk AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) - OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) + OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) ) ) ) -- Etiquetas que no se han escaneado y ya estamos con una posterior OR - (s.alertLevel > 1 + (s.alertLevel > alOnPreparation.id AND tp.parkingFk = vParkingFk AND sc.isPackagingArea - AND tp.created < vParked + AND tp.created < vParked AND t.packages <=> 0); END ;; DELIMITER ; @@ -71662,64 +71873,28 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN - + /* Modifica el estado de un ticket de hoy - * + * * @param vTicketFk el id del ticket * @param vStateCode estado a modificar del ticket - * + * */ - + DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM state s - JOIN ticketStateToday tst ON tst.state = s.id + DECLARE vAlertLevelPacked INT; + + SELECT s.alertLevel, al.id + INTO vAlertLevel, vAlertLevelPacked + FROM state s + JOIN ticketStateToday tst ON tst.state = s.id + JOIN alertLevel al ON al.code = 'PACKED' WHERE tst.ticketFk = vTicketFk LIMIT 1; - - IF vAlertLevel < 2 THEN - + + IF vAlertLevel < vAlertLevelPacked THEN + CALL vn.ticket_setState(vTicketFk, vStateCode); - - END IF; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketStateUpdate` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) -BEGIN - - /* - * @deprecated:utilizar ticket_setState - */ - - DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM vn.state s - JOIN vn.ticketState ts ON ts.stateFk = s.id - WHERE ts.ticketFk = vTicketFk; - - IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN - - INSERT INTO ticketTracking(stateFk, ticketFk, userFk) - SELECT id, vTicketFk, account.myUser_getId() - FROM vn.state - WHERE `code` = vStateCode collate utf8_unicode_ci; END IF; @@ -73157,10 +73332,11 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticket SELECT ticketFk FROM tmp.productionBuffer + JOIN alertLevel al ON al.code = 'FREE' WHERE shipped = util.VN_CURDATE() AND problem LIKE '%I:%' AND (HH <= vHour OR HH = vHour AND mm < vMinute) - AND alertLevel = 0; + AND alertLevel = al.id; OPEN cur1; @@ -73279,7 +73455,7 @@ BEGIN com.id companyFk, a.id addressFk, c2.defaultAddressFk, - su.id supplierFk, + IFNULL(sat.supplierFk, su.id) supplierFk, t.landed FROM ticket t JOIN ticketState ts ON ts.ticketFk = t.id @@ -73289,15 +73465,18 @@ BEGIN JOIN `address` a ON a.id = t.addressFk JOIN province p ON p.id = a.provinceFk JOIN country co ON co.id = p.countryFk - JOIN agencyMode am ON am.id = t.agencyModeFk JOIN warehouse w ON w.id = t.warehouseFk JOIN company com ON com.id = t.companyFk JOIN client c2 ON c2.id = com.clientFk - JOIN supplierAccount sa ON sa.id = com.supplierAccountFk + JOIN supplierAccount sa ON sa.id = com.supplierAccountFk JOIN supplier su ON su.id = sa.supplierFk LEFT JOIN route r ON r.id = t.routeFk LEFT JOIN worker wo ON wo.id = r.workerFk LEFT JOIN vehicle v ON v.id = r.vehicleFk + LEFT JOIN agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN agency ag ON ag.id = am.agencyFk + LEFT JOIN supplierAgencyTerm sat ON sat.agencyFk = ag.id + AND wo.isFreelance WHERE al.code IN ('PACKED', 'DELIVERED') AND co.code <> 'ES' AND am.name <> 'ABONO' @@ -82100,23 +82279,6 @@ SET character_set_client = utf8; 1 AS `description` */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `Saldos_Prevision` --- - -DROP TABLE IF EXISTS `Saldos_Prevision`; -/*!50001 DROP VIEW IF EXISTS `Saldos_Prevision`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `Saldos_Prevision` AS SELECT - 1 AS `Saldos_Prevision_id`, - 1 AS `Descripcion`, - 1 AS `Importe`, - 1 AS `Fecha`, - 1 AS `Id_Banco`, - 1 AS `empresa_id` */; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `Split_lines` -- @@ -82177,7 +82339,6 @@ SET character_set_client = utf8; 1 AS `Id_Trabajador`, 1 AS `Observaciones`, 1 AS `Firmado`, - 1 AS `Etiquetasemitidas`, 1 AS `PedidoImpreso`, 1 AS `Hora`, 1 AS `blocked`, @@ -85135,7 +85296,7 @@ USE `srt`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `bufferDayMinute` AS select `b`.`id` AS `bufferFk`,`e`.`id` AS `expeditionFk`,`srt`.`dayMinute`(ifnull(`rs`.`eta`,`z`.`hour`)) AS `dayMinute`,`e`.`position` AS `position`,ifnull(`rs`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) minute) AS `ETD`,`e2`.`ticketFk` AS `ticketFk`,ifnull(`t`.`routeFk`,`t`.`agencyModeFk`) AS `routeFk`,`z`.`name` AS `zonaTicket`,`es`.`description` AS `expeditionState` from ((((((((`srt`.`buffer` `b` left join `srt`.`expedition` `e` on(`b`.`id` = `e`.`bufferFk`)) left join `srt`.`expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `srt`.`bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) left join `vn`.`expedition` `e2` on(`e2`.`id` = `e`.`id`)) left join `vn`.`ticket` `t` on(`e2`.`ticketFk` = `t`.`id`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`roadmapStop` `rs` on(`rm`.`expeditionTruckFk` = `rs`.`id`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) where `b`.`isActive` <> 0 */; +/*!50001 VIEW `bufferDayMinute` AS select `b`.`id` AS `bufferFk`,`e`.`id` AS `expeditionFk`,`srt`.`dayMinute`(ifnull(`rs`.`eta`,`z`.`hour`)) AS `dayMinute`,`e`.`position` AS `position`,ifnull(`rs`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) minute) AS `ETD`,`e2`.`ticketFk` AS `ticketFk`,ifnull(`t`.`routeFk`,`t`.`agencyModeFk`) AS `routeFk`,`z`.`name` AS `zonaTicket`,`es`.`description` AS `expeditionState` from ((((((((`srt`.`buffer` `b` left join `srt`.`expedition` `e` on(`b`.`id` = `e`.`bufferFk`)) left join `srt`.`expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `srt`.`bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) left join `vn`.`expedition` `e2` on(`e2`.`id` = `e`.`id`)) left join `vn`.`ticket` `t` on(`e2`.`ticketFk` = `t`.`id`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`roadmapStop` `rs` on(`rm`.`roadmapStopFk` = `rs`.`id`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) where `b`.`isActive` <> 0 */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85171,7 +85332,7 @@ USE `srt`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `bufferStock` AS select `e`.`id` AS `expeditionFk`,`e`.`bufferFk` AS `bufferFk`,`e`.`position` AS `position`,`srt`.`dayMinute`(ifnull(`rs`.`eta`,`z`.`hour`)) AS `dayMinute`,ifnull(`rs`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) + 120 minute) AS `eta`,`ve`.`ticketFk` AS `ticketFk`,ifnull(`t`.`routeFk`,`t`.`agencyModeFk`) AS `routeFk`,`z`.`name` AS `zonaTicket`,`rs`.`description` AS `truck`,`es`.`description` AS `expeditionState`,`b`.`hasWorkerWaiting` AS `hasWorkerWaiting`,`b`.`isActive` AS `isActive`,if(`rs`.`id` is null,`c`.`bufferDefault`,`rs`.`bufferFk`) AS `bufferTruck`,`bt`.`typeName` AS `typeName`,`rm`.`bufferFk` AS `routeBuffer` from (((((((((`srt`.`expedition` `e` left join `vn`.`expedition` `ve` on(`ve`.`id` = `e`.`id`)) join `srt`.`expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `srt`.`buffer` `b` on(`b`.`id` = `e`.`bufferFk`)) left join `vn`.`ticket` `t` on(`t`.`id` = `ve`.`ticketFk`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`roadmapStop` `rs` on(`rm`.`expeditionTruckFk` = `rs`.`id`)) join `srt`.`config` `c`) join `srt`.`bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) where `bt`.`typeName` <> 'DISABLED' */; +/*!50001 VIEW `bufferStock` AS select `e`.`id` AS `expeditionFk`,`e`.`bufferFk` AS `bufferFk`,`e`.`position` AS `position`,`srt`.`dayMinute`(ifnull(`rs`.`eta`,`z`.`hour`)) AS `dayMinute`,ifnull(`rs`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) + 120 minute) AS `eta`,`ve`.`ticketFk` AS `ticketFk`,ifnull(`t`.`routeFk`,`t`.`agencyModeFk`) AS `routeFk`,`z`.`name` AS `zonaTicket`,`rs`.`description` AS `truck`,`es`.`description` AS `expeditionState`,`b`.`hasWorkerWaiting` AS `hasWorkerWaiting`,`b`.`isActive` AS `isActive`,if(`rs`.`id` is null,`c`.`bufferDefault`,`rs`.`bufferFk`) AS `bufferTruck`,`bt`.`typeName` AS `typeName`,`rm`.`bufferFk` AS `routeBuffer` from (((((((((`srt`.`expedition` `e` left join `vn`.`expedition` `ve` on(`ve`.`id` = `e`.`id`)) join `srt`.`expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `srt`.`buffer` `b` on(`b`.`id` = `e`.`bufferFk`)) left join `vn`.`ticket` `t` on(`t`.`id` = `ve`.`ticketFk`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`roadmapStop` `rs` on(`rm`.`roadmapStopFk` = `rs`.`id`)) join `srt`.`config` `c`) join `srt`.`bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) where `bt`.`typeName` <> 'DISABLED' */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85261,7 +85422,7 @@ USE `srt`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `upperStickers` AS select `e`.`id` AS `expeditionFk`,`e`.`id` MOD 10000 AS `expedition`,ifnull(`rs`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) + 120 minute) AS `ETD`,`ve`.`ticketFk` AS `ticketFk`,right(ifnull(`t`.`routeFk`,`t`.`agencyModeFk`),3) AS `routeFk`,`z`.`name` AS `zonaTicket`,`rs`.`description` AS `truck`,`epo`.`workerCode` AS `worker`,`p`.`name` AS `labeler`,`ve`.`counter` AS `expeditionCounter`,`vn`.`ticketTotalVolume`(`t`.`id`) AS `m3`,`t`.`clientFk` AS `clientFk` from (((((((`srt`.`expedition` `e` left join `vn`.`expedition` `ve` on(`ve`.`id` = `e`.`id`)) left join `vn`.`ticket` `t` on(`t`.`id` = `ve`.`ticketFk`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`roadmapStop` `rs` on(`rm`.`expeditionTruckFk` = `rs`.`id`)) join `dipole`.`expedition_PrintOut` `epo` on(`epo`.`expeditionFk` = `e`.`id`)) join `vn`.`printer` `p` on(`p`.`id` = `epo`.`printerFk`)) */; +/*!50001 VIEW `upperStickers` AS select `e`.`id` AS `expeditionFk`,`e`.`id` MOD 10000 AS `expedition`,ifnull(`rs`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) + 120 minute) AS `ETD`,`ve`.`ticketFk` AS `ticketFk`,right(ifnull(`t`.`routeFk`,`t`.`agencyModeFk`),3) AS `routeFk`,`z`.`name` AS `zonaTicket`,`rs`.`description` AS `truck`,`epo`.`workerCode` AS `worker`,`p`.`name` AS `labeler`,`ve`.`counter` AS `expeditionCounter`,`vn`.`ticketTotalVolume`(`t`.`id`) AS `m3`,`t`.`clientFk` AS `clientFk` from (((((((`srt`.`expedition` `e` left join `vn`.`expedition` `ve` on(`ve`.`id` = `e`.`id`)) left join `vn`.`ticket` `t` on(`t`.`id` = `ve`.`ticketFk`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`roadmapStop` `rs` on(`rm`.`roadmapStopFk` = `rs`.`id`)) join `dipole`.`expedition_PrintOut` `epo` on(`epo`.`expeditionFk` = `e`.`id`)) join `vn`.`printer` `p` on(`p`.`id` = `epo`.`printerFk`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85681,7 +85842,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionCommon` AS select `rs`.`id` AS `truckFk`,`rs`.`eta` AS `eta`,ifnull(ucase(`rs`.`description`),'SIN ESCANEAR') AS `description`,`es`.`palletFk` AS `palletFk`,`t`.`routeFk` AS `routeFk`,`es`.`id` AS `scanFk`,`e`.`id` AS `expeditionFk`,`r`.`expeditionTruckFk` AS `expeditionTruckFk`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `lastPacked`,`t`.`id` AS `ticketFk` from (((((`roadmapStop` `rs` left join `routesMonitor` `r` on(`rs`.`id` = `r`.`expeditionTruckFk`)) left join `ticket` `t` on(`r`.`routeFk` = `t`.`routeFk`)) left join `expedition` `e` on(`t`.`id` = `e`.`ticketFk`)) left join `expeditionScan` `es` on(`e`.`id` = `es`.`expeditionFk`)) left join `expeditionPallet` `ep` on(`es`.`palletFk` = `ep`.`id`)) where `rs`.`eta` >= `util`.`VN_CURDATE`() */; +/*!50001 VIEW `expeditionCommon` AS select `rs`.`id` AS `truckFk`,`rs`.`eta` AS `eta`,ifnull(ucase(`rs`.`description`),'SIN ESCANEAR') AS `description`,`es`.`palletFk` AS `palletFk`,`t`.`routeFk` AS `routeFk`,`es`.`id` AS `scanFk`,`e`.`id` AS `expeditionFk`,`r`.`roadmapStopFk` AS `roadmapStopFk`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `lastPacked`,`t`.`id` AS `ticketFk` from (((((`roadmapStop` `rs` left join `routesMonitor` `r` on(`rs`.`id` = `r`.`roadmapStopFk`)) left join `ticket` `t` on(`r`.`routeFk` = `t`.`routeFk`)) left join `expedition` `e` on(`t`.`id` = `e`.`ticketFk`)) left join `expeditionScan` `es` on(`e`.`id` = `es`.`expeditionFk`)) left join `expeditionPallet` `ep` on(`es`.`palletFk` = `ep`.`id`)) where `rs`.`eta` >= `util`.`VN_CURDATE`() */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85699,7 +85860,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionPallet_Print` AS select `rs2`.`description` AS `truck`,`t`.`routeFk` AS `routeFk`,`r`.`description` AS `zone`,count(`es`.`id`) AS `eti`,`ep`.`id` AS `palletFk`,`rs`.`id` <=> `rm`.`expeditionTruckFk` AS `isMatch`,`t`.`warehouseFk` AS `warehouseFk`,if(`r`.`created` > `util`.`VN_CURDATE`() + interval 1 day,ucase(dayname(`r`.`created`)),NULL) AS `nombreDia` from (((((((`roadmapStop` `rs` join `expeditionPallet` `ep` on(`ep`.`truckFk` = `rs`.`id`)) join `expeditionScan` `es` on(`es`.`palletFk` = `ep`.`id`)) join `expedition` `e` on(`e`.`id` = `es`.`expeditionFk`)) join `ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) join `route` `r` on(`r`.`id` = `t`.`routeFk`)) left join `routesMonitor` `rm` on(`rm`.`routeFk` = `r`.`id`)) left join `roadmapStop` `rs2` on(`rs2`.`id` = `rm`.`expeditionTruckFk`)) group by `ep`.`id`,`t`.`routeFk` */; +/*!50001 VIEW `expeditionPallet_Print` AS select `rs2`.`description` AS `truck`,`t`.`routeFk` AS `routeFk`,`r`.`description` AS `zone`,count(`es`.`id`) AS `eti`,`ep`.`id` AS `palletFk`,`rs`.`id` <=> `rm`.`roadmapStopFk` AS `isMatch`,`t`.`warehouseFk` AS `warehouseFk`,if(`r`.`created` > `util`.`VN_CURDATE`() + interval 1 day,ucase(dayname(`r`.`created`)),NULL) AS `nombreDia` from (((((((`roadmapStop` `rs` join `expeditionPallet` `ep` on(`ep`.`truckFk` = `rs`.`id`)) join `expeditionScan` `es` on(`es`.`palletFk` = `ep`.`id`)) join `expedition` `e` on(`e`.`id` = `es`.`expeditionFk`)) join `ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) join `route` `r` on(`r`.`id` = `t`.`routeFk`)) left join `routesMonitor` `rm` on(`rm`.`routeFk` = `r`.`id`)) left join `roadmapStop` `rs2` on(`rs2`.`id` = `rm`.`roadmapStopFk`)) group by `ep`.`id`,`t`.`routeFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85717,7 +85878,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionRoute_Monitor` AS select `r`.`id` AS `routeFk`,count(distinct if(`e`.`id` is null,`t`.`id`,NULL)) AS `tickets`,count(distinct `e`.`id`) AS `expeditions`,count(distinct `es`.`id`) AS `scanned`,max(`e`.`created`) AS `lastPacked`,`r`.`created` AS `created` from (((((`route` `r` left join `routesMonitor` `rm` on(`r`.`id` = `rm`.`routeFk`)) left join `roadmapStop` `rs` on(`rs`.`id` = `rm`.`expeditionTruckFk`)) join `ticket` `t` on(`t`.`routeFk` = `r`.`id`)) left join `expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) left join `expeditionScan` `es` on(`es`.`expeditionFk` = `e`.`id`)) where `r`.`created` >= `util`.`yesterday`() group by `r`.`id` */; +/*!50001 VIEW `expeditionRoute_Monitor` AS select `r`.`id` AS `routeFk`,count(distinct if(`e`.`id` is null,`t`.`id`,NULL)) AS `tickets`,count(distinct `e`.`id`) AS `expeditions`,count(distinct `es`.`id`) AS `scanned`,max(`e`.`created`) AS `lastPacked`,`r`.`created` AS `created` from (((((`route` `r` left join `routesMonitor` `rm` on(`r`.`id` = `rm`.`routeFk`)) left join `roadmapStop` `rs` on(`rs`.`id` = `rm`.`roadmapStopFk`)) join `ticket` `t` on(`t`.`routeFk` = `r`.`id`)) left join `expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) left join `expeditionScan` `es` on(`es`.`expeditionFk` = `e`.`id`)) where `r`.`created` >= `util`.`yesterday`() group by `r`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85771,7 +85932,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionSticker` AS select `e`.`id` AS `expeditionFk`,`e`.`ticketFk` AS `ticketFk`,`t`.`addressFk` AS `addressFk`,`t`.`clientFk` AS `clientFk`,`a`.`street` AS `street`,`a`.`postalCode` AS `postalCode`,`a`.`city` AS `city`,`a`.`nickname` AS `nickname`,concat('R(',right(`t`.`routeFk`,3),')') AS `routeFk`,`rm`.`beachFk` AS `beachFk`,if(`t`.`routeFk`,ifnull(`rs`.`description`,replace(`am`.`name`,'ZONA ','Z')),`z`.`name`) AS `zona`,`p`.`name` AS `province`,ifnull(`c`.`mobile`,ifnull(`a`.`mobile`,ifnull(`c`.`phone`,`a`.`phone`))) AS `phone`,`w`.`code` AS `workerCode` from (((((((((((`expedition` `e` join `ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) join `address` `a` on(`a`.`id` = `t`.`addressFk`)) join `province` `p` on(`p`.`id` = `a`.`provinceFk`)) left join `routesMonitor` `rm` on(`rm`.`routeFk` = `t`.`routeFk`)) left join `roadmapStop` `rs` on(`rs`.`id` = `rm`.`expeditionTruckFk`)) left join `beach` `b` on(`b`.`code` = `rm`.`beachFk`)) left join `zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `route` `r` on(`r`.`id` = `t`.`routeFk`)) left join `agencyMode` `am` on(`am`.`id` = `r`.`agencyModeFk`)) join `client` `c` on(`c`.`id` = `a`.`clientFk`)) join `worker` `w` on(`w`.`id` = `e`.`workerFk`)) */; +/*!50001 VIEW `expeditionSticker` AS select `e`.`id` AS `expeditionFk`,`e`.`ticketFk` AS `ticketFk`,`t`.`addressFk` AS `addressFk`,`t`.`clientFk` AS `clientFk`,`a`.`street` AS `street`,`a`.`postalCode` AS `postalCode`,`a`.`city` AS `city`,`a`.`nickname` AS `nickname`,concat('R(',right(`t`.`routeFk`,3),')') AS `routeFk`,`rm`.`beachFk` AS `beachFk`,if(`t`.`routeFk`,ifnull(`rs`.`description`,replace(`am`.`name`,'ZONA ','Z')),`z`.`name`) AS `zona`,`p`.`name` AS `province`,ifnull(`c`.`mobile`,ifnull(`a`.`mobile`,ifnull(`c`.`phone`,`a`.`phone`))) AS `phone`,`w`.`code` AS `workerCode` from (((((((((((`expedition` `e` join `ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) join `address` `a` on(`a`.`id` = `t`.`addressFk`)) join `province` `p` on(`p`.`id` = `a`.`provinceFk`)) left join `routesMonitor` `rm` on(`rm`.`routeFk` = `t`.`routeFk`)) left join `roadmapStop` `rs` on(`rs`.`id` = `rm`.`roadmapStopFk`)) left join `beach` `b` on(`b`.`code` = `rm`.`beachFk`)) left join `zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `route` `r` on(`r`.`id` = `t`.`routeFk`)) left join `agencyMode` `am` on(`am`.`id` = `r`.`agencyModeFk`)) join `client` `c` on(`c`.`id` = `a`.`clientFk`)) join `worker` `w` on(`w`.`id` = `e`.`workerFk`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85789,7 +85950,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTicket_NoBoxes` AS select `t`.`id` AS `ticketFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`routeFk` AS `routeFk`,`rs`.`description` AS `description` from (((`ticket` `t` left join `expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) join `routesMonitor` `rm` on(`rm`.`routeFk` = `t`.`routeFk`)) join `roadmapStop` `rs` on(`rs`.`id` = `rm`.`expeditionTruckFk`)) where `e`.`id` is null and `rs`.`eta` > `util`.`VN_CURDATE`() */; +/*!50001 VIEW `expeditionTicket_NoBoxes` AS select `t`.`id` AS `ticketFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`routeFk` AS `routeFk`,`rs`.`description` AS `description` from (((`ticket` `t` left join `expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) join `routesMonitor` `rm` on(`rm`.`routeFk` = `t`.`routeFk`)) join `roadmapStop` `rs` on(`rs`.`id` = `rm`.`roadmapStopFk`)) where `e`.`id` is null and `rs`.`eta` > `util`.`VN_CURDATE`() */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85825,61 +85986,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck` AS select `rs`.`id` AS `id`,`rs`.`roadmapFk` AS `roadmapFk`,`rs`.`warehouseFk` AS `warehouseFk`,`rs`.`eta` AS `eta`,`rs`.`description` AS `description`,`rs`.`bufferFk` AS `bufferFk`,`rs`.`created` AS `created`,`rs`.`userFk` AS `userFk` from `roadmapStop` `rs` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `expeditionTruck_Control` --- - -/*!50001 DROP VIEW IF EXISTS `expeditionTruck_Control`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control` AS select `e`.`truckFk` AS `id`,`e`.`eta` AS `ETD`,`e`.`description` AS `description`,count(distinct if(`e`.`expeditionFk` is null,`e`.`ticketFk`,NULL)) AS `ticketsSinBultos`,count(distinct `e`.`palletFk`) AS `pallets`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionFk`) AS `expeditions`,sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk` order by sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) desc,`e`.`eta` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `expeditionTruck_Control_Detail` --- - -/*!50001 DROP VIEW IF EXISTS `expeditionTruck_Control_Detail`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control_Detail` AS select `e`.`truckFk` AS `id`,`e`.`eta` AS `eta`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionTruckFk`) AS `destinos`,sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk`,`e`.`palletFk` order by sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) desc,`e`.`eta`,`e`.`truckFk` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `expeditionTruck_Control_Detail_Pallet` --- - -/*!50001 DROP VIEW IF EXISTS `expeditionTruck_Control_Detail_Pallet`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control_Detail_Pallet` AS select `e`.`truckFk` AS `id`,`e`.`eta` AS `eta`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,`e`.`routeFk` AS `route`,count(distinct `e`.`scanFk`) AS `scans`,`rs`.`description` AS `destinos`,sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,`e`.`expeditionTruckFk` AS `expeditionTruckFk`,max(`e`.`lastPacked`) AS `lastPacked` from (`expeditionCommon` `e` left join `roadmapStop` `rs` on(`rs`.`id` = `e`.`expeditionTruckFk`)) group by `e`.`truckFk`,`e`.`palletFk`,`e`.`routeFk` order by sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) desc,`e`.`palletFk` */; +/*!50001 VIEW `expeditionTruck` AS select `rs`.`id` AS `id`,`rs`.`roadmapFk` AS `roadmapFk`,`rs`.`eta` AS `eta`,`rs`.`description` AS `description`,`rs`.`bufferFk` AS `bufferFk`,`rs`.`created` AS `created`,`rs`.`userFk` AS `userFk` from `roadmapStop` `rs` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -87852,24 +87959,6 @@ USE `vn2008`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `Saldos_Prevision` --- - -/*!50001 DROP VIEW IF EXISTS `Saldos_Prevision`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `Saldos_Prevision` AS select `fb`.`id` AS `Saldos_Prevision_id`,`fb`.`description` AS `Descripcion`,`fb`.`amount` AS `Importe`,`fb`.`dated` AS `Fecha`,`fb`.`accountingFk` AS `Id_Banco`,`fb`.`companyFk` AS `empresa_id` from `vn`.`forecastedBalance` `fb` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - -- -- Final view structure for view `Split_lines` -- @@ -87919,7 +88008,7 @@ USE `vn2008`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `Tickets` AS select `t`.`id` AS `Id_Ticket`,`t`.`clientFk` AS `Id_Cliente`,`t`.`warehouseFk` AS `warehouse_id`,`t`.`shipped` AS `Fecha`,`t`.`landed` AS `landing`,`t`.`nickname` AS `Alias`,`t`.`refFk` AS `Factura`,`t`.`addressFk` AS `Id_Consigna`,`t`.`location` AS `Localizacion`,`t`.`solution` AS `Solucion`,`t`.`routeFk` AS `Id_Ruta`,`t`.`companyFk` AS `empresa_id`,`t`.`agencyModeFk` AS `Id_Agencia`,`t`.`priority` AS `Prioridad`,`t`.`packages` AS `Bultos`,`t`.`isDeleted` AS `isDeleted`,`t`.`created` AS `odbc_date`,`t`.`workerFk` AS `Id_Trabajador`,`t`.`observations` AS `Observaciones`,`t`.`isSigned` AS `Firmado`,`t`.`isLabeled` AS `Etiquetasemitidas`,`t`.`isPrinted` AS `PedidoImpreso`,`t`.`hour` AS `Hora`,`t`.`isBlocked` AS `blocked`,`t`.`hasPriority` AS `priority`,`t`.`isBoxed` AS `boxed`,`t`.`zoneFk` AS `zoneFk`,`t`.`totalWithVat` AS `totalWithVat`,`t`.`totalWithoutVat` AS `totalWithoutVat` from `vn`.`ticket` `t` */; +/*!50001 VIEW `Tickets` AS select `t`.`id` AS `Id_Ticket`,`t`.`clientFk` AS `Id_Cliente`,`t`.`warehouseFk` AS `warehouse_id`,`t`.`shipped` AS `Fecha`,`t`.`landed` AS `landing`,`t`.`nickname` AS `Alias`,`t`.`refFk` AS `Factura`,`t`.`addressFk` AS `Id_Consigna`,`t`.`location` AS `Localizacion`,`t`.`solution` AS `Solucion`,`t`.`routeFk` AS `Id_Ruta`,`t`.`companyFk` AS `empresa_id`,`t`.`agencyModeFk` AS `Id_Agencia`,`t`.`priority` AS `Prioridad`,`t`.`packages` AS `Bultos`,`t`.`isDeleted` AS `isDeleted`,`t`.`created` AS `odbc_date`,`t`.`workerFk` AS `Id_Trabajador`,`t`.`observations` AS `Observaciones`,`t`.`isSigned` AS `Firmado`,`t`.`isPrinted` AS `PedidoImpreso`,`t`.`hour` AS `Hora`,`t`.`isBlocked` AS `blocked`,`t`.`hasPriority` AS `priority`,`t`.`isBoxed` AS `boxed`,`t`.`zoneFk` AS `zoneFk`,`t`.`totalWithVat` AS `totalWithVat`,`t`.`totalWithoutVat` AS `totalWithoutVat` from `vn`.`ticket` `t` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -89715,4 +89804,4 @@ USE `vn2008`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-06-11 6:35:36 +-- Dump completed on 2024-06-25 7:26:45 diff --git a/db/dump/.dump/triggers.sql b/db/dump/.dump/triggers.sql index b2f550bbe..90ff6b30d 100644 --- a/db/dump/.dump/triggers.sql +++ b/db/dump/.dump/triggers.sql @@ -2140,24 +2140,22 @@ BEGIN END IF; IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN - - SELECT COUNT(*) > 0 INTO isOverlapping - FROM business b - WHERE (util.hasDateOverlapped( - NEW.started, - IFNULL(NEW.ended, b.started), - b.started, - IFNULL(b.ended, NEW.started)) - OR (NEW.ended <=> NULL AND b.ended <=> NULL)) - AND b.id <> OLD.id - AND workerFk = OLD.workerFk; + SELECT util.hasDateOverlapped( + started, + ended, + NEW.started, + IFNULL(NEW.ended, b.started) + ) isOverlapped INTO isOverlapping + FROM vn.business b + WHERE workerFk = NEW.workerFK + AND b.id <> NEW.id + ORDER BY isOverlapped DESC + LIMIT 1; IF isOverlapping THEN CALL util.throw ('IS_OVERLAPPING'); END IF; - END IF; - END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -2366,7 +2364,15 @@ trig:BEGIN LEAVE trig; END IF; - CALL entry_isEditable(OLD.entryFk); + IF NOT (NEW.entryFk <=> OLD.entryFk) OR + NOT (NEW.quantity <=> OLD.quantity) OR + NOT (NEW.buyingValue <=> OLD.buyingValue) OR + NOT (NEW.packing <=> OLD.packing) + THEN + + CALL entry_isEditable(OLD.entryFk); + END IF; + SET NEW.editorFk = account.myUser_getId(); SELECT defaultEntry INTO vDefaultEntry @@ -3010,6 +3016,52 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimRatio_afterInsert` + AFTER INSERT ON `claimRatio` + FOR EACH ROW +BEGIN + INSERT INTO clientRate(clientFk, `value`) + VALUES(NEW.clientFk, NEW.priceIncreasing) + ON DUPLICATE KEY UPDATE + `value` = VALUES(`value`); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimRatio_afterUpdate` + AFTER UPDATE ON `claimRatio` + FOR EACH ROW +BEGIN + INSERT INTO clientRate(clientFk, `value`) + VALUES(NEW.clientFk, NEW.priceIncreasing) + ON DUPLICATE KEY UPDATE + `value` = VALUES(`value`); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_beforeInsert` BEFORE INSERT ON `claimState` FOR EACH ROW @@ -3198,11 +3250,11 @@ BEGIN END IF; END IF; - IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN + IF NOT (NEW.salesPersonFk <=> OLD.salesPersonFk) THEN SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); END IF; - IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN + IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN SET NEW.isTaxDataChecked = 0; END IF; END */;; @@ -3224,13 +3276,36 @@ DELIMITER ;; AFTER UPDATE ON `client` FOR EACH ROW BEGIN - IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN + IF NOT (NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN UPDATE `address` SET isDefaultAddress = FALSE WHERE clientFk = NEW.id; UPDATE `address` SET isDefaultAddress = TRUE WHERE id = NEW.defaultAddressFk; END IF; + + IF NEW.id <> OLD.id + OR NOT (NEW.provinceFk <=> OLD.provinceFk) + OR NOT (NEW.socialName <=> OLD.socialName) + OR NOT (NEW.street <=> OLD.street) + OR NOT (NEW.accountingAccount <=> OLD.accountingAccount) + OR NOT (NEW.isVies <=> OLD.isVies) + OR NOT (NEW.fi <=> OLD.fi) + OR NOT (NEW.postcode <=> OLD.postcode) + OR NOT (NEW.city <=> OLD.city) + OR NOT (NEW.countryFk <=> OLD.countryFk) + OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk) + OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk) + OR NOT (NEW.email <=> OLD.email) + OR NOT (NEW.iban <=> OLD.iban) + OR NOT (NEW.phone <=> OLD.phone) + OR NOT (NEW.mobile <=> OLD.mobile) THEN + + UPDATE sage.clientSupplier + SET isSync = FALSE + WHERE idClientSupplier IN (NEW.id, OLD.id) + AND `type` = 'C'; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4203,31 +4278,6 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionConfig_afterUpdate` - AFTER UPDATE ON `deviceProductionConfig` - FOR EACH ROW -BEGIN - IF NEW.isAllUsersAllowed = 1 OR NEW.isAllUsersAllowed = -1 THEN - SET @username := (SELECT account.myUser_getName()); - INSERT INTO vn.mail (receiver, subject, body) - VALUES ('cau@verdnatura.es', 'Se ha activado la autenticación sin restricciones en la app', - CONCAT('El usuario ', @username,' ha habilitado la opción para que todos los usuarios puedan acceder a la app sin restricciones')); - END IF; -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionModels_beforeInsert` BEFORE INSERT ON `deviceProductionModels` FOR EACH ROW @@ -4617,10 +4667,21 @@ BEGIN DECLARE vPrintedCount INT; DECLARE vHasDistinctWarehouses BOOL; DECLARE vTotalBuy INT; - - IF NEW.isBooked = OLD.isBooked THEN + + IF NEW.isBooked = OLD.isBooked AND ( + NOT (NEW.supplierFk <=> OLD.supplierFk) OR + NOT (NEW.dated <=> OLD.dated) OR + NOT (NEW.invoiceNumber <=> OLD.invoiceNumber) OR + NOT (NEW.travelFk <=> OLD.travelFk) OR + NOT (NEW.companyFk <=> OLD.companyFk) OR + NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) OR + NOT (NEW.invoiceAmount <=> OLD.invoiceAmount) OR + NOT (NEW.typeFk <=> OLD.typeFk) + ) THEN + CALL entry_isEditable(OLD.id); ELSE + IF NEW.isBooked THEN SELECT COUNT(*) INTO vTotalBuy FROM buy @@ -4894,25 +4955,25 @@ DELIMITER ;; BEFORE INSERT ON `expedition` FOR EACH ROW BEGIN - DECLARE intcounter INT; - DECLARE vShipFk INT; + DECLARE vMaxCounter INT; SET NEW.editorFk = account.myUser_getId(); - IF NEW.freightItemFk IS NOT NULL THEN + IF NEW.freightItemFk IS NOT NULL THEN UPDATE ticket SET packages = IFNULL(packages, 0) + 1 WHERE id = NEW.ticketFk; - SELECT IFNULL(MAX(counter),0) +1 INTO intcounter - FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id + SELECT IFNULL(MAX(counter),0) + 1 INTO vMaxCounter + FROM expedition e + JOIN alertLevel al ON al.code = 'DELIVERED' + JOIN ticket t1 ON e.ticketFk = t1.id LEFT JOIN ticketState ts ON ts.ticketFk = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) AND t1.warehouseFk = t2.warehouseFk - WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk + WHERE t2.id = NEW.ticketFk AND ts.alertLevel < al.id AND t1.companyFk = t2.companyFk AND t1.agencyModeFk = t2.agencyModeFk; - SET NEW.`counter` = intcounter; + SET NEW.`counter` = vMaxCounter; END IF; END */;; DELIMITER ; @@ -8525,6 +8586,44 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_afterUpdate` + BEFORE UPDATE ON `supplier` + FOR EACH ROW +BEGIN + IF NEW.id <> OLD.id + OR NOT (NEW.name <=> OLD.name) + OR NOT (NEW.street <=> OLD.street) + OR NOT (NEW.account <=> OLD.account) + OR NOT (NEW.nif <=> OLD.nif) + OR NOT (NEW.isVies <=> OLD.isVies) + OR NOT (NEW.provinceFk <=> OLD.provinceFk) + OR NOT (NEW.countryFk <=> OLD.countryFk) + OR NOT (NEW.postCode <=> OLD.postCode) + OR NOT (NEW.city <=> OLD.city) + OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk) + OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk) + OR NOT (NEW.withholdingSageFk <=> OLD.withholdingSageFk) THEN + + UPDATE sage.clientSupplier + SET isSync = FALSE + WHERE idClientSupplier IN (NEW.id, OLD.id) + AND `type` = 'P'; + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_afterDelete` AFTER DELETE ON `supplier` FOR EACH ROW @@ -10825,4 +10924,4 @@ USE `vn2008`; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-06-11 6:35:55 +-- Dump completed on 2024-06-25 7:27:06 From 655bbe4967e34ca9fa02adc70f77b40503979785 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 25 Jun 2024 12:29:17 +0200 Subject: [PATCH 80/81] refs #7406 fix pr --- db/dump/fixtures.before.sql | 10 ++++------ db/versions/11073-crimsonBirch/00-firstScript.sql | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 941a046b0..0be918fbb 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3828,7 +3828,6 @@ INSERT INTO vn.workerTeam(id, team, workerFk) INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL); -UPDATE vn.locker SET workerFk = 1110 WHERE id = 147; INSERT INTO `vn`.`locker` (code, gender, workerFk) VALUES ('1M', 'M', 1), ('2M', 'M', 9), @@ -3848,11 +3847,10 @@ INSERT INTO `vn`.`ledgerConfig` SET INSERT INTO vn.trainingCourse (workerFk,trainingCourseTypeFk,centerFk,started,ended,hasDiscount,hasDiploma) - VALUES (9,2,1,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',0,1); -INSERT INTO vn.trainingCourse (workerFk,trainingCourseTypeFk,centerFk,started,ended,hasDiscount,hasDiploma) - VALUES (9,1,2,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',1,0); -INSERT INTO vn.trainingCourse (workerFk,trainingCourseTypeFk,centerFk,started,ended,hasDiscount,hasDiploma) - VALUES (9,2,2,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',1,1); + VALUES + (9,2,1,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',0,1), + (9,1,2,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',1,0), + (9,2,2,'2018-06-20 00:00:00.000','2020-06-24 00:00:00.000',1,1); INSERT INTO vn.sectorCollection SET id = 2, diff --git a/db/versions/11073-crimsonBirch/00-firstScript.sql b/db/versions/11073-crimsonBirch/00-firstScript.sql index 7d76a75cd..e82d342c9 100644 --- a/db/versions/11073-crimsonBirch/00-firstScript.sql +++ b/db/versions/11073-crimsonBirch/00-firstScript.sql @@ -1,9 +1,9 @@ -- Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values. INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('TrainingCourse','*','*','ALLOW','ROLE','employee'); + VALUES ('TrainingCourse','*','*','ALLOW','ROLE','hr'); INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('TrainingCourseType','*','*','ALLOW','ROLE','employee'); + VALUES ('TrainingCourseType','*','*','ALLOW','ROLE','hr'); INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('TrainingCenter','*','*','ALLOW','ROLE','employee'); + VALUES ('TrainingCenter','*','*','ALLOW','ROLE','hr'); INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Worker','__get__trainingCourse','*','ALLOW','ROLE','employee'); + VALUES ('Worker','__get__trainingCourse','*','ALLOW','ROLE','hr'); From 85854e0713d07a3e525a6a0e5fd7a64c350dc406 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 25 Jun 2024 13:14:44 +0200 Subject: [PATCH 81/81] warmFix: use vn --- db/routines/vn/procedures/duaInvoiceInBooking.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 1f026e96b..6d0c9f517 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -36,7 +36,7 @@ BEGIN SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk; - IF vBookEntry IS NULL THEN + IF vBookEntry IS NULL THEN SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear FROM invoiceIn ii JOIN `entry` e ON e.invoiceInFk = ii.id @@ -45,7 +45,7 @@ BEGIN WHERE d.id = vDuaFk LIMIT 1; CALL ledger_nextTx(vFiscalYear, vBookEntry); - END IF; + END IF; OPEN vInvoicesIn; @@ -75,14 +75,14 @@ BEGIN JOIN ( WITH entries AS ( SELECT e.id, de.duaFk - FROM `entry` e - JOIN duaEntry de ON de.entryFk = e.id + FROM vn.`entry` e + JOIN vn.duaEntry de ON de.entryFk = e.id WHERE de.duaFk = vDuaFk AND (NOT e.isBooked OR NOT e.isConfirmed) ), notBookedEntries AS ( SELECT e.id - FROM duaEntry + FROM vn.duaEntry WHERE duaFk = vDuaFk AND NOT customsValue )