From 1ccec1e0fb5ab8d5b747431693a5ce49860e7a73 Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 4 Mar 2024 08:11:06 +0100 Subject: [PATCH 01/13] refs #6499 procRefactor part 6 --- .../procedures/absoluteInventoryHistory.sql | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 db/routines/vn/procedures/absoluteInventoryHistory.sql diff --git a/db/routines/vn/procedures/absoluteInventoryHistory.sql b/db/routines/vn/procedures/absoluteInventoryHistory.sql new file mode 100644 index 000000000..427b9ba51 --- /dev/null +++ b/db/routines/vn/procedures/absoluteInventoryHistory.sql @@ -0,0 +1,99 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`( + vIdArticle INT, vWarehouse INT, vDate DATETIME) +BEGIN +/** +* Calcula y proporciona un historial de inventario absoluto +* para un artículo específico en un almacén dado +* hasta una fecha determinada. +* +* @param vIdArticle Id de artículo +* @param vWarehouse Almacén +* @param vDate Fecha +*/ + DECLARE vCalculatedInventory INT; + DECLARE vToday DATETIME; + + SET vToday = util.VN_CURDATE(); + + CREATE OR REPLACE TEMPORARY TABLE historicalPast + ENGINE = MEMORY + SELECT * + FROM ( + SELECT tr.landed Fecha, + b.quantity Entrada, + NULL Salida, + (tr.isReceived != FALSE) OK, + s.name Alias, + e.invoiceNumber Referencia, + e.id id, + tr.isDelivered F5 + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN supplier s ON s.id = e.supplierFk + WHERE tr.landed >= '2001-01-01' + AND s.id <> 4 + AND vWarehouse IN (tr.warehouseInFk, 0) + AND b.itemFk = vIdArticle + AND e.isExcludedFromAvailable = 0 + AND e.isRaid = 0 + UNION ALL + SELECT tr.shipped Fecha, + NULL Entrada, + b.quantity Salida, + tr.isDelivered OK, + s.name Alias, + e.invoiceNumber Referencia, + e.id id, + tr.isDelivered F5 + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN supplier s ON s.id = e.supplierFk + WHERE tr.shipped >= '2001-01-01' + AND vWarehouse = tr.warehouseOutFk + AND s.id <> 4 + AND b.itemFk = vIdArticle + AND e.isExcludedFromAvailable = 0 + AND e.isRaid = 0 + UNION ALL + SELECT t.shipped Fecha, + NULL Entrada, + m.quantity Salida, + (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) OK, + t.nickname Alias, + t.refFk Referencia, + t.id, + t.isPrinted + FROM sale m + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente + WHERE T.Fecha >= '2001-01-01' + AND M.Id_Article = vIdArticle + AND vWarehouse IN (T.warehouse_id , 0) + ) t1 + ORDER BY Fecha, Entrada DESC, OK DESC; + + SELECT sum(Entrada) - sum(Salida) INTO vCalculatedInventory + FROM historicalPast + WHERE Fecha < vDate; + + SELECT p1.*, NULL v_virtual + FROM( + SELECT vDate Fecha, + vCalculatedInventory Entrada, + NULL Salida, + 1 OK, + 'Inventario calculado' Alias, + '' Referencia, 0 id, + 1 F5 + UNION ALL + SELECT * + FROM historicalPast + WHERE Fecha >= vDate + ) p1; + + DROP TEMPORARY TABLE historicalPast; +END$$ +DELIMITER ; \ No newline at end of file From 68846d30184961cd92704a65c95617b58876ee40 Mon Sep 17 00:00:00 2001 From: ivanm Date: Tue, 5 Mar 2024 13:43:03 +0100 Subject: [PATCH 02/13] refs #6499 Refactor historico_multiple --- .../procedures/absoluteInventoryHistory.sql | 109 ++++++------ .../procedures/multipleInventoryHistory.sql | 161 ++++++++++++++++++ 2 files changed, 216 insertions(+), 54 deletions(-) create mode 100644 db/routines/vn/procedures/multipleInventoryHistory.sql diff --git a/db/routines/vn/procedures/absoluteInventoryHistory.sql b/db/routines/vn/procedures/absoluteInventoryHistory.sql index 427b9ba51..f1a317598 100644 --- a/db/routines/vn/procedures/absoluteInventoryHistory.sql +++ b/db/routines/vn/procedures/absoluteInventoryHistory.sql @@ -1,13 +1,13 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`( - vIdArticle INT, vWarehouse INT, vDate DATETIME) + vItemFk INT, vWarehouse INT, vDate DATETIME) BEGIN /** * Calcula y proporciona un historial de inventario absoluto * para un artículo específico en un almacén dado * hasta una fecha determinada. * -* @param vIdArticle Id de artículo +* @param vItemFk Id de artículo * @param vWarehouse Almacén * @param vDate Fecha */ @@ -16,84 +16,85 @@ BEGIN SET vToday = util.VN_CURDATE(); - CREATE OR REPLACE TEMPORARY TABLE historicalPast - ENGINE = MEMORY + CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast + ENGINE = MEMORY SELECT * FROM ( - SELECT tr.landed Fecha, - b.quantity Entrada, - NULL Salida, - (tr.isReceived != FALSE) OK, - s.name Alias, - e.invoiceNumber Referencia, + SELECT tr.landed `date`, + b.quantity input, + NULL `output`, + (tr.isReceived != FALSE) ok, + s.name alias, + e.invoiceNumber reference, e.id id, - tr.isDelivered F5 + tr.isDelivered f5 FROM buy b - JOIN entry e ON e.id = b.entryFk + JOIN `entry` e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk - JOIN supplier s ON s.id = e.supplierFk + JOIN supplier s ON s.id = e.supplierFk WHERE tr.landed >= '2001-01-01' AND s.id <> 4 AND vWarehouse IN (tr.warehouseInFk, 0) - AND b.itemFk = vIdArticle - AND e.isExcludedFromAvailable = 0 - AND e.isRaid = 0 + AND b.itemFk = vItemFk + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid UNION ALL - SELECT tr.shipped Fecha, - NULL Entrada, - b.quantity Salida, - tr.isDelivered OK, - s.name Alias, - e.invoiceNumber Referencia, + SELECT tr.shipped `date`, + NULL input, + b.quantity `output`, + tr.isDelivered ok, + s.name alias, + e.invoiceNumber reference, e.id id, - tr.isDelivered F5 + tr.isDelivered f5 FROM buy b - JOIN entry e ON e.id = b.entryFk + JOIN `entry` e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk - JOIN supplier s ON s.id = e.supplierFk + JOIN supplier s ON s.id = e.supplierFk WHERE tr.shipped >= '2001-01-01' AND vWarehouse = tr.warehouseOutFk AND s.id <> 4 - AND b.itemFk = vIdArticle - AND e.isExcludedFromAvailable = 0 - AND e.isRaid = 0 + AND b.itemFk = vItemFk + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid UNION ALL - SELECT t.shipped Fecha, - NULL Entrada, - m.quantity Salida, - (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) OK, - t.nickname Alias, - t.refFk Referencia, + SELECT t.shipped `date`, + NULL input, + m.quantity `output`, + (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok, + t.nickname alias, + t.refFk reference, t.id, t.isPrinted FROM sale m - JOIN Tickets T USING (Id_Ticket) - JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente - WHERE T.Fecha >= '2001-01-01' - AND M.Id_Article = vIdArticle - AND vWarehouse IN (T.warehouse_id , 0) + JOIN ticket t ON t.id = m.ticketFk + JOIN client c ON c.id = t.clientFk + WHERE t.shipped >= '2001-01-01' + AND m.itemFk = vItemFk + AND vWarehouse IN (t.warehouseFk , 0) ) t1 - ORDER BY Fecha, Entrada DESC, OK DESC; + ORDER BY `date`, input DESC, ok DESC; - SELECT sum(Entrada) - sum(Salida) INTO vCalculatedInventory - FROM historicalPast - WHERE Fecha < vDate; + SELECT sum(input) - sum(`output`) INTO vCalculatedInventory + FROM tHistoricalPast + WHERE `date` < vDate; SELECT p1.*, NULL v_virtual FROM( - SELECT vDate Fecha, - vCalculatedInventory Entrada, - NULL Salida, - 1 OK, - 'Inventario calculado' Alias, - '' Referencia, 0 id, - 1 F5 + SELECT vDate `date`, + vCalculatedInventory input, + NULL `output`, + 1 ok, + 'Inventario calculado' alias, + '' reference, + 0 id, + 1 f5 UNION ALL - SELECT * - FROM historicalPast - WHERE Fecha >= vDate + SELECT * + FROM tHistoricalPast + WHERE `date` >= vDate ) p1; - DROP TEMPORARY TABLE historicalPast; + DROP TEMPORARY TABLE tHistoricalPast; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/multipleInventoryHistory.sql b/db/routines/vn/procedures/multipleInventoryHistory.sql new file mode 100644 index 000000000..bd399e889 --- /dev/null +++ b/db/routines/vn/procedures/multipleInventoryHistory.sql @@ -0,0 +1,161 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`( + vItemFk INT) +BEGIN +/** +* Calcula y proporciona un historial de inventario detallado +* para un artículo dividiendo la información +* por almacén. +* +* @param vItemFk Artículo +*/ + DECLARE vDateInventory DATETIME; + + SELECT inventoried INTO vDateInventory FROM config; + + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory1; + + CREATE TEMPORARY TABLE tMultipleHistory1 + SELECT DATE(`date`) `date`, + input, + `output`, + ok, + reference, + history.id, + warehouse, + `name` warehouseName + FROM ( + SELECT tr.landed `date`, + c.quantity input, + NULL `output`, + IF(warehouseInFk = 44, 1, warehouseInFk) warehouse, + (tr.isReceived <> FALSE) ok, + e.invoiceNumber reference, + e.id id + FROM buy c + JOIN `entry` e ON e.id = c.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.landed >= vDateInventory + AND c.itemFk = vItemFk + AND NOT e.isRaid + AND c.quantity <> 0 + UNION ALL + SELECT tr.shipped `date`, + NULL input, + c.quantity `output`, + warehouseOutFk warehouse, + tr.isDelivered ok, + e.invoiceNumber reference, + e.id id + FROM buy c + JOIN `entry` e ON e.id = c.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.shipped >= vDateInventory + AND c.itemFk = vItemFk + AND NOT e.isRaid + AND c.quantity <> 0 + UNION ALL + SELECT t.shipped `date`, + NULL input, + m.quantity `output`, + warehouseInFk warehouse, + (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok, + t.refFk reference, + t.id id + FROM sale m + JOIN ticket t ON t.id = m.ticketFk + WHERE t.shipped >= vDateInventory + AND m.itemFk = vItemFk + ) history + JOIN warehouse ON warehouse.id = history.warehouse + ORDER BY `date`, input DESC, ok DESC; + + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory3; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory4; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory5; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory6; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory7; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory8; + CREATE TEMPORARY TABLE tMultipleHistory2 SELECT * FROM tMultipleHistory1 WHERE warehouse = 19; + CREATE TEMPORARY TABLE tMultipleHistory3 SELECT * FROM tMultipleHistory1 WHERE warehouse = 7; + CREATE TEMPORARY TABLE tMultipleHistory4 SELECT * FROM tMultipleHistory1 WHERE warehouse = 60; + CREATE TEMPORARY TABLE tMultipleHistory5 SELECT * FROM tMultipleHistory1 WHERE warehouse = 5; + CREATE TEMPORARY TABLE tMultipleHistory6 SELECT * FROM tMultipleHistory1 WHERE warehouse = 17; + CREATE TEMPORARY TABLE tMultipleHistory7 SELECT * FROM tMultipleHistory1 WHERE warehouse = 37; + CREATE TEMPORARY TABLE tMultipleHistory8 SELECT * FROM tMultipleHistory1 WHERE warehouse = 55; + + SELECT * + FROM ( + SELECT `date`, input BOGinput, `output` BOGoutput, ok BOGok, reference BOGreference, id BOGid, + NULL VNHinput, NULL VNHoutput, NULL VNHok, NULL VNHreference, NULL VNHid, + NULL ALGinput, NULL ALGoutput, NULL ALGok, NULL ALGreference, NULL ALGid, + NULL MADinput, NULL MADoutput, NULL MADok, NULL MADreference, NULL MADid, + NULL MCFinput, NULL MCFoutput, NULL MCFok, NULL MCFreference, NULL MCFid, + NULL VILinput, NULL VILoutput, NULL VILok, NULL VILreference, NULL VILid, + NULL BARinput, NULL BARoutput, NULL BARok, NULL BARreference, NULL BARid + FROM tMultipleHistory2 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory3 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory4 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory5 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory6 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory7 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id + FROM tMultipleHistory8 + ) sub + ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL, MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL; +END$$ +DELIMITER ; \ No newline at end of file From f215ce5f05e4812a477fd1d6c3bf1d602c447275 Mon Sep 17 00:00:00 2001 From: ivanm Date: Tue, 5 Mar 2024 14:33:16 +0100 Subject: [PATCH 03/13] refs #6498 Delete procedures vn2008 and grant vn procs --- .../vn2008/procedures/historico_absoluto.sql | 91 -------- .../vn2008/procedures/historico_multiple.sql | 206 ------------------ .../10932-azureEucalyptus/00-firstScript.sql | 2 + 3 files changed, 2 insertions(+), 297 deletions(-) delete mode 100644 db/routines/vn2008/procedures/historico_absoluto.sql delete mode 100644 db/routines/vn2008/procedures/historico_multiple.sql create mode 100644 db/versions/10932-azureEucalyptus/00-firstScript.sql diff --git a/db/routines/vn2008/procedures/historico_absoluto.sql b/db/routines/vn2008/procedures/historico_absoluto.sql deleted file mode 100644 index 1a7e1dbfa..000000000 --- a/db/routines/vn2008/procedures/historico_absoluto.sql +++ /dev/null @@ -1,91 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_absoluto`(IN idART INT, IN wh INT, IN datfecha DATETIME) -BEGIN - - DECLARE inv_calculado INT; - DECLARE inv INT; - DECLARE today DATETIME; - DECLARE fecha_inv DATETIME; - - SET today = util.VN_CURDATE(); - - CREATE OR REPLACE TEMPORARY TABLE historico_pasado - SELECT * - FROM ( - SELECT TR.landing Fecha, - C.Cantidad Entrada, - NULL Salida, - (TR.received != FALSE) OK, - P.Proveedor Alias, - E.Referencia Referencia, - E.Id_Entrada id, - TR.delivered F5 - FROM Compres C -- mirar perque no entra en received - INNER JOIN Entradas E USING (Id_Entrada) - INNER JOIN travel TR ON TR.id = E.travel_id - INNER JOIN Proveedores P USING (Id_Proveedor) - WHERE TR.landing >= '2001-01-01' - AND Id_proveedor <> 4 - AND wh IN (TR.warehouse_id , 0) - AND C.Id_Article = idART - AND E.Inventario = 0 - AND E.Redada = 0 - UNION ALL - SELECT TR.shipment Fecha, - NULL Entrada, - C.Cantidad Salida, - TR.delivered OK, - P.Proveedor Alias, - E.Referencia Referencia, - E.Id_Entrada id, - TR.delivered F5 - FROM Compres C - INNER JOIN Entradas E USING (Id_Entrada) - INNER JOIN travel TR ON TR.id = E.travel_id - INNER JOIN Proveedores P USING (Id_Proveedor) - WHERE TR.shipment >= '2001-01-01' - AND wh = TR.warehouse_id_out - AND Id_Proveedor <> 4 - AND C.Id_Article = idART - AND E.Inventario = 0 - AND E.Redada = 0 - UNION ALL - SELECT T.Fecha Fecha, - NULL Entrada, - M.Cantidad Salida, - (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK, - T.Alias Alias, - T.Factura Referencia, - T.Id_Ticket, - T.PedidoImpreso - FROM Movimientos M - INNER JOIN Tickets T USING (Id_Ticket) - JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente - WHERE T.Fecha >= '2001-01-01' - AND M.Id_Article = idART - AND wh IN (T.warehouse_id , 0) - ) t1 - ORDER BY Fecha, Entrada DESC, OK DESC; - - SELECT sum(Entrada) - sum(Salida) INTO inv_calculado - FROM historico_pasado - WHERE Fecha < datfecha; - - SELECT p1.*, NULL v_virtual - FROM( - SELECT datfecha Fecha, - inv_calculado Entrada, - NULL Salida, - 1 OK, - 'Inventario calculado' Alias, - '' Referencia, 0 id, - 1 F5 - UNION ALL - SELECT * - FROM historico_pasado - WHERE Fecha >= datfecha - ) p1; - - DROP TEMPORARY TABLE historico_pasado; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/historico_multiple.sql b/db/routines/vn2008/procedures/historico_multiple.sql deleted file mode 100644 index ae4045a34..000000000 --- a/db/routines/vn2008/procedures/historico_multiple.sql +++ /dev/null @@ -1,206 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_multiple`(IN vItemFk INT) -BEGIN - - DECLARE vDateInventory DATETIME; - - SELECT Fechainventario INTO vDateInventory FROM tblContadores; - - SET @a = 0; - - DROP TEMPORARY TABLE IF EXISTS hm1; - - CREATE TEMPORARY TABLE hm1 - SELECT DATE(Fecha) as Fecha, - Entrada, - Salida, - OK, - Referencia, - Historia.id, - - wh, - - `name` as wh_name - - FROM - - ( SELECT TR.landing as Fecha, - C.Cantidad as Entrada, - NULL as Salida, - - IF(warehouse_id = 44, 1, warehouse_id) as wh, - (TR.received != FALSE) as OK, - E.Referencia as Referencia, - E.Id_Entrada as id - - - - FROM Compres C - INNER JOIN Entradas E USING (Id_Entrada) - INNER JOIN travel TR ON TR.id = E.travel_id - WHERE TR.landing >= vDateInventory - AND C.Id_Article = vItemFk - AND E.Redada = 0 - - AND C.Cantidad <> 0 - - UNION ALL - - SELECT TR.shipment as Fecha, - NULL as Entrada, - C.Cantidad as Salida, - warehouse_id_out as wh, - TR.delivered as OK, - E.Referencia as Referencia, - E.Id_Entrada as id - - FROM Compres C - INNER JOIN Entradas E USING (Id_Entrada) - INNER JOIN travel TR ON TR.id = E.travel_id - WHERE TR.shipment >= vDateInventory - AND C.Id_Article = vItemFk - - AND E.Redada = 0 - - AND C.Cantidad <> 0 - - UNION ALL - - SELECT T.Fecha as Fecha, - NULL as Entrada, - M.Cantidad as Salida, - warehouse_id as wh, - (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) as OK, - T.Factura as Referencia, - T.Id_Ticket as id - - FROM Movimientos M - INNER JOIN Tickets T USING (Id_Ticket) - WHERE T.Fecha >= vDateInventory - AND M.Id_Article = vItemFk - - ) AS Historia - - INNER JOIN warehouse ON warehouse.id = Historia.wh - ORDER BY Fecha, Entrada DESC, OK DESC; - - - DROP TEMPORARY TABLE IF EXISTS hm2; - DROP TEMPORARY TABLE IF EXISTS hm3; - DROP TEMPORARY TABLE IF EXISTS hm4; - DROP TEMPORARY TABLE IF EXISTS hm5; - DROP TEMPORARY TABLE IF EXISTS hm6; - DROP TEMPORARY TABLE IF EXISTS hm7; - DROP TEMPORARY TABLE IF EXISTS hm8; - CREATE TEMPORARY TABLE hm2 SELECT * FROM hm1 WHERE wh = 19; - CREATE TEMPORARY TABLE hm3 SELECT * FROM hm1 WHERE wh = 7; - CREATE TEMPORARY TABLE hm4 SELECT * FROM hm1 WHERE wh = 60; - CREATE TEMPORARY TABLE hm5 SELECT * FROM hm1 WHERE wh = 5; - CREATE TEMPORARY TABLE hm6 SELECT * FROM hm1 WHERE wh = 17; - CREATE TEMPORARY TABLE hm7 SELECT * FROM hm1 WHERE wh = 37; - CREATE TEMPORARY TABLE hm8 SELECT * FROM hm1 WHERE wh = 55; - - SELECT * FROM - - ( - - SELECT Fecha, Entrada as BOGEntrada, Salida as BOGSalida, OK as BOGOK, Referencia as BOGReferencia, id as BOGid, - - NULL AS VNHEntrada, NULL AS VNHSalida, NULL AS VNHOK, NULL AS VNHReferencia, NULL AS VNHid, - - NULL AS ALGEntrada, NULL AS ALGSalida, NULL AS ALGOK, NULL AS ALGReferencia, NULL AS ALGid, - - NULL AS MADEntrada, NULL AS MADSalida, NULL AS MADOK, NULL AS MADReferencia, NULL AS MADid, - - NULL AS MCFEntrada, NULL AS MCFSalida, NULL AS MCFOK, NULL AS MCFReferencia, NULL AS MCFid, - - NULL AS VILEntrada, NULL AS VILSalida, NULL AS VILOK, NULL AS VILReferencia, NULL AS VILid, - - NULL AS BAREntrada, NULL AS BARSalida, NULL AS BAROK, NULL AS BARReferencia, NULL AS BARid - - FROM hm2 - - - UNION ALL - - SELECT Fecha - , NULL, NULL, NULL, NULL, NULL - ,Entrada, Salida, OK, Referencia, id - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - FROM hm3 - - - - UNION ALL - - SELECT Fecha - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , Entrada, Salida, OK, Referencia, id - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - FROM hm4 - - UNION ALL - - SELECT Fecha - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , Entrada, Salida, OK, Referencia, id - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - FROM hm5 - - UNION ALL - - SELECT Fecha - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , Entrada, Salida, OK, Referencia, id - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - FROM hm6 - - UNION ALL - - SELECT Fecha - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , Entrada, Salida, OK, Referencia, id - , NULL, NULL, NULL, NULL, NULL - - - FROM hm7 - - UNION ALL - - SELECT Fecha - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , NULL, NULL, NULL, NULL, NULL - , Entrada, Salida, OK, Referencia, id - - FROM hm8 - - ) sub - - ORDER BY Fecha, BOGEntrada IS NULL, VNHEntrada IS NULL, ALGEntrada IS NULL, MADEntrada IS NULL, MCFEntrada IS NULL, VILEntrada IS NULL, BAREntrada IS NULL; - -END$$ -DELIMITER ; diff --git a/db/versions/10932-azureEucalyptus/00-firstScript.sql b/db/versions/10932-azureEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..55eea3211 --- /dev/null +++ b/db/versions/10932-azureEucalyptus/00-firstScript.sql @@ -0,0 +1,2 @@ +GRANT EXECUTE ON PROCEDURE vn.absoluteInventoryHistory TO buyer; +GRANT EXECUTE ON PROCEDURE vn.multipleInventoryHistory TO buyer; From 354ecfaa1684d1f17db20d092ce9821a849219d9 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 6 Mar 2024 09:00:21 +0100 Subject: [PATCH 04/13] refs #6498 Arreglar grant y tabs --- .../procedures/absoluteInventoryHistory.sql | 4 +- .../procedures/multipleInventoryHistory.sql | 206 +++++++++--------- .../10932-azureEucalyptus/00-firstScript.sql | 20 ++ 3 files changed, 125 insertions(+), 105 deletions(-) diff --git a/db/routines/vn/procedures/absoluteInventoryHistory.sql b/db/routines/vn/procedures/absoluteInventoryHistory.sql index f1a317598..a1e143185 100644 --- a/db/routines/vn/procedures/absoluteInventoryHistory.sql +++ b/db/routines/vn/procedures/absoluteInventoryHistory.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`( - vItemFk INT, vWarehouse INT, vDate DATETIME) + vItemFk INT, vWarehouse INT, vDate DATETIME) BEGIN /** * Calcula y proporciona un historial de inventario absoluto @@ -72,7 +72,7 @@ BEGIN WHERE t.shipped >= '2001-01-01' AND m.itemFk = vItemFk AND vWarehouse IN (t.warehouseFk , 0) - ) t1 + ) t1 ORDER BY `date`, input DESC, ok DESC; SELECT sum(input) - sum(`output`) INTO vCalculatedInventory diff --git a/db/routines/vn/procedures/multipleInventoryHistory.sql b/db/routines/vn/procedures/multipleInventoryHistory.sql index bd399e889..b15cab549 100644 --- a/db/routines/vn/procedures/multipleInventoryHistory.sql +++ b/db/routines/vn/procedures/multipleInventoryHistory.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`( - vItemFk INT) + vItemFk INT) BEGIN /** * Calcula y proporciona un historial de inventario detallado @@ -17,58 +17,58 @@ BEGIN CREATE TEMPORARY TABLE tMultipleHistory1 SELECT DATE(`date`) `date`, - input, + input, `output`, ok, reference, history.id, warehouse, `name` warehouseName - FROM ( - SELECT tr.landed `date`, + FROM ( + SELECT tr.landed `date`, c.quantity input, NULL `output`, IF(warehouseInFk = 44, 1, warehouseInFk) warehouse, (tr.isReceived <> FALSE) ok, e.invoiceNumber reference, - e.id id - FROM buy c - JOIN `entry` e ON e.id = c.entryFk - JOIN travel tr ON tr.id = e.travelFk - WHERE tr.landed >= vDateInventory - AND c.itemFk = vItemFk - AND NOT e.isRaid - AND c.quantity <> 0 - UNION ALL - SELECT tr.shipped `date`, + e.id id + FROM buy c + JOIN `entry` e ON e.id = c.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.landed >= vDateInventory + AND c.itemFk = vItemFk + AND NOT e.isRaid + AND c.quantity <> 0 + UNION ALL + SELECT tr.shipped `date`, NULL input, c.quantity `output`, - warehouseOutFk warehouse, + tr.warehouseOutFk warehouse, tr.isDelivered ok, e.invoiceNumber reference, e.id id - FROM buy c - JOIN `entry` e ON e.id = c.entryFk - JOIN travel tr ON tr.id = e.travelFk - WHERE tr.shipped >= vDateInventory - AND c.itemFk = vItemFk - AND NOT e.isRaid - AND c.quantity <> 0 - UNION ALL - SELECT t.shipped `date`, + FROM buy c + JOIN `entry` e ON e.id = c.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.shipped >= vDateInventory + AND c.itemFk = vItemFk + AND NOT e.isRaid + AND c.quantity <> 0 + UNION ALL + SELECT t.shipped `date`, NULL input, m.quantity `output`, - warehouseInFk warehouse, + tr.warehouseInFk warehouse, (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok, t.refFk reference, t.id id - FROM sale m - JOIN ticket t ON t.id = m.ticketFk - WHERE t.shipped >= vDateInventory - AND m.itemFk = vItemFk - ) history - JOIN warehouse ON warehouse.id = history.warehouse - ORDER BY `date`, input DESC, ok DESC; + FROM sale m + JOIN ticket t ON t.id = m.ticketFk + WHERE t.shipped >= vDateInventory + AND m.itemFk = vItemFk + ) history + JOIN warehouse ON warehouse.id = history.warehouse + ORDER BY `date`, input DESC, ok DESC; DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2; DROP TEMPORARY TABLE IF EXISTS tMultipleHistory3; @@ -86,76 +86,76 @@ BEGIN CREATE TEMPORARY TABLE tMultipleHistory8 SELECT * FROM tMultipleHistory1 WHERE warehouse = 55; SELECT * - FROM ( - SELECT `date`, input BOGinput, `output` BOGoutput, ok BOGok, reference BOGreference, id BOGid, - NULL VNHinput, NULL VNHoutput, NULL VNHok, NULL VNHreference, NULL VNHid, - NULL ALGinput, NULL ALGoutput, NULL ALGok, NULL ALGreference, NULL ALGid, - NULL MADinput, NULL MADoutput, NULL MADok, NULL MADreference, NULL MADid, - NULL MCFinput, NULL MCFoutput, NULL MCFok, NULL MCFreference, NULL MCFid, - NULL VILinput, NULL VILoutput, NULL VILok, NULL VILreference, NULL VILid, - NULL BARinput, NULL BARoutput, NULL BARok, NULL BARreference, NULL BARid - FROM tMultipleHistory2 - UNION ALL - SELECT `date`, - NULL, NULL, NULL, NULL, NULL, - input, `output`, ok, reference, id, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL - FROM tMultipleHistory3 - UNION ALL - SELECT `date`, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - input, `output`, ok, reference, id, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL - FROM tMultipleHistory4 - UNION ALL - SELECT `date`, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - input, `output`, ok, reference, id, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL - FROM tMultipleHistory5 - UNION ALL - SELECT `date`, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - input, `output`, ok, reference, id, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL - FROM tMultipleHistory6 - UNION ALL - SELECT `date`, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - input, `output`, ok, reference, id, - NULL, NULL, NULL, NULL, NULL - FROM tMultipleHistory7 - UNION ALL - SELECT `date`, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - input, `output`, ok, reference, id - FROM tMultipleHistory8 - ) sub - ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL, MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL; + FROM ( + SELECT `date`, input BOGinput, `output` BOGoutput, ok BOGok, reference BOGreference, id BOGid, + NULL VNHinput, NULL VNHoutput, NULL VNHok, NULL VNHreference, NULL VNHid, + NULL ALGinput, NULL ALGoutput, NULL ALGok, NULL ALGreference, NULL ALGid, + NULL MADinput, NULL MADoutput, NULL MADok, NULL MADreference, NULL MADid, + NULL MCFinput, NULL MCFoutput, NULL MCFok, NULL MCFreference, NULL MCFid, + NULL VILinput, NULL VILoutput, NULL VILok, NULL VILreference, NULL VILid, + NULL BARinput, NULL BARoutput, NULL BARok, NULL BARreference, NULL BARid + FROM tMultipleHistory2 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory3 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory4 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory5 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory6 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id, + NULL, NULL, NULL, NULL, NULL + FROM tMultipleHistory7 + UNION ALL + SELECT `date`, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + input, `output`, ok, reference, id + FROM tMultipleHistory8 + ) sub + ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL, MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/versions/10932-azureEucalyptus/00-firstScript.sql b/db/versions/10932-azureEucalyptus/00-firstScript.sql index 55eea3211..399819cc4 100644 --- a/db/versions/10932-azureEucalyptus/00-firstScript.sql +++ b/db/versions/10932-azureEucalyptus/00-firstScript.sql @@ -1,2 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`( + vItemFk INT) +BEGIN + DECLARE vDateInventory DATETIME; + SELECT inventoried INTO vDateInventory FROM config; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`( + vItemFk INT, vWarehouse INT, vDate DATETIME) +BEGIN + DECLARE vCalculatedInventory INT; + SET vCalculatedInventory = 0; + +END$$ +DELIMITER ; + GRANT EXECUTE ON PROCEDURE vn.absoluteInventoryHistory TO buyer; GRANT EXECUTE ON PROCEDURE vn.multipleInventoryHistory TO buyer; From 7947d6644e5de63988e8845185b7d968efb997ca Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 6 Mar 2024 12:44:59 +0100 Subject: [PATCH 05/13] refs #6498 Correcion errores --- .../procedures/absoluteInventoryHistory.sql | 25 ++++++++++--------- .../procedures/multipleInventoryHistory.sql | 24 ++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/absoluteInventoryHistory.sql b/db/routines/vn/procedures/absoluteInventoryHistory.sql index a1e143185..7dce6e252 100644 --- a/db/routines/vn/procedures/absoluteInventoryHistory.sql +++ b/db/routines/vn/procedures/absoluteInventoryHistory.sql @@ -1,6 +1,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`( - vItemFk INT, vWarehouse INT, vDate DATETIME) + vItemFk INT, + vWarehouseFk INT, + vDate DATETIME +) BEGIN /** * Calcula y proporciona un historial de inventario absoluto @@ -8,13 +11,11 @@ BEGIN * hasta una fecha determinada. * * @param vItemFk Id de artículo -* @param vWarehouse Almacén +* @param vWarehouseFk Id de almacén * @param vDate Fecha */ DECLARE vCalculatedInventory INT; - DECLARE vToday DATETIME; - - SET vToday = util.VN_CURDATE(); + DECLARE vToday DATETIME DEFAULT util.VN_CURDATE(); CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast ENGINE = MEMORY @@ -23,7 +24,7 @@ BEGIN SELECT tr.landed `date`, b.quantity input, NULL `output`, - (tr.isReceived != FALSE) ok, + tr.isReceived ok, s.name alias, e.invoiceNumber reference, e.id id, @@ -34,7 +35,7 @@ BEGIN JOIN supplier s ON s.id = e.supplierFk WHERE tr.landed >= '2001-01-01' AND s.id <> 4 - AND vWarehouse IN (tr.warehouseInFk, 0) + AND vWarehouseFk IN (tr.warehouseInFk, 0) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT e.isRaid @@ -52,7 +53,7 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk JOIN supplier s ON s.id = e.supplierFk WHERE tr.shipped >= '2001-01-01' - AND vWarehouse = tr.warehouseOutFk + AND vWarehouseFk = tr.warehouseOutFk AND s.id <> 4 AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable @@ -61,7 +62,7 @@ BEGIN SELECT t.shipped `date`, NULL input, m.quantity `output`, - (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok, + (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok, t.nickname alias, t.refFk reference, t.id, @@ -71,16 +72,16 @@ BEGIN JOIN client c ON c.id = t.clientFk WHERE t.shipped >= '2001-01-01' AND m.itemFk = vItemFk - AND vWarehouse IN (t.warehouseFk , 0) + AND vWarehouseFk IN (t.warehouseFk , 0) ) t1 ORDER BY `date`, input DESC, ok DESC; - SELECT sum(input) - sum(`output`) INTO vCalculatedInventory + SELECT SUM(input) - SUM(`output`) INTO vCalculatedInventory FROM tHistoricalPast WHERE `date` < vDate; SELECT p1.*, NULL v_virtual - FROM( + FROM ( SELECT vDate `date`, vCalculatedInventory input, NULL `output`, diff --git a/db/routines/vn/procedures/multipleInventoryHistory.sql b/db/routines/vn/procedures/multipleInventoryHistory.sql index b15cab549..ec151a6ff 100644 --- a/db/routines/vn/procedures/multipleInventoryHistory.sql +++ b/db/routines/vn/procedures/multipleInventoryHistory.sql @@ -29,16 +29,16 @@ BEGIN c.quantity input, NULL `output`, IF(warehouseInFk = 44, 1, warehouseInFk) warehouse, - (tr.isReceived <> FALSE) ok, + tr.isReceived ok, e.invoiceNumber reference, - e.id id + e.id FROM buy c JOIN `entry` e ON e.id = c.entryFk JOIN travel tr ON tr.id = e.travelFk WHERE tr.landed >= vDateInventory AND c.itemFk = vItemFk AND NOT e.isRaid - AND c.quantity <> 0 + AND c.quantity UNION ALL SELECT tr.shipped `date`, NULL input, @@ -46,20 +46,20 @@ BEGIN tr.warehouseOutFk warehouse, tr.isDelivered ok, e.invoiceNumber reference, - e.id id + e.id FROM buy c JOIN `entry` e ON e.id = c.entryFk JOIN travel tr ON tr.id = e.travelFk WHERE tr.shipped >= vDateInventory AND c.itemFk = vItemFk AND NOT e.isRaid - AND c.quantity <> 0 + AND c.quantity UNION ALL SELECT t.shipped `date`, NULL input, m.quantity `output`, tr.warehouseInFk warehouse, - (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok, + (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok, t.refFk reference, t.id id FROM sale m @@ -70,13 +70,8 @@ BEGIN JOIN warehouse ON warehouse.id = history.warehouse ORDER BY `date`, input DESC, ok DESC; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory3; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory4; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory5; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory6; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory7; - DROP TEMPORARY TABLE IF EXISTS tMultipleHistory8; + DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2, tMultipleHistory3, + tMultipleHistory4, tMultipleHistory5, tMultipleHistory6, tMultipleHistory7, tMultipleHistory8; CREATE TEMPORARY TABLE tMultipleHistory2 SELECT * FROM tMultipleHistory1 WHERE warehouse = 19; CREATE TEMPORARY TABLE tMultipleHistory3 SELECT * FROM tMultipleHistory1 WHERE warehouse = 7; CREATE TEMPORARY TABLE tMultipleHistory4 SELECT * FROM tMultipleHistory1 WHERE warehouse = 60; @@ -156,6 +151,7 @@ BEGIN input, `output`, ok, reference, id FROM tMultipleHistory8 ) sub - ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL, MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL; + ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL, + MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL; END$$ DELIMITER ; \ No newline at end of file From 6b2533cfb122ddd832ae9c6a447fe5bbac8b96fa Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 6 Mar 2024 15:16:55 +0100 Subject: [PATCH 06/13] refs #6498 correccion errores 2 --- .../procedures/absoluteInventoryHistory.sql | 41 ++++++++++--------- .../procedures/multipleInventoryHistory.sql | 31 +++++++------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/db/routines/vn/procedures/absoluteInventoryHistory.sql b/db/routines/vn/procedures/absoluteInventoryHistory.sql index 7dce6e252..627b7c8be 100644 --- a/db/routines/vn/procedures/absoluteInventoryHistory.sql +++ b/db/routines/vn/procedures/absoluteInventoryHistory.sql @@ -16,6 +16,7 @@ BEGIN */ DECLARE vCalculatedInventory INT; DECLARE vToday DATETIME DEFAULT util.VN_CURDATE(); + DECLARE vStartDate DATE DEFAULT '2001-01-01'; CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast ENGINE = MEMORY @@ -33,46 +34,46 @@ BEGIN JOIN `entry` e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk JOIN supplier s ON s.id = e.supplierFk - WHERE tr.landed >= '2001-01-01' - AND s.id <> 4 + WHERE tr.landed >= vStartDate + AND s.id <> (SELECT supplierFk FROM inventoryConfig) AND vWarehouseFk IN (tr.warehouseInFk, 0) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT e.isRaid UNION ALL - SELECT tr.shipped `date`, - NULL input, - b.quantity `output`, - tr.isDelivered ok, - s.name alias, - e.invoiceNumber reference, - e.id id, - tr.isDelivered f5 + SELECT tr.shipped, + NULL, + b.quantity, + tr.isDelivered, + s.name, + e.invoiceNumber, + e.id, + tr.isDelivered FROM buy b JOIN `entry` e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk JOIN supplier s ON s.id = e.supplierFk - WHERE tr.shipped >= '2001-01-01' + WHERE tr.shipped >= vStartDate AND vWarehouseFk = tr.warehouseOutFk - AND s.id <> 4 + AND s.id <> (SELECT supplierFk FROM inventoryConfig) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT e.isRaid UNION ALL - SELECT t.shipped `date`, - NULL input, - m.quantity `output`, - (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok, - t.nickname alias, - t.refFk reference, + SELECT t.shipped, + NULL, + m.quantity, + (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL), + t.nickname, + t.refFk, t.id, t.isPrinted FROM sale m JOIN ticket t ON t.id = m.ticketFk JOIN client c ON c.id = t.clientFk - WHERE t.shipped >= '2001-01-01' + WHERE t.shipped >= vStartDate AND m.itemFk = vItemFk - AND vWarehouseFk IN (t.warehouseFk , 0) + AND vWarehouseFk IN (t.warehouseFk, 0) ) t1 ORDER BY `date`, input DESC, ok DESC; diff --git a/db/routines/vn/procedures/multipleInventoryHistory.sql b/db/routines/vn/procedures/multipleInventoryHistory.sql index ec151a6ff..dc19e615a 100644 --- a/db/routines/vn/procedures/multipleInventoryHistory.sql +++ b/db/routines/vn/procedures/multipleInventoryHistory.sql @@ -1,6 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`( - vItemFk INT) + vItemFk INT +) BEGIN /** * Calcula y proporciona un historial de inventario detallado @@ -28,7 +29,7 @@ BEGIN SELECT tr.landed `date`, c.quantity input, NULL `output`, - IF(warehouseInFk = 44, 1, warehouseInFk) warehouse, + tr.warehouseInFk warehouse, tr.isReceived ok, e.invoiceNumber reference, e.id @@ -40,12 +41,12 @@ BEGIN AND NOT e.isRaid AND c.quantity UNION ALL - SELECT tr.shipped `date`, - NULL input, - c.quantity `output`, - tr.warehouseOutFk warehouse, - tr.isDelivered ok, - e.invoiceNumber reference, + SELECT tr.shipped, + NULL, + c.quantity, + tr.warehouseOutFk, + tr.isDelivered, + e.invoiceNumber, e.id FROM buy c JOIN `entry` e ON e.id = c.entryFk @@ -55,13 +56,13 @@ BEGIN AND NOT e.isRaid AND c.quantity UNION ALL - SELECT t.shipped `date`, - NULL input, - m.quantity `output`, - tr.warehouseInFk warehouse, - (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok, - t.refFk reference, - t.id id + SELECT t.shipped, + NULL, + m.quantity, + t.warehouseFk, + (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL), + t.refFk, + t.id FROM sale m JOIN ticket t ON t.id = m.ticketFk WHERE t.shipped >= vDateInventory From d53a053ccb9aed3e50f916a63daf77c1b9f39419 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 20 Mar 2024 13:07:02 +0100 Subject: [PATCH 07/13] refactor: refs #6923 Deteted procs --- .../vn2008/procedures/add_awb_component.sql | 61 ------------------- .../vn2008/procedures/agencyModeImbalance.sql | 50 --------------- 2 files changed, 111 deletions(-) delete mode 100644 db/routines/vn2008/procedures/add_awb_component.sql delete mode 100644 db/routines/vn2008/procedures/agencyModeImbalance.sql diff --git a/db/routines/vn2008/procedures/add_awb_component.sql b/db/routines/vn2008/procedures/add_awb_component.sql deleted file mode 100644 index e75290b4b..000000000 --- a/db/routines/vn2008/procedures/add_awb_component.sql +++ /dev/null @@ -1,61 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`add_awb_component`(IN vAwbFk SMALLINT) -BEGIN - - DECLARE vShipped DATE; - DECLARE vHasStems BOOLEAN; - - SELECT t.shipped, IF(a.stems, TRUE, FALSE) - INTO vShipped, vHasStems - FROM vn.travel t - JOIN vn.awb a ON a.id = t.awbFk - WHERE awbFk = vAwbFk - LIMIT 1; - - INSERT IGNORE INTO awb_component (awb_id,Id_Proveedor,awb_component_type_id,awb_role_id,awb_unit_id,value,Id_Moneda) - SELECT id, Id_Proveedor, awb_component_type_id, awb_role_id,awb_unit_id, LEAST(GREATEST(value1, IFNULL(min_value, value1)), IFNULL(max_value, value1)), Id_Moneda - FROM ( - SELECT a.id, - IFNULL(act.carguera_id, - CASE awb_role_id - WHEN 1 THEN a.carguera_id - WHEN 2 THEN a.transitario_id - WHEN 3 THEN f.airline_id - END - ) Id_Proveedor, - act.awb_component_type_id, - act.awb_role_id, - act.awb_unit_id, - value * - CASE awb_unit_id - WHEN '1000Tj-20' THEN ((CAST(stems AS SIGNED) - 20000)/1000) + (min_value / value) - WHEN '1000Tj-10' THEN ((CAST(stems AS SIGNED) - 10000)/1000) + (min_value / value) - WHEN '100GW' THEN peso/100 - WHEN 'AWB' THEN 1 -- No action - WHEN 'FB' THEN hb/2 - WHEN 'GW' THEN peso - WHEN 'TW' THEN GREATEST(peso,volume_weight) - WHEN 'PN' THEN LEAST(90, value + a.propertyNumber * 10) - END value1, - value, - act.Id_Moneda, - act.min_value, - act.max_value - FROM awb a - JOIN flight f ON f.flight_id = a.flight_id - LEFT JOIN awb_component_template act ON - ((IFNULL(act.carguera_id, a.carguera_id) = a.carguera_id AND awb_role_id = 1) - OR (IFNULL(act.carguera_id, a.transitario_id) = a.transitario_id AND awb_role_id = 2) - OR (IFNULL(act.airline_id, f.airline_id) = f.airline_id AND awb_role_id = 3) - OR (awb_role_id = 4)) - AND IFNULL(act.airport_out, f.airport_out) = f.airport_out - AND IFNULL(act.airport_in, f.airport_in) = f.airport_in - AND IFNULL(act.airline_id, f.airline_id) = f.airline_id - AND INSTR(IFNULL(act.days, WEEKDAY(vShipped) + 1),WEEKDAY(vShipped) + 1) - JOIN awb_component_type acty ON acty.awb_component_type_id = act.awb_component_type_id - WHERE a.id = vAwbFk AND Fecha <= vShipped - AND (vHasStems = TRUE OR acty.hasStems) - ORDER BY Fecha DESC, act.days DESC LIMIT 10000000000000000000 - ) t; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/agencyModeImbalance.sql b/db/routines/vn2008/procedures/agencyModeImbalance.sql deleted file mode 100644 index 89706f0d2..000000000 --- a/db/routines/vn2008/procedures/agencyModeImbalance.sql +++ /dev/null @@ -1,50 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`agencyModeImbalance`(vStarted DATE, vEnded DATE) -BEGIN -/** - * Devuelve el valor de los precios teorico, practico de las agencias - * y si ademas es de mrw lo compara con su fichero previamente procesado - * - * @param vEktFk Identificador de edi.ekt - */ - DECLARE vEndedDayEnd DATETIME; - - SET vEndedDayEnd = util.dayEnd(vEnded); - - SELECT t.id ticketFk,t.addressFk, - CAST(v.amount AS DECIMAL (10,2)) AS VN, - CAST(v.amount - e.shipping_charge AS DECIMAL (10,2)) AS Difer, - CAST(mrwPrice AS DECIMAL (10,2)) mrwPrice, - CAST(e.shipping_charge - mrwPrice AS DECIMAL (10,2)) mrwDifference, - CAST(e.shipping_charge AS DECIMAL (10,2)) AS teorico, - CAST(e.extraCharge AS DECIMAL (10,2)) AS extraCharge, - t.packages, t.clientFk, - t.zoneFk, a.provinceFk, mrwCount - FROM vn.ticket t - LEFT JOIN - (SELECT ticketFk, SUM(amount) amount, fc.shipped - FROM vn.sale_freightComponent fc - JOIN vn.ticket t ON t.id = fc.ticketFk - JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk - WHERE fc.shipped BETWEEN vStarted AND vEndedDayEnd - GROUP BY ticketFk) v ON t.id = v.ticketFk - LEFT JOIN (SELECT t.id, - SUM(t.zonePrice) shipping_charge, - SUM(IFNULL(aex.price,0)) extraCharge - FROM vn.ticket t - LEFT JOIN vn.expedition e ON e.ticketFk = t.id - LEFT JOIN vn.packaging p ON p.id = e.packagingFk - JOIN tmp.agencyMode amc ON amc.agencyModeFk = t.agencyModeFk - JOIN vn.agencyMode am ON am.id = amc.agencyModeFk - LEFT JOIN vn.agencyExtraCharge aex ON p.width+p.depth+p.height BETWEEN aex.sizeMin AND aex.sizeMax AND aex.agencyFk = am.agencyFk - WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd - GROUP BY t.id - ) e ON t.id = e.id - LEFT JOIN (SELECT ticketFk, SUM(price) mrwPrice, COUNT(*) mrwCount - FROM vn.mrw - GROUP BY ticketFk) mrw ON mrw.ticketFk = t.id - JOIN vn.address a ON a.id = t.addressFk - JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk - WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd; -END$$ -DELIMITER ; From 1cd495df06984f6d43d5bd60f96cc765bd06649b Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 21 Mar 2024 09:25:33 +0100 Subject: [PATCH 08/13] fix: refs #7018 Fix invoiceInTax_recalc --- db/routines/vn/procedures/invoiceInTax_recalc.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/invoiceInTax_recalc.sql b/db/routines/vn/procedures/invoiceInTax_recalc.sql index 3b5ce5247..8c4015bc3 100644 --- a/db/routines/vn/procedures/invoiceInTax_recalc.sql +++ b/db/routines/vn/procedures/invoiceInTax_recalc.sql @@ -11,7 +11,7 @@ BEGIN */ DECLARE vRate DOUBLE DEFAULT 1; DECLARE vDated DATE; - DECLARE vExpenseFk INT; + DECLARE vExpenseFk VARCHAR(10); SELECT MAX(rr.dated) INTO vDated FROM referenceRate rr From d0067c80967b9a8b20b0cb696922b89869fd756f Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 21 Mar 2024 11:30:10 +0100 Subject: [PATCH 09/13] ticket #167473 Hotfix --- db/routines/bs/procedures/ventas_contables_add.sql | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index 12b2738f3..9e2b75f6d 100644 --- a/db/routines/bs/procedures/ventas_contables_add.sql +++ b/db/routines/bs/procedures/ventas_contables_add.sql @@ -23,7 +23,7 @@ BEGIN ENGINE = MEMORY SELECT Id_Ticket FROM vn2008.Tickets t - JOIN vn.invoiceOut io ON io.id = t.Factura + JOIN vn.invoiceOut io ON io.`ref` = t.Factura WHERE year(io.issued) = vYear AND month(io.issued) = vMonth; @@ -47,12 +47,7 @@ BEGIN , tp.reino_id , a.tipo_id , t.empresa_id - , a.expenseFk - + IF(e.empresa_grupo = e2.empresa_grupo - ,1 - ,IF(e2.empresa_grupo,2,0) - ) * 100000 - + tp.reino_id * 1000 as Gasto + , a.expenseFk gasto FROM vn2008.Movimientos m JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna From 535dd406250ddd6b0764142e6a7681b9d51e8b6d Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 21 Mar 2024 12:06:59 +0100 Subject: [PATCH 10/13] fix: refs #7018 Fix invoiceInTax_recalc --- db/routines/vn/procedures/invoiceInTax_recalc.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/invoiceInTax_recalc.sql b/db/routines/vn/procedures/invoiceInTax_recalc.sql index 3b5ce5247..40fd98378 100644 --- a/db/routines/vn/procedures/invoiceInTax_recalc.sql +++ b/db/routines/vn/procedures/invoiceInTax_recalc.sql @@ -11,18 +11,20 @@ BEGIN */ DECLARE vRate DOUBLE DEFAULT 1; DECLARE vDated DATE; - DECLARE vExpenseFk INT; + DECLARE vCurrencyFk INT; + DECLARE vExpenseFk VARCHAR(10); - SELECT MAX(rr.dated) INTO vDated + SELECT MAX(rr.dated), ii.currencyFk INTO vDated, vCurrencyFk FROM referenceRate rr JOIN invoiceIn ii ON ii.id = vInvoiceInFk WHERE rr.dated <= ii.issued AND rr.currencyFk = ii.currencyFk; - IF vDated THEN + IF vDated AND vCurrencyFk THEN SELECT `value` INTO vRate FROM referenceRate - WHERE dated = vDated; + WHERE dated = vDated + AND currencyFk = vCurrencyFk; END IF; DELETE FROM invoiceInTax WHERE invoiceInFk = vInvoiceInFk; From ee67820c20b2257c2358b81607b0474470c96168 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 21 Mar 2024 12:14:48 +0100 Subject: [PATCH 11/13] refactor: refs #7018 Fix invoiceInTax_recalc --- db/routines/vn/procedures/invoiceInTax_recalc.sql | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/db/routines/vn/procedures/invoiceInTax_recalc.sql b/db/routines/vn/procedures/invoiceInTax_recalc.sql index 40fd98378..4e20b01d3 100644 --- a/db/routines/vn/procedures/invoiceInTax_recalc.sql +++ b/db/routines/vn/procedures/invoiceInTax_recalc.sql @@ -10,22 +10,15 @@ BEGIN * @param vInvoiceInFk Id de factura recibida */ DECLARE vRate DOUBLE DEFAULT 1; - DECLARE vDated DATE; - DECLARE vCurrencyFk INT; DECLARE vExpenseFk VARCHAR(10); - SELECT MAX(rr.dated), ii.currencyFk INTO vDated, vCurrencyFk + SELECT `value` INTO vRate FROM referenceRate rr JOIN invoiceIn ii ON ii.id = vInvoiceInFk WHERE rr.dated <= ii.issued - AND rr.currencyFk = ii.currencyFk; - - IF vDated AND vCurrencyFk THEN - SELECT `value` INTO vRate - FROM referenceRate - WHERE dated = vDated - AND currencyFk = vCurrencyFk; - END IF; + AND rr.currencyFk = ii.currencyFk + ORDER BY dated DESC + LIMIT 1; DELETE FROM invoiceInTax WHERE invoiceInFk = vInvoiceInFk; From ece94c2bd124a4b7668550a5dd6f7043bdfa702c Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 21 Mar 2024 12:39:39 +0100 Subject: [PATCH 12/13] ref #5034 remove e2e --- e2e/paths/14-account/05_connections.spec.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/e2e/paths/14-account/05_connections.spec.js b/e2e/paths/14-account/05_connections.spec.js index 89b286101..49d5f612d 100644 --- a/e2e/paths/14-account/05_connections.spec.js +++ b/e2e/paths/14-account/05_connections.spec.js @@ -22,12 +22,4 @@ describe('Account Connections path', () => { expect(firstResult).toContain(account); }); - - it('should kill this connection and then get redirected to the login page', async() => { - await page.waitToClick(selectors.accountConnections.deleteFirstConnection); - await page.waitToClick(selectors.globalItems.acceptButton); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Your session has expired, please login again'); - }); }); From 2b26153bfa597fcd84f200a292f03aa2daad672c Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 21 Mar 2024 12:52:04 +0100 Subject: [PATCH 13/13] refactor: refs #7018 Requested changes --- db/routines/bs/procedures/ventas_contables_add.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index 9e2b75f6d..66c012a19 100644 --- a/db/routines/bs/procedures/ventas_contables_add.sql +++ b/db/routines/bs/procedures/ventas_contables_add.sql @@ -47,7 +47,12 @@ BEGIN , tp.reino_id , a.tipo_id , t.empresa_id - , a.expenseFk gasto + , a.expenseFk + + IF(e.empresa_grupo = e2.empresa_grupo + ,1 + ,IF(e2.empresa_grupo,2,0) + ) * 100000 + + tp.reino_id * 1000 as Gasto FROM vn2008.Movimientos m JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna