From 6f4c0f655ded04e0ab53c04482221b2e17acfdc5 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 2 Feb 2024 08:05:17 +0100 Subject: [PATCH 01/17] feat: #6392 migrado de database --- .../bs/procedures/ventas_contables_add.sql | 34 +++++++------- .../10862-navyHydrangea/00-firstScript.sql | 11 +++++ .../01-ventasContablesPk.sql | 5 ++ .../02-balance_nest_tree.sql | 45 ++++++++++++++++++ .../10862-navyHydrangea/03-updateExpense.sql | 46 +++++++++++++++++++ .../10862-navyHydrangea/04-updateItem.sql | 2 + .../05-updateGastosResumen copy.sql | 46 +++++++++++++++++++ .../06-updateVentasContables.sql | 38 +++++++++++++++ 8 files changed, 210 insertions(+), 17 deletions(-) create mode 100644 db/versions/10862-navyHydrangea/00-firstScript.sql create mode 100644 db/versions/10862-navyHydrangea/01-ventasContablesPk.sql create mode 100644 db/versions/10862-navyHydrangea/02-balance_nest_tree.sql create mode 100644 db/versions/10862-navyHydrangea/03-updateExpense.sql create mode 100644 db/versions/10862-navyHydrangea/04-updateItem.sql create mode 100644 db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql create mode 100644 db/versions/10862-navyHydrangea/06-updateVentasContables.sql diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index d8e963e3e..8e2a85582 100644 --- a/db/routines/bs/procedures/ventas_contables_add.sql +++ b/db/routines/bs/procedures/ventas_contables_add.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_contables_add`(IN vYear INT, IN vMonth INT) BEGIN - + /** * Reemplaza las ventas contables del último año. * Es el origen de datos para el balance de Entradas @@ -13,8 +13,8 @@ BEGIN DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; - DELETE FROM bs.ventas_contables - WHERE year = vYear + DELETE FROM bs.ventas_contables + WHERE year = vYear AND month = vMonth; DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; @@ -25,7 +25,7 @@ BEGIN FROM vn2008.Tickets t JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura WHERE year(f.Fecha) = vYear - AND month(f.Fecha) = vMonth; + AND month(f.Fecha) = vMonth; INSERT INTO bs.ventas_contables(year , month @@ -35,7 +35,7 @@ BEGIN , tipo_id , empresa_id , gasto) - + SELECT vYear , vMonth , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) @@ -47,13 +47,13 @@ BEGIN , tp.reino_id , a.tipo_id , t.empresa_id - , 7000000000 + , a.expenseFk + IF(e.empresa_grupo = e2.empresa_grupo ,1 ,IF(e2.empresa_grupo,2,0) - ) * 1000000 - + tp.reino_id * 10000 as Gasto - FROM vn2008.Movimientos m + ) * 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 JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente @@ -67,7 +67,7 @@ BEGIN AND m.Descuento <> 100 AND a.tipo_id != TIPO_PATRIMONIAL GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto; - + INSERT INTO bs.ventas_contables(year , month , venta @@ -86,17 +86,17 @@ BEGIN ) as grupo , NULL , NULL - , t.companyFk + , t.companyFk , 7050000000 - FROM vn.ticketService ts + FROM vn.ticketService ts JOIN vn.ticket t ON ts.ticketFk = t.id - JOIN vn.address a on a.id = t.addressFk - JOIN vn.client cl on cl.id = a.clientFk + JOIN vn.address a on a.id = t.addressFk + JOIN vn.client cl on cl.id = a.clientFk JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id - JOIN vn.company c on c.id = t.companyFk + JOIN vn.company c on c.id = t.companyFk LEFT JOIN vn.company c2 on c2.clientFk = cl.id - GROUP BY grupo, t.companyFk ; - + GROUP BY grupo, t.companyFk ; + DROP TEMPORARY TABLE tmp.ticket_list; END$$ DELIMITER ; diff --git a/db/versions/10862-navyHydrangea/00-firstScript.sql b/db/versions/10862-navyHydrangea/00-firstScript.sql new file mode 100644 index 000000000..3553aa3aa --- /dev/null +++ b/db/versions/10862-navyHydrangea/00-firstScript.sql @@ -0,0 +1,11 @@ +DELETE FROM vn2008.Gastos + WHERE Id_Gasto='' AND Gasto IS NULL AND isWithheld=FALSE; +UPDATE vn.expense + SET id='7002090000' + WHERE id='7002009000'; +UPDATE vn.expense + SET id='7001090000' + WHERE id='7001009000'; +UPDATE vn2008.balance_nest_tree + SET Id_Gasto='7001090000' + WHERE Id_Gasto='7001009000'; diff --git a/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql b/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql new file mode 100644 index 000000000..0ef62c405 --- /dev/null +++ b/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql @@ -0,0 +1,5 @@ +-- Eliminar la clave primaria actual +ALTER TABLE bs.ventas_contables DROP PRIMARY KEY; + +-- Agregar la nueva clave primaria incluyendo el campo `gasto` +ALTER TABLE bs.ventas_contables ADD PRIMARY KEY (`year`, `month`, `grupo`, `reino_id`, `tipo_id`, `empresa_id`, `gasto`); diff --git a/db/versions/10862-navyHydrangea/02-balance_nest_tree.sql b/db/versions/10862-navyHydrangea/02-balance_nest_tree.sql new file mode 100644 index 000000000..5318d8041 --- /dev/null +++ b/db/versions/10862-navyHydrangea/02-balance_nest_tree.sql @@ -0,0 +1,45 @@ +UPDATE vn2008.balance_nest_tree +SET Id_Gasto = CASE Id_Gasto + WHEN 7000010000 THEN 7001001000 + WHEN 7000020000 THEN 7001002000 + WHEN 7000030000 THEN 7001003000 + WHEN 7000040000 THEN 7001004000 + WHEN 7000050000 THEN 7001005000 + WHEN 7000060000 THEN 7001006000 + WHEN 7000070000 THEN 7001007000 + WHEN 7002060000 THEN 7001206000 + WHEN 7002070000 THEN 7001207000 + WHEN 7002030000 THEN 7001203000 + WHEN 7002040000 THEN 7001204000 + WHEN 7002050000 THEN 7001205000 + WHEN 7002020000 THEN 7001202000 + WHEN 7002010000 THEN 7001201000 + WHEN 7001060000 THEN 7001106000 + WHEN 7001070000 THEN 7001107000 + WHEN 7001030000 THEN 7001103000 + WHEN 7001040000 THEN 7001104000 + WHEN 7001050000 THEN 7001105000 + WHEN 7001020000 THEN 7001102000 + WHEN 7001010000 THEN 7001101000 + WHEN 7000080000 THEN 7000008000 + WHEN 7001080000 THEN 7000108000 + WHEN 7002080000 THEN 7000208000 + WHEN 7000090000 THEN 7000009000 + WHEN 7000100000 THEN 7000010000 + WHEN 7002090000 THEN 7000209000 + WHEN 7002100000 THEN 7000210000 + WHEN 7001090000 THEN 7000109000 + WHEN 7001100000 THEN 7000110000 + WHEN 7000120000 THEN 7000012000 + WHEN 7002120000 THEN 7000212000 + WHEN 7000130000 THEN 7000013000 + WHEN 7000140000 THEN 7000014000 + ELSE Id_Gasto +END +WHERE Id_Gasto IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, + 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, + 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, + 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, + 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, + 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/03-updateExpense.sql b/db/versions/10862-navyHydrangea/03-updateExpense.sql new file mode 100644 index 000000000..6226323c2 --- /dev/null +++ b/db/versions/10862-navyHydrangea/03-updateExpense.sql @@ -0,0 +1,46 @@ +/*UPDATE vn.expense +SET id = CASE id + WHEN 7000010000 THEN 7001001000 + WHEN 7000020000 THEN 7001002000 + WHEN 7000030000 THEN 7001003000 + WHEN 7000040000 THEN 7001004000 + WHEN 7000050000 THEN 7001005000 + WHEN 7000060000 THEN 7001006000 + WHEN 7000070000 THEN 7001007000 + WHEN 7002060000 THEN 7001206000 + WHEN 7002070000 THEN 7001207000 + WHEN 7002030000 THEN 7001203000 + WHEN 7002040000 THEN 7001204000 + WHEN 7002050000 THEN 7001205000 + WHEN 7002020000 THEN 7001202000 + WHEN 7002010000 THEN 7001201000 + WHEN 7001060000 THEN 7001106000 + WHEN 7001070000 THEN 7001107000 + WHEN 7001030000 THEN 7001103000 + WHEN 7001040000 THEN 7001104000 + WHEN 7001050000 THEN 7001105000 + WHEN 7001020000 THEN 7001102000 + WHEN 7001010000 THEN 7001101000 + WHEN 7000080000 THEN 7000008000 + WHEN 7001080000 THEN 7000108000 + WHEN 7002080000 THEN 7000208000 + WHEN 7000090000 THEN 7000009000 + WHEN 7000100000 THEN 7000010000 + WHEN 7002090000 THEN 7000209000 + WHEN 7002100000 THEN 7000210000 + WHEN 7001090000 THEN 7000109000 + WHEN 7001100000 THEN 7000110000 + WHEN 7000120000 THEN 7000012000 + WHEN 7002120000 THEN 7000212000 + WHEN 7000130000 THEN 7000013000 + WHEN 7000140000 THEN 7000014000 + ELSE id +END +WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, + 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, + 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, + 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, + 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, + 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000); +*/ diff --git a/db/versions/10862-navyHydrangea/04-updateItem.sql b/db/versions/10862-navyHydrangea/04-updateItem.sql new file mode 100644 index 000000000..8334232bf --- /dev/null +++ b/db/versions/10862-navyHydrangea/04-updateItem.sql @@ -0,0 +1,2 @@ +-- Actualizar los item.expenseFk de produccion propia +-- Tot lo de producció propia porta el productor o *Polpiser o Santa Dorotea* diff --git a/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql b/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql new file mode 100644 index 000000000..4cf9266fe --- /dev/null +++ b/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql @@ -0,0 +1,46 @@ +/*UPDATE vn2008.gastos_resumen +SET Id_Gasto = CASE Id_Gastos + WHEN 7000010000 THEN 7001001000 + WHEN 7000020000 THEN 7001002000 + WHEN 7000030000 THEN 7001003000 + WHEN 7000040000 THEN 7001004000 + WHEN 7000050000 THEN 7001005000 + WHEN 7000060000 THEN 7001006000 + WHEN 7000070000 THEN 7001007000 + WHEN 7002060000 THEN 7001206000 + WHEN 7002070000 THEN 7001207000 + WHEN 7002030000 THEN 7001203000 + WHEN 7002040000 THEN 7001204000 + WHEN 7002050000 THEN 7001205000 + WHEN 7002020000 THEN 7001202000 + WHEN 7002010000 THEN 7001201000 + WHEN 7001060000 THEN 7001106000 + WHEN 7001070000 THEN 7001107000 + WHEN 7001030000 THEN 7001103000 + WHEN 7001040000 THEN 7001104000 + WHEN 7001050000 THEN 7001105000 + WHEN 7001020000 THEN 7001102000 + WHEN 7001010000 THEN 7001101000 + WHEN 7000080000 THEN 7000008000 + WHEN 7001080000 THEN 7000108000 + WHEN 7002080000 THEN 7000208000 + WHEN 7000090000 THEN 7000009000 + WHEN 7000100000 THEN 7000010000 + WHEN 7002090000 THEN 7000209000 + WHEN 7002100000 THEN 7000210000 + WHEN 7001090000 THEN 7000109000 + WHEN 7001100000 THEN 7000110000 + WHEN 7000120000 THEN 7000012000 + WHEN 7002120000 THEN 7000212000 + WHEN 7000130000 THEN 7000013000 + WHEN 7000140000 THEN 7000014000 + ELSE Id_Gastos +END +WHERE Id_Gastos IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, + 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, + 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, + 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, + 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, + 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000); +*/ diff --git a/db/versions/10862-navyHydrangea/06-updateVentasContables.sql b/db/versions/10862-navyHydrangea/06-updateVentasContables.sql new file mode 100644 index 000000000..9587b1663 --- /dev/null +++ b/db/versions/10862-navyHydrangea/06-updateVentasContables.sql @@ -0,0 +1,38 @@ +/*CALL bs.ventas_contables_add(2021, 1); +CALL bs.ventas_contables_add(2021, 2); +CALL bs.ventas_contables_add(2021, 3); +CALL bs.ventas_contables_add(2021, 4); +CALL bs.ventas_contables_add(2021, 5); +CALL bs.ventas_contables_add(2021, 6); +CALL bs.ventas_contables_add(2021, 7); +CALL bs.ventas_contables_add(2021, 8); +CALL bs.ventas_contables_add(2021, 9); +CALL bs.ventas_contables_add(2021, 10); +CALL bs.ventas_contables_add(2021, 11); +CALL bs.ventas_contables_add(2021, 12); +CALL bs.ventas_contables_add(2022, 1); +CALL bs.ventas_contables_add(2022, 2); +CALL bs.ventas_contables_add(2022, 3); +CALL bs.ventas_contables_add(2022, 4); +CALL bs.ventas_contables_add(2022, 5); +CALL bs.ventas_contables_add(2022, 6); +CALL bs.ventas_contables_add(2022, 7); +CALL bs.ventas_contables_add(2022, 8); +CALL bs.ventas_contables_add(2022, 9); +CALL bs.ventas_contables_add(2022, 10); +CALL bs.ventas_contables_add(2022, 11); +CALL bs.ventas_contables_add(2022, 12); +CALL bs.ventas_contables_add(2023, 1); +CALL bs.ventas_contables_add(2023, 2); +CALL bs.ventas_contables_add(2023, 3); +CALL bs.ventas_contables_add(2023, 4); +CALL bs.ventas_contables_add(2023, 5); +CALL bs.ventas_contables_add(2023, 6); +CALL bs.ventas_contables_add(2023, 7); +CALL bs.ventas_contables_add(2023, 8); +CALL bs.ventas_contables_add(2023, 9); +CALL bs.ventas_contables_add(2023, 10); +CALL bs.ventas_contables_add(2023, 11); +CALL bs.ventas_contables_add(2023, 12); +CALL bs.ventas_contables_add(2024, 1); +*/ From 6a738627e7644f81da5052f64f2b9c01624c1933 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 6 Feb 2024 15:42:03 +0100 Subject: [PATCH 02/17] feat: #6392 adaptado a los nuevos nombres --- .../10862-navyHydrangea/00-firstScript.sql | 6 +-- .../02-balanceNestTree.sql | 46 +++++++++++++++++++ .../02-balance_nest_tree.sql | 45 ------------------ .../10862-navyHydrangea/03-updateExpense.sql | 3 +- .../05-updateGastosResumen copy.sql | 5 +- 5 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 db/versions/10862-navyHydrangea/02-balanceNestTree.sql delete mode 100644 db/versions/10862-navyHydrangea/02-balance_nest_tree.sql diff --git a/db/versions/10862-navyHydrangea/00-firstScript.sql b/db/versions/10862-navyHydrangea/00-firstScript.sql index 3553aa3aa..2b79cf5db 100644 --- a/db/versions/10862-navyHydrangea/00-firstScript.sql +++ b/db/versions/10862-navyHydrangea/00-firstScript.sql @@ -6,6 +6,6 @@ UPDATE vn.expense UPDATE vn.expense SET id='7001090000' WHERE id='7001009000'; -UPDATE vn2008.balance_nest_tree - SET Id_Gasto='7001090000' - WHERE Id_Gasto='7001009000'; +UPDATE vn.balanceNestTree + SET expenseFk='7001090000' + WHERE expenseFk='7001009000'; diff --git a/db/versions/10862-navyHydrangea/02-balanceNestTree.sql b/db/versions/10862-navyHydrangea/02-balanceNestTree.sql new file mode 100644 index 000000000..8b606eade --- /dev/null +++ b/db/versions/10862-navyHydrangea/02-balanceNestTree.sql @@ -0,0 +1,46 @@ +UPDATE vn.balanceNestTree + SET expenseFk = + CASE expenseFk + WHEN 7000010000 THEN 7001001000 + WHEN 7000020000 THEN 7001002000 + WHEN 7000030000 THEN 7001003000 + WHEN 7000040000 THEN 7001004000 + WHEN 7000050000 THEN 7001005000 + WHEN 7000060000 THEN 7001006000 + WHEN 7000070000 THEN 7001007000 + WHEN 7002060000 THEN 7001206000 + WHEN 7002070000 THEN 7001207000 + WHEN 7002030000 THEN 7001203000 + WHEN 7002040000 THEN 7001204000 + WHEN 7002050000 THEN 7001205000 + WHEN 7002020000 THEN 7001202000 + WHEN 7002010000 THEN 7001201000 + WHEN 7001060000 THEN 7001106000 + WHEN 7001070000 THEN 7001107000 + WHEN 7001030000 THEN 7001103000 + WHEN 7001040000 THEN 7001104000 + WHEN 7001050000 THEN 7001105000 + WHEN 7001020000 THEN 7001102000 + WHEN 7001010000 THEN 7001101000 + WHEN 7000080000 THEN 7000008000 + WHEN 7001080000 THEN 7000108000 + WHEN 7002080000 THEN 7000208000 + WHEN 7000090000 THEN 7000009000 + WHEN 7000100000 THEN 7000010000 + WHEN 7002090000 THEN 7000209000 + WHEN 7002100000 THEN 7000210000 + WHEN 7001090000 THEN 7000109000 + WHEN 7001100000 THEN 7000110000 + WHEN 7000120000 THEN 7000012000 + WHEN 7002120000 THEN 7000212000 + WHEN 7000130000 THEN 7000013000 + WHEN 7000140000 THEN 7000014000 + ELSE expenseFk + END + WHERE expenseFk IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, + 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, + 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, + 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, + 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, + 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/02-balance_nest_tree.sql b/db/versions/10862-navyHydrangea/02-balance_nest_tree.sql deleted file mode 100644 index 5318d8041..000000000 --- a/db/versions/10862-navyHydrangea/02-balance_nest_tree.sql +++ /dev/null @@ -1,45 +0,0 @@ -UPDATE vn2008.balance_nest_tree -SET Id_Gasto = CASE Id_Gasto - WHEN 7000010000 THEN 7001001000 - WHEN 7000020000 THEN 7001002000 - WHEN 7000030000 THEN 7001003000 - WHEN 7000040000 THEN 7001004000 - WHEN 7000050000 THEN 7001005000 - WHEN 7000060000 THEN 7001006000 - WHEN 7000070000 THEN 7001007000 - WHEN 7002060000 THEN 7001206000 - WHEN 7002070000 THEN 7001207000 - WHEN 7002030000 THEN 7001203000 - WHEN 7002040000 THEN 7001204000 - WHEN 7002050000 THEN 7001205000 - WHEN 7002020000 THEN 7001202000 - WHEN 7002010000 THEN 7001201000 - WHEN 7001060000 THEN 7001106000 - WHEN 7001070000 THEN 7001107000 - WHEN 7001030000 THEN 7001103000 - WHEN 7001040000 THEN 7001104000 - WHEN 7001050000 THEN 7001105000 - WHEN 7001020000 THEN 7001102000 - WHEN 7001010000 THEN 7001101000 - WHEN 7000080000 THEN 7000008000 - WHEN 7001080000 THEN 7000108000 - WHEN 7002080000 THEN 7000208000 - WHEN 7000090000 THEN 7000009000 - WHEN 7000100000 THEN 7000010000 - WHEN 7002090000 THEN 7000209000 - WHEN 7002100000 THEN 7000210000 - WHEN 7001090000 THEN 7000109000 - WHEN 7001100000 THEN 7000110000 - WHEN 7000120000 THEN 7000012000 - WHEN 7002120000 THEN 7000212000 - WHEN 7000130000 THEN 7000013000 - WHEN 7000140000 THEN 7000014000 - ELSE Id_Gasto -END -WHERE Id_Gasto IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, - 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, - 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, - 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, - 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/03-updateExpense.sql b/db/versions/10862-navyHydrangea/03-updateExpense.sql index 6226323c2..bd90faa72 100644 --- a/db/versions/10862-navyHydrangea/03-updateExpense.sql +++ b/db/versions/10862-navyHydrangea/03-updateExpense.sql @@ -1,4 +1,4 @@ -/*UPDATE vn.expense +UPDATE vn.expense SET id = CASE id WHEN 7000010000 THEN 7001001000 WHEN 7000020000 THEN 7001002000 @@ -43,4 +43,3 @@ WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, 7000120000, 7002120000, 7000130000, 7000140000); -*/ diff --git a/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql b/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql index 4cf9266fe..94b7a0385 100644 --- a/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql +++ b/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql @@ -1,4 +1,5 @@ -/*UPDATE vn2008.gastos_resumen +-- en el futuro expenseSummary +UPDATE vn2008.gastos_resumen SET Id_Gasto = CASE Id_Gastos WHEN 7000010000 THEN 7001001000 WHEN 7000020000 THEN 7001002000 @@ -43,4 +44,4 @@ WHERE Id_Gastos IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, 7000120000, 7002120000, 7000130000, 7000140000); -*/ + From 3e8fbce34d5cf6b51223229fcbd6d2d71ca530e4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 8 Feb 2024 11:08:03 +0100 Subject: [PATCH 03/17] feat: #6392 testeado --- ...updateExpense.sql => 02-updateExpense.sql} | 25 ++++++++--------- ...nceNestTree.sql => 03-balanceNestTree.sql} | 27 ++++++++++--------- .../06-updateVentasContables.sql | 3 +-- 3 files changed, 28 insertions(+), 27 deletions(-) rename db/versions/10862-navyHydrangea/{03-updateExpense.sql => 02-updateExpense.sql} (72%) rename db/versions/10862-navyHydrangea/{02-balanceNestTree.sql => 03-balanceNestTree.sql} (70%) diff --git a/db/versions/10862-navyHydrangea/03-updateExpense.sql b/db/versions/10862-navyHydrangea/02-updateExpense.sql similarity index 72% rename from db/versions/10862-navyHydrangea/03-updateExpense.sql rename to db/versions/10862-navyHydrangea/02-updateExpense.sql index bd90faa72..917c2afb5 100644 --- a/db/versions/10862-navyHydrangea/03-updateExpense.sql +++ b/db/versions/10862-navyHydrangea/02-updateExpense.sql @@ -23,17 +23,18 @@ SET id = CASE id WHEN 7001010000 THEN 7001101000 WHEN 7000080000 THEN 7000008000 WHEN 7001080000 THEN 7000108000 - WHEN 7002080000 THEN 7000208000 - WHEN 7000090000 THEN 7000009000 - WHEN 7000100000 THEN 7000010000 - WHEN 7002090000 THEN 7000209000 - WHEN 7002100000 THEN 7000210000 - WHEN 7001090000 THEN 7000109000 - WHEN 7001100000 THEN 7000110000 - WHEN 7000120000 THEN 7000012000 - WHEN 7002120000 THEN 7000212000 - WHEN 7000130000 THEN 7000013000 - WHEN 7000140000 THEN 7000014000 + WHEN 7002080000 THEN 7001208000 + WHEN 7000090000 THEN 7001009000 + WHEN 7000100000 THEN 7001010000 + WHEN 7002090000 THEN 7001209000 + WHEN 7002100000 THEN 7001210000 + WHEN 7001090000 THEN 7001109000 + WHEN 7001100000 THEN 7001110000 + WHEN 7000120000 THEN 7001012000 + WHEN 7002120000 THEN 7001212000 + WHEN 7000130000 THEN 7001013000 + WHEN 7000140000 THEN 7001014000 + WHEN 7000008000 THEN 7040008000 ELSE id END WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, @@ -42,4 +43,4 @@ WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); + 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); diff --git a/db/versions/10862-navyHydrangea/02-balanceNestTree.sql b/db/versions/10862-navyHydrangea/03-balanceNestTree.sql similarity index 70% rename from db/versions/10862-navyHydrangea/02-balanceNestTree.sql rename to db/versions/10862-navyHydrangea/03-balanceNestTree.sql index 8b606eade..0cfb02ff2 100644 --- a/db/versions/10862-navyHydrangea/02-balanceNestTree.sql +++ b/db/versions/10862-navyHydrangea/03-balanceNestTree.sql @@ -23,18 +23,19 @@ UPDATE vn.balanceNestTree WHEN 7001020000 THEN 7001102000 WHEN 7001010000 THEN 7001101000 WHEN 7000080000 THEN 7000008000 - WHEN 7001080000 THEN 7000108000 - WHEN 7002080000 THEN 7000208000 - WHEN 7000090000 THEN 7000009000 - WHEN 7000100000 THEN 7000010000 - WHEN 7002090000 THEN 7000209000 - WHEN 7002100000 THEN 7000210000 - WHEN 7001090000 THEN 7000109000 - WHEN 7001100000 THEN 7000110000 - WHEN 7000120000 THEN 7000012000 - WHEN 7002120000 THEN 7000212000 - WHEN 7000130000 THEN 7000013000 - WHEN 7000140000 THEN 7000014000 + WHEN 7001080000 THEN 7001108000 + WHEN 7002080000 THEN 7001208000 + WHEN 7000090000 THEN 7001009000 + WHEN 7000100000 THEN 7001010000 + WHEN 7002090000 THEN 7001209000 + WHEN 7002100000 THEN 7001210000 + WHEN 7001090000 THEN 7001109000 + WHEN 7001100000 THEN 7001110000 + WHEN 7000120000 THEN 7001012000 + WHEN 7002120000 THEN 7001212000 + WHEN 7000130000 THEN 7001013000 + WHEN 7000140000 THEN 7001014000 + WHEN 7000008000 THEN 7040008000 ELSE expenseFk END WHERE expenseFk IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, @@ -43,4 +44,4 @@ UPDATE vn.balanceNestTree 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); + 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); diff --git a/db/versions/10862-navyHydrangea/06-updateVentasContables.sql b/db/versions/10862-navyHydrangea/06-updateVentasContables.sql index 9587b1663..f59c3e140 100644 --- a/db/versions/10862-navyHydrangea/06-updateVentasContables.sql +++ b/db/versions/10862-navyHydrangea/06-updateVentasContables.sql @@ -1,4 +1,4 @@ -/*CALL bs.ventas_contables_add(2021, 1); +CALL bs.ventas_contables_add(2021, 1); CALL bs.ventas_contables_add(2021, 2); CALL bs.ventas_contables_add(2021, 3); CALL bs.ventas_contables_add(2021, 4); @@ -35,4 +35,3 @@ CALL bs.ventas_contables_add(2023, 10); CALL bs.ventas_contables_add(2023, 11); CALL bs.ventas_contables_add(2023, 12); CALL bs.ventas_contables_add(2024, 1); -*/ From 974228eedd3c99b28ac3bd1cfe4ae24304c6b3b8 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 8 Feb 2024 11:37:15 +0100 Subject: [PATCH 04/17] refactor: refs #5586 Optimized SQL negativeBases --- db/routines/vn/procedures/ticket_getTax.sql | 59 +++++++++---------- .../back/methods/invoiceOut/negativeBases.js | 55 ++++++++--------- 2 files changed, 54 insertions(+), 60 deletions(-) diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql index 7269a1caf..fbdbdc785 100644 --- a/db/routines/vn/procedures/ticket_getTax.sql +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -9,32 +9,31 @@ BEGIN * @return tmp.ticketAmount (ticketFk, taxableBase, tax, code) * @return tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) Impuesto desglosado para cada ticket. */ - DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; - CREATE TEMPORARY TABLE tmp.addressCompany + CREATE OR REPLACE TEMPORARY TABLE tmp.addressCompany (INDEX (addressFk, companyFk)) ENGINE = MEMORY SELECT DISTINCT t.addressFk, t.companyFk FROM tmp.ticket tmpTicket JOIN ticket t ON t.id = tmpTicket.ticketFk; - CALL addressTaxArea (); + CALL addressTaxArea(); IF vTaxArea IS NOT NULL THEN UPDATE tmp.addressTaxArea SET areaFk = vTaxArea; END IF; - /* Solo se calcula la base imponible (taxableBase) y el impuesto se calculará posteriormente - * No se debería cambiar el sistema por problemas con los decimales - */ - DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; - CREATE TEMPORARY TABLE tmp.ticketTax + -- Solo se calcula la base imponible (taxableBase) y + -- el impuesto se calculará posteriormente + -- No se debería cambiar el sistema por problemas con los decimales + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketTax (PRIMARY KEY (ticketFk, code, rate)) ENGINE = MEMORY SELECT * FROM ( SELECT tmpTicket.ticketFk, bp.pgcFk, - SUM(s.quantity * s.price * (100 - s.discount)/100 ) taxableBase, + SUM(s.quantity * s.price * (100 - s.discount) / 100 ) taxableBase, pgc.rate, tc.code, bp.priority @@ -43,22 +42,21 @@ BEGIN JOIN item i ON i.id = s.itemFk JOIN ticket t ON t.id = tmpTicket.ticketFk JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata - ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN itemTaxCountry itc - ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - JOIN bookingPlanner bp - ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = itc.taxClassFk + JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk + AND ata.companyFk = t.companyFk + JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = su.countryFk + JOIN bookingPlanner bp ON bp.countryFk = su.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = itc.taxClassFk JOIN pgc ON pgc.code = bp.pgcFk JOIN taxClass tc ON tc.id = bp.taxClassFk GROUP BY tmpTicket.ticketFk, pgc.code, pgc.rate - HAVING taxableBase <> 0) t3 + HAVING taxableBase + ) t3 ORDER BY priority; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax; - CREATE TEMPORARY TABLE tmp.ticketServiceTax + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax (PRIMARY KEY (ticketFk, code, rate)) ENGINE = MEMORY SELECT tt.ticketFk, @@ -70,24 +68,22 @@ BEGIN JOIN ticketService ts ON ts.ticketFk = tt.ticketFk JOIN ticket t ON t.id = tt.ticketFk JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata - ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN bookingPlanner bp - ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = ts.taxClassFk + JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk + AND ata.companyFk = t.companyFk + JOIN bookingPlanner bp ON bp.countryFk = su.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = ts.taxClassFk JOIN pgc ON pgc.code = bp.pgcFk JOIN taxClass tc ON tc.id = bp.taxClassFk GROUP BY tt.ticketFk, pgc.code - HAVING taxableBase <> 0; + HAVING taxableBase; INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.rate, ts.code FROM tmp.ticketServiceTax ts ON DUPLICATE KEY UPDATE ticketTax.taxableBase = VALUES (taxableBase) + ticketTax.taxableBase ; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; - CREATE TEMPORARY TABLE tmp.ticketAmount + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketAmount (INDEX (ticketFk)) ENGINE = MEMORY SELECT ticketFk, @@ -97,7 +93,8 @@ BEGIN FROM tmp.ticketTax GROUP BY ticketFk, code; - DROP TEMPORARY TABLE tmp.addressCompany; - DROP TEMPORARY TABLE tmp.addressTaxArea; + DROP TEMPORARY TABLE + tmp.addressCompany, + tmp.addressTaxArea; END$$ DELIMITER ; diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 96c789316..0b152441b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -46,23 +46,19 @@ module.exports = Self => { const stmts = []; let stmt; - stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket`); - stmts.push(new ParameterizedSQL( - `CREATE TEMPORARY TABLE tmp.ticket + `CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (KEY (ticketFk)) ENGINE = MEMORY SELECT id ticketFk FROM ticket t - WHERE shipped BETWEEN ? AND ? + WHERE shipped BETWEEN ? AND util.dayEnd(?) AND refFk IS NULL`, [args.from, args.to])); stmts.push(`CALL vn.ticket_getTax(NULL)`); - stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.filter`); stmts.push(new ParameterizedSQL( - `CREATE TEMPORARY TABLE tmp.filter + `CREATE OR REPLACE TEMPORARY TABLE tmp.filter ENGINE = MEMORY - SELECT - co.code company, + SELECT co.code company, cou.country, c.id clientId, c.socialName clientSocialName, @@ -74,27 +70,25 @@ module.exports = Self => { c.isTaxDataChecked, w.id comercialId, CONCAT(w.firstName, ' ', w.lastName) comercialName - FROM vn.ticket t - JOIN vn.company co ON co.id = t.companyFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.country cou ON cou.id = c.countryFk - LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN ( - SELECT ticketFk, taxableBase - FROM tmp.ticketAmount - GROUP BY ticketFk - HAVING taxableBase < 0 - ) negativeBase ON negativeBase.ticketFk = t.id - WHERE t.shipped BETWEEN ? AND ? - AND t.refFk IS NULL - AND c.typeFk IN ('normal','trust') - GROUP BY t.clientFk, negativeBase.taxableBase - HAVING amount < 0`, [args.from, args.to])); + FROM vn.ticket t + JOIN vn.company co ON co.id = t.companyFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.country cou ON cou.id = c.countryFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + LEFT JOIN ( + SELECT ticketFk, taxableBase + FROM tmp.ticketAmount + GROUP BY ticketFk + HAVING taxableBase < 0 + ) negativeBase ON negativeBase.ticketFk = t.id + WHERE t.shipped BETWEEN ? AND util.dayEnd(?) + AND t.refFk IS NULL + AND c.typeFk IN ('normal','trust') + GROUP BY t.clientFk, negativeBase.taxableBase + HAVING amount < 0`, [args.from, args.to])); - stmt = new ParameterizedSQL(` - SELECT f.* - FROM tmp.filter f`); + stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`); if (args.filter) { stmt.merge(conn.makeWhere(args.filter.where)); @@ -104,7 +98,10 @@ module.exports = Self => { const negativeBasesIndex = stmts.push(stmt) - 1; - stmts.push(`DROP TEMPORARY TABLE tmp.filter, tmp.ticket, tmp.ticketTax, tmp.ticketAmount`); + stmts.push(`DROP TEMPORARY TABLE tmp.filter, + tmp.ticket, + tmp.ticketTax, + tmp.ticketAmount`); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql); From 463b3fb6f3d4a37b5c4812ff0919fe04aa6a10a4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 9 Feb 2024 11:35:47 +0100 Subject: [PATCH 05/17] feat: #6392 solveConflicts --- .../10862-navyHydrangea/02-updateExpense.sql | 3 +- .../03-updateExpenseConflict.sql | 6 ++++ ...nceNestTree.sql => 04-balanceNestTree.sql} | 3 +- .../05-balanceNestTreeConflict.sql | 6 ++++ .../{04-updateItem.sql => 06-updateItem.sql} | 0 ...en copy.sql => 07-updateGastosResumen.sql} | 28 +++++++++---------- .../08-updateGastosResumenConflict.sql | 8 ++++++ ...ables.sql => 09-updateVentasContables.sql} | 0 8 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 db/versions/10862-navyHydrangea/03-updateExpenseConflict.sql rename db/versions/10862-navyHydrangea/{03-balanceNestTree.sql => 04-balanceNestTree.sql} (94%) create mode 100644 db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql rename db/versions/10862-navyHydrangea/{04-updateItem.sql => 06-updateItem.sql} (100%) rename db/versions/10862-navyHydrangea/{05-updateGastosResumen copy.sql => 07-updateGastosResumen.sql} (69%) create mode 100644 db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql rename db/versions/10862-navyHydrangea/{06-updateVentasContables.sql => 09-updateVentasContables.sql} (100%) diff --git a/db/versions/10862-navyHydrangea/02-updateExpense.sql b/db/versions/10862-navyHydrangea/02-updateExpense.sql index 917c2afb5..56364a600 100644 --- a/db/versions/10862-navyHydrangea/02-updateExpense.sql +++ b/db/versions/10862-navyHydrangea/02-updateExpense.sql @@ -25,7 +25,6 @@ SET id = CASE id WHEN 7001080000 THEN 7000108000 WHEN 7002080000 THEN 7001208000 WHEN 7000090000 THEN 7001009000 - WHEN 7000100000 THEN 7001010000 WHEN 7002090000 THEN 7001209000 WHEN 7002100000 THEN 7001210000 WHEN 7001090000 THEN 7001109000 @@ -42,5 +41,5 @@ WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, + 7002090000, 7002100000, 7001090000, 7001100000, 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); diff --git a/db/versions/10862-navyHydrangea/03-updateExpenseConflict.sql b/db/versions/10862-navyHydrangea/03-updateExpenseConflict.sql new file mode 100644 index 000000000..0e008081b --- /dev/null +++ b/db/versions/10862-navyHydrangea/03-updateExpenseConflict.sql @@ -0,0 +1,6 @@ +UPDATE vn.expense +SET id = CASE id + WHEN 7000100000 THEN 7001010000 + ELSE id +END +WHERE id IN (7000100000); diff --git a/db/versions/10862-navyHydrangea/03-balanceNestTree.sql b/db/versions/10862-navyHydrangea/04-balanceNestTree.sql similarity index 94% rename from db/versions/10862-navyHydrangea/03-balanceNestTree.sql rename to db/versions/10862-navyHydrangea/04-balanceNestTree.sql index 0cfb02ff2..e086a656d 100644 --- a/db/versions/10862-navyHydrangea/03-balanceNestTree.sql +++ b/db/versions/10862-navyHydrangea/04-balanceNestTree.sql @@ -26,7 +26,6 @@ UPDATE vn.balanceNestTree WHEN 7001080000 THEN 7001108000 WHEN 7002080000 THEN 7001208000 WHEN 7000090000 THEN 7001009000 - WHEN 7000100000 THEN 7001010000 WHEN 7002090000 THEN 7001209000 WHEN 7002100000 THEN 7001210000 WHEN 7001090000 THEN 7001109000 @@ -43,5 +42,5 @@ UPDATE vn.balanceNestTree 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, + 7002090000, 7002100000, 7001090000, 7001100000, 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); diff --git a/db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql b/db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql new file mode 100644 index 000000000..dddc82888 --- /dev/null +++ b/db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql @@ -0,0 +1,6 @@ +UPDATE vn.balanceNestTree + SET expenseFk = CASE expenseFk + WHEN 7000100000 THEN 7001010000 + ELSE expenseFk + END + WHERE expenseFk IN (7000100000); diff --git a/db/versions/10862-navyHydrangea/04-updateItem.sql b/db/versions/10862-navyHydrangea/06-updateItem.sql similarity index 100% rename from db/versions/10862-navyHydrangea/04-updateItem.sql rename to db/versions/10862-navyHydrangea/06-updateItem.sql diff --git a/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql b/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql similarity index 69% rename from db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql rename to db/versions/10862-navyHydrangea/07-updateGastosResumen.sql index 94b7a0385..70f22c1e6 100644 --- a/db/versions/10862-navyHydrangea/05-updateGastosResumen copy.sql +++ b/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql @@ -23,18 +23,18 @@ SET Id_Gasto = CASE Id_Gastos WHEN 7001020000 THEN 7001102000 WHEN 7001010000 THEN 7001101000 WHEN 7000080000 THEN 7000008000 - WHEN 7001080000 THEN 7000108000 - WHEN 7002080000 THEN 7000208000 - WHEN 7000090000 THEN 7000009000 - WHEN 7000100000 THEN 7000010000 - WHEN 7002090000 THEN 7000209000 - WHEN 7002100000 THEN 7000210000 - WHEN 7001090000 THEN 7000109000 - WHEN 7001100000 THEN 7000110000 - WHEN 7000120000 THEN 7000012000 - WHEN 7002120000 THEN 7000212000 - WHEN 7000130000 THEN 7000013000 - WHEN 7000140000 THEN 7000014000 + WHEN 7001080000 THEN 7001108000 + WHEN 7002080000 THEN 7001208000 + WHEN 7000090000 THEN 7001009000 + WHEN 7002090000 THEN 7001209000 + WHEN 7002100000 THEN 7001210000 + WHEN 7001090000 THEN 7001109000 + WHEN 7001100000 THEN 7001110000 + WHEN 7000120000 THEN 7001012000 + WHEN 7002120000 THEN 7001212000 + WHEN 7000130000 THEN 7001013000 + WHEN 7000140000 THEN 7001014000 + WHEN 7000008000 THEN 7040008000 ELSE Id_Gastos END WHERE Id_Gastos IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, @@ -42,6 +42,6 @@ WHERE Id_Gastos IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7000100000, 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); + 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); diff --git a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql new file mode 100644 index 000000000..82b1aef2d --- /dev/null +++ b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql @@ -0,0 +1,8 @@ +-- en el futuro expenseSummary +UPDATE vn2008.gastos_resumen +SET Id_Gasto = CASE Id_Gastos + WHEN 7000100000 THEN 7000010000 + ELSE Id_Gastos +END +WHERE Id_Gastos IN (7000100000); + diff --git a/db/versions/10862-navyHydrangea/06-updateVentasContables.sql b/db/versions/10862-navyHydrangea/09-updateVentasContables.sql similarity index 100% rename from db/versions/10862-navyHydrangea/06-updateVentasContables.sql rename to db/versions/10862-navyHydrangea/09-updateVentasContables.sql From c81860155288d00050a7d40f3314e6d0cc27255f Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 12 Feb 2024 08:45:47 +0100 Subject: [PATCH 06/17] feat: #6392 constraint solved --- .../10862-navyHydrangea/02-updateExpense.sql | 5 ++--- .../04-balanceNestTree.sql | 5 ++--- .../07-updateGastosResumen.sql | 21 +++++++++---------- .../08-updateGastosResumenConflict.sql | 6 +++--- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/db/versions/10862-navyHydrangea/02-updateExpense.sql b/db/versions/10862-navyHydrangea/02-updateExpense.sql index 56364a600..a44c4c504 100644 --- a/db/versions/10862-navyHydrangea/02-updateExpense.sql +++ b/db/versions/10862-navyHydrangea/02-updateExpense.sql @@ -21,7 +21,7 @@ SET id = CASE id WHEN 7001050000 THEN 7001105000 WHEN 7001020000 THEN 7001102000 WHEN 7001010000 THEN 7001101000 - WHEN 7000080000 THEN 7000008000 + WHEN 7000080000 THEN 7040008000 WHEN 7001080000 THEN 7000108000 WHEN 7002080000 THEN 7001208000 WHEN 7000090000 THEN 7001009000 @@ -33,7 +33,6 @@ SET id = CASE id WHEN 7002120000 THEN 7001212000 WHEN 7000130000 THEN 7001013000 WHEN 7000140000 THEN 7001014000 - WHEN 7000008000 THEN 7040008000 ELSE id END WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, @@ -42,4 +41,4 @@ WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); + 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/04-balanceNestTree.sql b/db/versions/10862-navyHydrangea/04-balanceNestTree.sql index e086a656d..803f88dab 100644 --- a/db/versions/10862-navyHydrangea/04-balanceNestTree.sql +++ b/db/versions/10862-navyHydrangea/04-balanceNestTree.sql @@ -22,7 +22,7 @@ UPDATE vn.balanceNestTree WHEN 7001050000 THEN 7001105000 WHEN 7001020000 THEN 7001102000 WHEN 7001010000 THEN 7001101000 - WHEN 7000080000 THEN 7000008000 + WHEN 7000080000 THEN 7040008000 WHEN 7001080000 THEN 7001108000 WHEN 7002080000 THEN 7001208000 WHEN 7000090000 THEN 7001009000 @@ -34,7 +34,6 @@ UPDATE vn.balanceNestTree WHEN 7002120000 THEN 7001212000 WHEN 7000130000 THEN 7001013000 WHEN 7000140000 THEN 7001014000 - WHEN 7000008000 THEN 7040008000 ELSE expenseFk END WHERE expenseFk IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, @@ -43,4 +42,4 @@ UPDATE vn.balanceNestTree 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); + 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql b/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql index 70f22c1e6..e557cc7d6 100644 --- a/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql +++ b/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql @@ -1,6 +1,6 @@ -- en el futuro expenseSummary UPDATE vn2008.gastos_resumen -SET Id_Gasto = CASE Id_Gastos +SET Id_Gasto = CASE Id_Gasto WHEN 7000010000 THEN 7001001000 WHEN 7000020000 THEN 7001002000 WHEN 7000030000 THEN 7001003000 @@ -22,7 +22,7 @@ SET Id_Gasto = CASE Id_Gastos WHEN 7001050000 THEN 7001105000 WHEN 7001020000 THEN 7001102000 WHEN 7001010000 THEN 7001101000 - WHEN 7000080000 THEN 7000008000 + WHEN 7000080000 THEN 7040008000 WHEN 7001080000 THEN 7001108000 WHEN 7002080000 THEN 7001208000 WHEN 7000090000 THEN 7001009000 @@ -34,14 +34,13 @@ SET Id_Gasto = CASE Id_Gastos WHEN 7002120000 THEN 7001212000 WHEN 7000130000 THEN 7001013000 WHEN 7000140000 THEN 7001014000 - WHEN 7000008000 THEN 7040008000 - ELSE Id_Gastos + ELSE Id_Gasto END -WHERE Id_Gastos IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, - 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, - 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, - 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, - 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000, 7000008000); +WHERE Id_Gasto IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, + 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, + 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, + 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, + 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, + 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql index 82b1aef2d..58722c4a9 100644 --- a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql +++ b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql @@ -1,8 +1,8 @@ -- en el futuro expenseSummary UPDATE vn2008.gastos_resumen -SET Id_Gasto = CASE Id_Gastos +SET Id_Gasto = CASE Id_Gasto WHEN 7000100000 THEN 7000010000 - ELSE Id_Gastos + ELSE Id_Gasto END -WHERE Id_Gastos IN (7000100000); +WHERE Id_Gasto IN (7000100000); From 51afb87122e498280031bbcff35c5928d7bd8560 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 13 Feb 2024 09:54:26 +0100 Subject: [PATCH 07/17] feat: #6392 cambia gasto --- .../10862-navyHydrangea/08-updateGastosResumenConflict.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql index 58722c4a9..b7497d00c 100644 --- a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql +++ b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql @@ -1,7 +1,7 @@ -- en el futuro expenseSummary UPDATE vn2008.gastos_resumen SET Id_Gasto = CASE Id_Gasto - WHEN 7000100000 THEN 7000010000 + WHEN 7000100000 THEN 7001010000 ELSE Id_Gasto END WHERE Id_Gasto IN (7000100000); From bdc6192a7c39784d2c52fce27068c2bda83fba1a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 13 Feb 2024 12:50:39 +0100 Subject: [PATCH 08/17] refactor: refs #5586 Optimized SQL negativeBases --- .../back/methods/invoiceOut/negativeBases.js | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index c40373963..193397b53 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -46,15 +46,6 @@ module.exports = Self => { const stmts = []; let stmt; - stmts.push(new ParameterizedSQL( - `CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM ticket t - WHERE shipped BETWEEN ? AND util.dayEnd(?) - AND refFk IS NULL`, [args.from, args.to])); - stmts.push(`CALL vn.ticket_getTax(NULL)`); stmts.push(new ParameterizedSQL( `CREATE OR REPLACE TEMPORARY TABLE tmp.filter ENGINE = MEMORY @@ -64,8 +55,8 @@ module.exports = Self => { c.socialName clientSocialName, u.nickname workerSocialName, SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount, - negativeBase.taxableBase, - negativeBase.ticketFk, + t.totalWithoutVat taxableBase, + s.ticketFk, c.isActive, c.hasToInvoice, c.isTaxDataChecked, @@ -78,16 +69,10 @@ module.exports = Self => { JOIN vn.country cou ON cou.id = c.countryFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk JOIN account.user u ON u.id = w.id - LEFT JOIN ( - SELECT ticketFk, taxableBase - FROM tmp.ticketAmount - GROUP BY ticketFk - HAVING taxableBase < 0 - ) negativeBase ON negativeBase.ticketFk = t.id - WHERE t.shipped BETWEEN ? AND ? + WHERE t.shipped BETWEEN ? AND util.dayEnd(?) AND t.refFk IS NULL AND c.typeFk IN ('normal','trust') - GROUP BY t.clientFk, negativeBase.taxableBase + GROUP BY t.clientFk, t.totalWithoutVat HAVING amount < 0`, [args.from, args.to])); stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`); @@ -100,10 +85,7 @@ module.exports = Self => { const negativeBasesIndex = stmts.push(stmt) - 1; - stmts.push(`DROP TEMPORARY TABLE tmp.filter, - tmp.ticket, - tmp.ticketTax, - tmp.ticketAmount`); + stmts.push(`DROP TEMPORARY TABLE tmp.filter`); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql); From 92261ebe0d36732315fe48d1d745415834e41819 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 13 Feb 2024 13:09:12 +0100 Subject: [PATCH 09/17] fix: refs #5586 Tests fix --- db/routines/vn/procedures/ticket_getTax.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql index fbdbdc785..b9f5c14e3 100644 --- a/db/routines/vn/procedures/ticket_getTax.sql +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -9,7 +9,10 @@ BEGIN * @return tmp.ticketAmount (ticketFk, taxableBase, tax, code) * @return tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) Impuesto desglosado para cada ticket. */ - CREATE OR REPLACE TEMPORARY TABLE tmp.addressCompany + -- Mantengo el drop porque si no da error en los tests de back de salix + -- Table 'addressCompany' was locked with a READ lock and can't be updated' + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany (INDEX (addressFk, companyFk)) ENGINE = MEMORY SELECT DISTINCT t.addressFk, t.companyFk From 3665db359e75550fb52a7d83c88415d2f537f890 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 14 Feb 2024 09:02:39 +0100 Subject: [PATCH 10/17] feat: #63922 actualiza usando las fk --- .../01-alterGastosResumen.sql | 8 ++++ .../04-balanceNestTree.sql | 45 ------------------ .../05-balanceNestTreeConflict.sql | 6 --- .../07-updateGastosResumen.sql | 46 ------------------- .../08-updateGastosResumenConflict.sql | 8 ---- 5 files changed, 8 insertions(+), 105 deletions(-) create mode 100644 db/versions/10862-navyHydrangea/01-alterGastosResumen.sql delete mode 100644 db/versions/10862-navyHydrangea/04-balanceNestTree.sql delete mode 100644 db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql delete mode 100644 db/versions/10862-navyHydrangea/07-updateGastosResumen.sql delete mode 100644 db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql diff --git a/db/versions/10862-navyHydrangea/01-alterGastosResumen.sql b/db/versions/10862-navyHydrangea/01-alterGastosResumen.sql new file mode 100644 index 000000000..7a90962c4 --- /dev/null +++ b/db/versions/10862-navyHydrangea/01-alterGastosResumen.sql @@ -0,0 +1,8 @@ +ALTER TABLE vn2008.gastos_resumen MODIFY COLUMN Id_Gasto varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; + +DELETE gr.* + FROM vn2008.gastos_resumen gr LEFT JOIN vn.expense e ON gr.Id_Gasto = e.id + WHERE e.id IS NULL AND importe; + +ALTER TABLE vn2008.gastos_resumen + ADD CONSTRAINT gastos_resumen_expense_FKFOREIGN KEY (Id_Gasto) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10862-navyHydrangea/04-balanceNestTree.sql b/db/versions/10862-navyHydrangea/04-balanceNestTree.sql deleted file mode 100644 index 803f88dab..000000000 --- a/db/versions/10862-navyHydrangea/04-balanceNestTree.sql +++ /dev/null @@ -1,45 +0,0 @@ -UPDATE vn.balanceNestTree - SET expenseFk = - CASE expenseFk - WHEN 7000010000 THEN 7001001000 - WHEN 7000020000 THEN 7001002000 - WHEN 7000030000 THEN 7001003000 - WHEN 7000040000 THEN 7001004000 - WHEN 7000050000 THEN 7001005000 - WHEN 7000060000 THEN 7001006000 - WHEN 7000070000 THEN 7001007000 - WHEN 7002060000 THEN 7001206000 - WHEN 7002070000 THEN 7001207000 - WHEN 7002030000 THEN 7001203000 - WHEN 7002040000 THEN 7001204000 - WHEN 7002050000 THEN 7001205000 - WHEN 7002020000 THEN 7001202000 - WHEN 7002010000 THEN 7001201000 - WHEN 7001060000 THEN 7001106000 - WHEN 7001070000 THEN 7001107000 - WHEN 7001030000 THEN 7001103000 - WHEN 7001040000 THEN 7001104000 - WHEN 7001050000 THEN 7001105000 - WHEN 7001020000 THEN 7001102000 - WHEN 7001010000 THEN 7001101000 - WHEN 7000080000 THEN 7040008000 - WHEN 7001080000 THEN 7001108000 - WHEN 7002080000 THEN 7001208000 - WHEN 7000090000 THEN 7001009000 - WHEN 7002090000 THEN 7001209000 - WHEN 7002100000 THEN 7001210000 - WHEN 7001090000 THEN 7001109000 - WHEN 7001100000 THEN 7001110000 - WHEN 7000120000 THEN 7001012000 - WHEN 7002120000 THEN 7001212000 - WHEN 7000130000 THEN 7001013000 - WHEN 7000140000 THEN 7001014000 - ELSE expenseFk - END - WHERE expenseFk IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, - 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, - 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, - 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, - 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql b/db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql deleted file mode 100644 index dddc82888..000000000 --- a/db/versions/10862-navyHydrangea/05-balanceNestTreeConflict.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE vn.balanceNestTree - SET expenseFk = CASE expenseFk - WHEN 7000100000 THEN 7001010000 - ELSE expenseFk - END - WHERE expenseFk IN (7000100000); diff --git a/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql b/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql deleted file mode 100644 index e557cc7d6..000000000 --- a/db/versions/10862-navyHydrangea/07-updateGastosResumen.sql +++ /dev/null @@ -1,46 +0,0 @@ --- en el futuro expenseSummary -UPDATE vn2008.gastos_resumen -SET Id_Gasto = CASE Id_Gasto - WHEN 7000010000 THEN 7001001000 - WHEN 7000020000 THEN 7001002000 - WHEN 7000030000 THEN 7001003000 - WHEN 7000040000 THEN 7001004000 - WHEN 7000050000 THEN 7001005000 - WHEN 7000060000 THEN 7001006000 - WHEN 7000070000 THEN 7001007000 - WHEN 7002060000 THEN 7001206000 - WHEN 7002070000 THEN 7001207000 - WHEN 7002030000 THEN 7001203000 - WHEN 7002040000 THEN 7001204000 - WHEN 7002050000 THEN 7001205000 - WHEN 7002020000 THEN 7001202000 - WHEN 7002010000 THEN 7001201000 - WHEN 7001060000 THEN 7001106000 - WHEN 7001070000 THEN 7001107000 - WHEN 7001030000 THEN 7001103000 - WHEN 7001040000 THEN 7001104000 - WHEN 7001050000 THEN 7001105000 - WHEN 7001020000 THEN 7001102000 - WHEN 7001010000 THEN 7001101000 - WHEN 7000080000 THEN 7040008000 - WHEN 7001080000 THEN 7001108000 - WHEN 7002080000 THEN 7001208000 - WHEN 7000090000 THEN 7001009000 - WHEN 7002090000 THEN 7001209000 - WHEN 7002100000 THEN 7001210000 - WHEN 7001090000 THEN 7001109000 - WHEN 7001100000 THEN 7001110000 - WHEN 7000120000 THEN 7001012000 - WHEN 7002120000 THEN 7001212000 - WHEN 7000130000 THEN 7001013000 - WHEN 7000140000 THEN 7001014000 - ELSE Id_Gasto -END -WHERE Id_Gasto IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000, - 7000060000, 7000070000, 7002060000, 7002070000, 7002030000, - 7002040000, 7002050000, 7002020000, 7002010000, 7001060000, - 7001070000, 7001030000, 7001040000, 7001050000, 7001020000, - 7001010000, 7000080000, 7001080000, 7002080000, 7000090000, - 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); - diff --git a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql b/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql deleted file mode 100644 index b7497d00c..000000000 --- a/db/versions/10862-navyHydrangea/08-updateGastosResumenConflict.sql +++ /dev/null @@ -1,8 +0,0 @@ --- en el futuro expenseSummary -UPDATE vn2008.gastos_resumen -SET Id_Gasto = CASE Id_Gasto - WHEN 7000100000 THEN 7001010000 - ELSE Id_Gasto -END -WHERE Id_Gasto IN (7000100000); - From 05b7c37b94c6c51ecb1fb0c9754de2950f1f1c0b Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 15 Feb 2024 07:49:17 +0100 Subject: [PATCH 11/17] fix: refs #5586 Rollback --- .../back/methods/invoiceOut/negativeBases.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 193397b53..9242ffb8b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -46,6 +46,15 @@ module.exports = Self => { const stmts = []; let stmt; + stmts.push(new ParameterizedSQL( + `CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM ticket t + WHERE shipped BETWEEN ? AND ? + AND refFk IS NULL`, [args.from, args.to])); + stmts.push(`CALL vn.ticket_getTax(NULL)`); stmts.push(new ParameterizedSQL( `CREATE OR REPLACE TEMPORARY TABLE tmp.filter ENGINE = MEMORY @@ -55,8 +64,8 @@ module.exports = Self => { c.socialName clientSocialName, u.nickname workerSocialName, SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount, - t.totalWithoutVat taxableBase, - s.ticketFk, + negativeBase.taxableBase, + negativeBase.ticketFk, c.isActive, c.hasToInvoice, c.isTaxDataChecked, @@ -69,6 +78,12 @@ module.exports = Self => { JOIN vn.country cou ON cou.id = c.countryFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk JOIN account.user u ON u.id = w.id + LEFT JOIN ( + SELECT ticketFk, taxableBase + FROM tmp.ticketAmount + GROUP BY ticketFk + HAVING taxableBase < 0 + ) negativeBase ON negativeBase.ticketFk = t.id WHERE t.shipped BETWEEN ? AND util.dayEnd(?) AND t.refFk IS NULL AND c.typeFk IN ('normal','trust') @@ -85,7 +100,7 @@ module.exports = Self => { const negativeBasesIndex = stmts.push(stmt) - 1; - stmts.push(`DROP TEMPORARY TABLE tmp.filter`); + stmts.push(`DROP TEMPORARY TABLE tmp.filter, tmp.ticket, tmp.ticketTax, tmp.ticketAmount`); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql); From 10bfb7a7d789ecaeb241f03ad5a9cf23ac005da0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 15 Feb 2024 07:52:33 +0100 Subject: [PATCH 12/17] fix: refs #5586 Minor change --- modules/invoiceOut/back/methods/invoiceOut/negativeBases.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 9242ffb8b..993ac2c0e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -52,7 +52,7 @@ module.exports = Self => { ENGINE = MEMORY SELECT id ticketFk FROM ticket t - WHERE shipped BETWEEN ? AND ? + WHERE shipped BETWEEN ? AND util.dayEnd(?) AND refFk IS NULL`, [args.from, args.to])); stmts.push(`CALL vn.ticket_getTax(NULL)`); stmts.push(new ParameterizedSQL( From 5a0ce700b3310f429ee5e8c84a3e5251ab5590aa Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 15 Feb 2024 09:38:34 +0100 Subject: [PATCH 13/17] fix: refs #5586 Requested changes --- modules/invoiceOut/back/methods/invoiceOut/negativeBases.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 993ac2c0e..66440616c 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -87,7 +87,7 @@ module.exports = Self => { WHERE t.shipped BETWEEN ? AND util.dayEnd(?) AND t.refFk IS NULL AND c.typeFk IN ('normal','trust') - GROUP BY t.clientFk, t.totalWithoutVat + GROUP BY t.clientFk, negativeBase.taxableBase HAVING amount < 0`, [args.from, args.to])); stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`); From 27627017c5f6c065815f7061b77527fef65e4b48 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 15 Feb 2024 14:21:49 +0100 Subject: [PATCH 14/17] feat: #6392 fk que faltan --- .../00-alterAgencyTermConfig.sql | 3 ++ ...sResumen.sql => 00-alterGastosResumen.sql} | 7 +++- .../00-alterInvoiceOutTaxConfig.sql | 5 +++ .../00-alterItemGroupToOffer.sql | 5 +++ .../01-ventasContablesPk.sql | 9 +++++ ...ipt.sql => 02-updateExpenseRegularize.sql} | 3 -- ...updateExpense.sql => 03-updateExpense.sql} | 0 ...flict.sql => 04-updateExpenseConflict.sql} | 0 .../10862-navyHydrangea/06-updateItem.sql | 2 - .../09-updateVentasContables.sql | 37 ------------------- 10 files changed, 27 insertions(+), 44 deletions(-) create mode 100644 db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql rename db/versions/10862-navyHydrangea/{01-alterGastosResumen.sql => 00-alterGastosResumen.sql} (60%) create mode 100644 db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql create mode 100644 db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql rename db/versions/10862-navyHydrangea/{00-firstScript.sql => 02-updateExpenseRegularize.sql} (71%) rename db/versions/10862-navyHydrangea/{02-updateExpense.sql => 03-updateExpense.sql} (100%) rename db/versions/10862-navyHydrangea/{03-updateExpenseConflict.sql => 04-updateExpenseConflict.sql} (100%) delete mode 100644 db/versions/10862-navyHydrangea/06-updateItem.sql delete mode 100644 db/versions/10862-navyHydrangea/09-updateVentasContables.sql diff --git a/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql b/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql new file mode 100644 index 000000000..3409b762e --- /dev/null +++ b/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql @@ -0,0 +1,3 @@ +USE vn; +ALTER TABLE vn.agencyTermConfig + ADD CONSTRAINT agencyTermConfig_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10862-navyHydrangea/01-alterGastosResumen.sql b/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql similarity index 60% rename from db/versions/10862-navyHydrangea/01-alterGastosResumen.sql rename to db/versions/10862-navyHydrangea/00-alterGastosResumen.sql index 7a90962c4..307b8f205 100644 --- a/db/versions/10862-navyHydrangea/01-alterGastosResumen.sql +++ b/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql @@ -1,8 +1,11 @@ +USE vn; + ALTER TABLE vn2008.gastos_resumen MODIFY COLUMN Id_Gasto varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; DELETE gr.* FROM vn2008.gastos_resumen gr LEFT JOIN vn.expense e ON gr.Id_Gasto = e.id - WHERE e.id IS NULL AND importe; + WHERE e.id IS NULL; ALTER TABLE vn2008.gastos_resumen - ADD CONSTRAINT gastos_resumen_expense_FKFOREIGN KEY (Id_Gasto) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; + ADD CONSTRAINT gastos_resumen_expense_FK + FOREIGN KEY (Id_Gasto) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql b/db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql new file mode 100644 index 000000000..fc5025c18 --- /dev/null +++ b/db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql @@ -0,0 +1,5 @@ +USE vn; +ALTER TABLE vn.invoiceOutTaxConfig MODIFY COLUMN expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; + +ALTER TABLE vn.invoiceOutTaxConfig + ADD CONSTRAINT invoiceOutTaxConfig_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql b/db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql new file mode 100644 index 000000000..68611c13c --- /dev/null +++ b/db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql @@ -0,0 +1,5 @@ +USE edi; +ALTER TABLE edi.item_groupToOffer MODIFY COLUMN expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '7001000000' NULL; + +ALTER TABLE edi.item_groupToOffer + ADD CONSTRAINT item_groupToOffer_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql b/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql index 0ef62c405..3f8bf2c79 100644 --- a/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql +++ b/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql @@ -1,5 +1,14 @@ +USE vn; -- Eliminar la clave primaria actual ALTER TABLE bs.ventas_contables DROP PRIMARY KEY; -- Agregar la nueva clave primaria incluyendo el campo `gasto` ALTER TABLE bs.ventas_contables ADD PRIMARY KEY (`year`, `month`, `grupo`, `reino_id`, `tipo_id`, `empresa_id`, `gasto`); + +DELETE vc.* FROM bs.ventas_contables vc LEFT JOIN vn.expense e ON e.id = vc.gasto WHERE e.id IS NULL; + +ALTER TABLE bs.ventas_contables + MODIFY COLUMN gasto VARCHAR(10) + CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; + +ALTER TABLE bs.ventas_contables ADD CONSTRAINT ventas_contables_expense_FK FOREIGN KEY (gasto) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10862-navyHydrangea/00-firstScript.sql b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql similarity index 71% rename from db/versions/10862-navyHydrangea/00-firstScript.sql rename to db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql index 2b79cf5db..7b7d1e197 100644 --- a/db/versions/10862-navyHydrangea/00-firstScript.sql +++ b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql @@ -6,6 +6,3 @@ UPDATE vn.expense UPDATE vn.expense SET id='7001090000' WHERE id='7001009000'; -UPDATE vn.balanceNestTree - SET expenseFk='7001090000' - WHERE expenseFk='7001009000'; diff --git a/db/versions/10862-navyHydrangea/02-updateExpense.sql b/db/versions/10862-navyHydrangea/03-updateExpense.sql similarity index 100% rename from db/versions/10862-navyHydrangea/02-updateExpense.sql rename to db/versions/10862-navyHydrangea/03-updateExpense.sql diff --git a/db/versions/10862-navyHydrangea/03-updateExpenseConflict.sql b/db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql similarity index 100% rename from db/versions/10862-navyHydrangea/03-updateExpenseConflict.sql rename to db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql diff --git a/db/versions/10862-navyHydrangea/06-updateItem.sql b/db/versions/10862-navyHydrangea/06-updateItem.sql deleted file mode 100644 index 8334232bf..000000000 --- a/db/versions/10862-navyHydrangea/06-updateItem.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Actualizar los item.expenseFk de produccion propia --- Tot lo de producció propia porta el productor o *Polpiser o Santa Dorotea* diff --git a/db/versions/10862-navyHydrangea/09-updateVentasContables.sql b/db/versions/10862-navyHydrangea/09-updateVentasContables.sql deleted file mode 100644 index f59c3e140..000000000 --- a/db/versions/10862-navyHydrangea/09-updateVentasContables.sql +++ /dev/null @@ -1,37 +0,0 @@ -CALL bs.ventas_contables_add(2021, 1); -CALL bs.ventas_contables_add(2021, 2); -CALL bs.ventas_contables_add(2021, 3); -CALL bs.ventas_contables_add(2021, 4); -CALL bs.ventas_contables_add(2021, 5); -CALL bs.ventas_contables_add(2021, 6); -CALL bs.ventas_contables_add(2021, 7); -CALL bs.ventas_contables_add(2021, 8); -CALL bs.ventas_contables_add(2021, 9); -CALL bs.ventas_contables_add(2021, 10); -CALL bs.ventas_contables_add(2021, 11); -CALL bs.ventas_contables_add(2021, 12); -CALL bs.ventas_contables_add(2022, 1); -CALL bs.ventas_contables_add(2022, 2); -CALL bs.ventas_contables_add(2022, 3); -CALL bs.ventas_contables_add(2022, 4); -CALL bs.ventas_contables_add(2022, 5); -CALL bs.ventas_contables_add(2022, 6); -CALL bs.ventas_contables_add(2022, 7); -CALL bs.ventas_contables_add(2022, 8); -CALL bs.ventas_contables_add(2022, 9); -CALL bs.ventas_contables_add(2022, 10); -CALL bs.ventas_contables_add(2022, 11); -CALL bs.ventas_contables_add(2022, 12); -CALL bs.ventas_contables_add(2023, 1); -CALL bs.ventas_contables_add(2023, 2); -CALL bs.ventas_contables_add(2023, 3); -CALL bs.ventas_contables_add(2023, 4); -CALL bs.ventas_contables_add(2023, 5); -CALL bs.ventas_contables_add(2023, 6); -CALL bs.ventas_contables_add(2023, 7); -CALL bs.ventas_contables_add(2023, 8); -CALL bs.ventas_contables_add(2023, 9); -CALL bs.ventas_contables_add(2023, 10); -CALL bs.ventas_contables_add(2023, 11); -CALL bs.ventas_contables_add(2023, 12); -CALL bs.ventas_contables_add(2024, 1); From 2c1172bd88c2810a9f710708402916c492bafac6 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 19 Feb 2024 13:56:16 +0100 Subject: [PATCH 15/17] feat: #6392 sin gastos --- .../10862-navyHydrangea/02-updateExpenseRegularize.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql index 7b7d1e197..90d865c1d 100644 --- a/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql +++ b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql @@ -1,5 +1,5 @@ -DELETE FROM vn2008.Gastos - WHERE Id_Gasto='' AND Gasto IS NULL AND isWithheld=FALSE; +DELETE FROM vn.expense + WHERE id ='' AND id IS NULL AND isWithheld = FALSE; UPDATE vn.expense SET id='7002090000' WHERE id='7002009000'; From c53ff1243ff9d6898bcc331574e92c622022b70e Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 19 Feb 2024 14:37:36 +0100 Subject: [PATCH 16/17] feat: #6392 no es necesario agencyTermConfig --- db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql diff --git a/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql b/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql deleted file mode 100644 index 3409b762e..000000000 --- a/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql +++ /dev/null @@ -1,3 +0,0 @@ -USE vn; -ALTER TABLE vn.agencyTermConfig - ADD CONSTRAINT agencyTermConfig_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE; From a7c48e9132f5dbc1fbacf51dd289b4fb7a984511 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 19 Feb 2024 15:05:11 +0100 Subject: [PATCH 17/17] feat: #6392 quito de fixtures para que no falle la fk --- db/dump/.dump/data.sql | 2 -- db/dump/fixtures.before.sql | 3 ++- db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql | 3 +++ myt.config.yml | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 8367471bc..6fe6c1414 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -1750,8 +1750,6 @@ USE `vn`; /*!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 `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios'); - INSERT INTO `alertLevel` VALUES ('FREE',0,1); INSERT INTO `alertLevel` VALUES ('ON_PREPARATION',1,1); INSERT INTO `alertLevel` VALUES ('PACKED',2,0); diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 094b956af..43293c9ea 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -653,6 +653,7 @@ INSERT INTO `vn`.`expense`(`id`, `name`, `isWithheld`) (7001000000, 'Mercaderia', 0), (7050000000, 'Prestacion de servicios', 1); +INSERT INTO `vn`.`agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios'); INSERT INTO `vn`.`invoiceOutExpense`(`id`, `invoiceOutFk`, `amount`, `expenseFk`, `created`) VALUES @@ -728,7 +729,7 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`) VALUES (1 , 3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1), - (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2), + (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2), (3 , 1, 7, 1, 6, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 3), (4 , 3, 2, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, NULL), (5 , 3, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, NULL), diff --git a/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql b/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql new file mode 100644 index 000000000..3409b762e --- /dev/null +++ b/db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql @@ -0,0 +1,3 @@ +USE vn; +ALTER TABLE vn.agencyTermConfig + ADD CONSTRAINT agencyTermConfig_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/myt.config.yml b/myt.config.yml index 2e37a0d97..0b1d62d25 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -44,7 +44,6 @@ fixtures: - module - defaultViewConfig vn: - - agencyTermConfig - alertLevel - bookingPlanner - businessType