From 8ea3c98a13a01c2992237aa2ca30ce3c8e1e60e4 Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 29 Jan 2024 09:12:29 +0100 Subject: [PATCH 01/86] refs #6372 feat: vn2008 to vn --- .../triggers/movement_label_afterUpdate.sql | 8 - db/routines/vn2008/views/Rutas_Master | 24 --- .../vn2008/views/financialProductType.sql | 4 + db/routines/vn2008/views/flight.sql | 13 ++ db/routines/vn2008/views/gastos_resumen.sql | 11 ++ db/routines/vn2008/views/integra2.sql | 9 + .../vn2008/views/integra2_province.sql | 8 + db/routines/vn2008/views/link.sql | 8 + db/routines/vn2008/views/warehouse_pickup.sql | 9 + .../01-financialProductType.sql | 1 + db/versions/10836-limeCordyline/02-flight.sql | 7 + .../10836-limeCordyline/03-gastos_resumen.sql | 17 ++ .../10836-limeCordyline/04-integra2.sql | 10 ++ .../05-integra2_province.sql | 4 + .../06-intervalos__delete.sql | 1 + db/versions/10836-limeCordyline/09-link.sql | 11 ++ .../10-mail_templates__delete.sql | 1 + .../12-ticket_location__delete.sql | 1 + .../10836-limeCordyline/13-turn__delete.sql | 1 + .../25-warehouse_pickup.sql | 5 + db/versions/10836-limeCordyline/29-kk.sql | 155 ++++++++++++++++++ .../10836-limeCordyline/30-permissions.sql | 36 ++++ 22 files changed, 312 insertions(+), 32 deletions(-) delete mode 100644 db/routines/vn2008/triggers/movement_label_afterUpdate.sql delete mode 100644 db/routines/vn2008/views/Rutas_Master create mode 100644 db/routines/vn2008/views/financialProductType.sql create mode 100644 db/routines/vn2008/views/flight.sql create mode 100644 db/routines/vn2008/views/gastos_resumen.sql create mode 100644 db/routines/vn2008/views/integra2.sql create mode 100644 db/routines/vn2008/views/integra2_province.sql create mode 100644 db/routines/vn2008/views/link.sql create mode 100644 db/routines/vn2008/views/warehouse_pickup.sql create mode 100644 db/versions/10836-limeCordyline/01-financialProductType.sql create mode 100644 db/versions/10836-limeCordyline/02-flight.sql create mode 100644 db/versions/10836-limeCordyline/03-gastos_resumen.sql create mode 100644 db/versions/10836-limeCordyline/04-integra2.sql create mode 100644 db/versions/10836-limeCordyline/05-integra2_province.sql create mode 100644 db/versions/10836-limeCordyline/06-intervalos__delete.sql create mode 100644 db/versions/10836-limeCordyline/09-link.sql create mode 100644 db/versions/10836-limeCordyline/10-mail_templates__delete.sql create mode 100644 db/versions/10836-limeCordyline/12-ticket_location__delete.sql create mode 100644 db/versions/10836-limeCordyline/13-turn__delete.sql create mode 100644 db/versions/10836-limeCordyline/25-warehouse_pickup.sql create mode 100644 db/versions/10836-limeCordyline/29-kk.sql create mode 100644 db/versions/10836-limeCordyline/30-permissions.sql diff --git a/db/routines/vn2008/triggers/movement_label_afterUpdate.sql b/db/routines/vn2008/triggers/movement_label_afterUpdate.sql deleted file mode 100644 index 364568fb3..000000000 --- a/db/routines/vn2008/triggers/movement_label_afterUpdate.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`movement_label_afterUpdate` - AFTER UPDATE ON `movement_label` - FOR EACH ROW -IF NEW.stem >= (SELECT Cantidad FROM Movimientos WHERE Id_Movimiento = NEW.Id_Movimiento) THEN - UPDATE Movimientos SET OK = 1 WHERE Id_Movimiento = NEW.Id_Movimiento; -END IF$$ -DELIMITER ; diff --git a/db/routines/vn2008/views/Rutas_Master b/db/routines/vn2008/views/Rutas_Master deleted file mode 100644 index 03b9cfc21..000000000 --- a/db/routines/vn2008/views/Rutas_Master +++ /dev/null @@ -1,24 +0,0 @@ - -CREATE OR REPLACE DEFINER = `root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`Rutas_Master` -AS SELECT - `rm`.`id` AS `id`, - `rm`.`warehoseFk` AS `warehouse_id`, - `rm`.`km` AS `km`, - `rm`.`packages` AS `bultos`, - `rm`.`vehicleCost` AS `vehiculos_coste`, - `rm`.`staffCost` AS `personal_coste`, - `rm`.`vehicle` AS `vehiculos_numero`, - `rm`.`staff` AS `personal_numero`, - `rm`.`fuel` AS `gasoil`, - `rm`.`freelancers` AS `autonomos`, - `rm`.`year` AS `año`, - `rm`.`mounth` AS `mes`, - `rm`.`expense` AS `gastos`, - `rm`.`freelancersPackages` AS `bultos_autonomos`, - `rm`.`kmCost` AS `coste_km`, - `rm`.`packageCost` AS `coste_bulto`, - `rm`.`freelancerPackageCost` AS `coste_bulto_autonomo` , - `rm`.`created` AS `odbc_date` - FROM `vn`.`routeMaster` `rm` \ No newline at end of file diff --git a/db/routines/vn2008/views/financialProductType.sql b/db/routines/vn2008/views/financialProductType.sql new file mode 100644 index 000000000..89a063856 --- /dev/null +++ b/db/routines/vn2008/views/financialProductType.sql @@ -0,0 +1,4 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`financialProductType`AS + SELECT * FROM vn.financialProductType; \ No newline at end of file diff --git a/db/routines/vn2008/views/flight.sql b/db/routines/vn2008/views/flight.sql new file mode 100644 index 000000000..e671801c0 --- /dev/null +++ b/db/routines/vn2008/views/flight.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`flight` +AS SELECT + `f`.`id` AS `flight_id`, + `f`.`duration` AS `duration`, + `f`.`route` AS `route`, + `f`.`days` AS `days`, + `f`.`airlineFk` AS `airline_id`, + `f`.`airportOutFk` AS `airport_out`, + `f`.`airportInFk` AS `airport_in` +FROM + `vn`.`flight` `f`; \ No newline at end of file diff --git a/db/routines/vn2008/views/gastos_resumen.sql b/db/routines/vn2008/views/gastos_resumen.sql new file mode 100644 index 000000000..1b6b6d877 --- /dev/null +++ b/db/routines/vn2008/views/gastos_resumen.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`gastos_resumen` +AS SELECT + `es`.`expenseFk` AS `Id_Gasto`, + `es`.`year` AS `year`, + `es`.`month` AS `month`, + `es`.`amount` AS `importe`, + `es`.`companyFk` AS `empresa_id` +FROM + `vn`.`expenseSummary` `es`; \ No newline at end of file diff --git a/db/routines/vn2008/views/integra2.sql b/db/routines/vn2008/views/integra2.sql new file mode 100644 index 000000000..05840d6bb --- /dev/null +++ b/db/routines/vn2008/views/integra2.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`integra2` +AS SELECT + `i2`.`postCode` AS `postal_code`, + `i2`.`frequency` AS `frequency`, + `i2`.`warehouseFk` AS `warehouse_id` +FROM + `vn`.`integra2` `i2`; \ No newline at end of file diff --git a/db/routines/vn2008/views/integra2_province.sql b/db/routines/vn2008/views/integra2_province.sql new file mode 100644 index 000000000..bc099adb3 --- /dev/null +++ b/db/routines/vn2008/views/integra2_province.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`integra2_province` +AS SELECT + `ip`.`provinceFk` AS `province_id`, + `ip`.`franchise` AS `franquicia` +FROM + `vn`.`integra2Province` `ip`; \ No newline at end of file diff --git a/db/routines/vn2008/views/link.sql b/db/routines/vn2008/views/link.sql new file mode 100644 index 000000000..f5fb9bd2b --- /dev/null +++ b/db/routines/vn2008/views/link.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`link` +AS SELECT + `l`.`clientFk` AS `Id_Cliente`, + `l`.`supplierFk` AS `Id_Proveedor` +FROM + `vn`.`link` `l`; \ No newline at end of file diff --git a/db/routines/vn2008/views/warehouse_pickup.sql b/db/routines/vn2008/views/warehouse_pickup.sql new file mode 100644 index 000000000..c3a7268a1 --- /dev/null +++ b/db/routines/vn2008/views/warehouse_pickup.sql @@ -0,0 +1,9 @@ + +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`warehouse_pickup` +AS SELECT + `wp`.`warehouseFk` AS `warehouse_id`, + `wp`.`agencyModeFk` AS `agency_id` +FROM + `vn`.`warehousePickup` `wp`; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/01-financialProductType.sql b/db/versions/10836-limeCordyline/01-financialProductType.sql new file mode 100644 index 000000000..c5d51e015 --- /dev/null +++ b/db/versions/10836-limeCordyline/01-financialProductType.sql @@ -0,0 +1 @@ +ALTER TABLE IF EXISTS `vn2008`.`financialProductType` RENAME `vn`.`financialProductType`; diff --git a/db/versions/10836-limeCordyline/02-flight.sql b/db/versions/10836-limeCordyline/02-flight.sql new file mode 100644 index 000000000..37849d037 --- /dev/null +++ b/db/versions/10836-limeCordyline/02-flight.sql @@ -0,0 +1,7 @@ +ALTER TABLE IF EXISTS `vn2008`.`flight` RENAME `vn`.`flight`; + +ALTER TABLE IF EXISTS `vn`.`flight` +CHANGE COLUMN IF EXISTS `flight_id` `id` varchar(10) NOT NULL, +CHANGE COLUMN IF EXISTS `airline_id` `airlineFk` smallint(2) unsigned DEFAULT NULL, +CHANGE COLUMN IF EXISTS `airport_out` `airportOutFk` varchar(3) NOT NULL, +CHANGE COLUMN IF EXISTS `airport_in` `airportInFk` varchar(3) NOT NULL; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/03-gastos_resumen.sql b/db/versions/10836-limeCordyline/03-gastos_resumen.sql new file mode 100644 index 000000000..bfec006fa --- /dev/null +++ b/db/versions/10836-limeCordyline/03-gastos_resumen.sql @@ -0,0 +1,17 @@ +ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseSummary`; + +ALTER TABLE IF EXISTS `vn`.`expenseSummary` +CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, +CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, +CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; + +ALTER TABLE IF EXISTS vn.expenseSummary COLLATE=utf8mb3_general_ci; + +ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; + +ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN companyFk int(10) unsigned NOT NULL; + +ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_company_FK FOREIGN KEY (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; + diff --git a/db/versions/10836-limeCordyline/04-integra2.sql b/db/versions/10836-limeCordyline/04-integra2.sql new file mode 100644 index 000000000..663b28d78 --- /dev/null +++ b/db/versions/10836-limeCordyline/04-integra2.sql @@ -0,0 +1,10 @@ +ALTER TABLE IF EXISTS `vn2008`.`integra2` RENAME `vn`.`integra2`; + +ALTER TABLE IF EXISTS `vn`.`integra2` +CHANGE COLUMN IF EXISTS `postal_code` `postCode` varchar(10) NOT NULL, +CHANGE COLUMN IF EXISTS `frequency` `frequency` decimal(10,2) DEFAULT NULL, +CHANGE COLUMN IF EXISTS `warehouse_id` `warehouseFk` smallint(6) unsigned NOT NULL; + +ALTER TABLE IF EXISTS vn.integra2 ADD CONSTRAINT integra2_warehouse_FK +FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE CASCADE ON UPDATE CASCADE; + diff --git a/db/versions/10836-limeCordyline/05-integra2_province.sql b/db/versions/10836-limeCordyline/05-integra2_province.sql new file mode 100644 index 000000000..31f8f4156 --- /dev/null +++ b/db/versions/10836-limeCordyline/05-integra2_province.sql @@ -0,0 +1,4 @@ +ALTER TABLE IF EXISTS `vn2008`.`integra2_province` RENAME `vn`.`integra2Province`; +ALTER TABLE IF EXISTS `vn`.`integra2Province` +CHANGE COLUMN IF EXISTS `franquicia` `franchise` varchar(65) NOT NULL, +CHANGE COLUMN IF EXISTS `province_id` `provinceFk` smallint(6) unsigned NOT NULL; diff --git a/db/versions/10836-limeCordyline/06-intervalos__delete.sql b/db/versions/10836-limeCordyline/06-intervalos__delete.sql new file mode 100644 index 000000000..18d4f57ca --- /dev/null +++ b/db/versions/10836-limeCordyline/06-intervalos__delete.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS vn2008.intervalos__; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/09-link.sql b/db/versions/10836-limeCordyline/09-link.sql new file mode 100644 index 000000000..a1a671270 --- /dev/null +++ b/db/versions/10836-limeCordyline/09-link.sql @@ -0,0 +1,11 @@ +ALTER TABLE IF EXISTS `vn2008`.`link` RENAME `vn`.`link`; + +ALTER TABLE IF EXISTS `vn`.`link` +CHANGE COLUMN IF EXISTS `Id_Cliente` `clientFk` int(11) NOT NULL, +CHANGE COLUMN IF EXISTS `Id_Proveedor` `supplierFk` int(11) NOT NULL; + +ALTER TABLE IF EXISTS vn.link MODIFY COLUMN supplierFk int(10) unsigned NOT NULL; + +ALTER TABLE IF EXISTS vn.link ADD CONSTRAINT link_client_FK FOREIGN KEY (clientFk) REFERENCES vn.client(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE IF EXISTS vn.link ADD CONSTRAINT link_supplier_FK FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE CASCADE ON UPDATE CASCADE; + diff --git a/db/versions/10836-limeCordyline/10-mail_templates__delete.sql b/db/versions/10836-limeCordyline/10-mail_templates__delete.sql new file mode 100644 index 000000000..e30aae925 --- /dev/null +++ b/db/versions/10836-limeCordyline/10-mail_templates__delete.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS vn2008.mail_templates__; diff --git a/db/versions/10836-limeCordyline/12-ticket_location__delete.sql b/db/versions/10836-limeCordyline/12-ticket_location__delete.sql new file mode 100644 index 000000000..a7dbbfb95 --- /dev/null +++ b/db/versions/10836-limeCordyline/12-ticket_location__delete.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS vn2008.ticket_location__; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/13-turn__delete.sql b/db/versions/10836-limeCordyline/13-turn__delete.sql new file mode 100644 index 000000000..7aa69e57d --- /dev/null +++ b/db/versions/10836-limeCordyline/13-turn__delete.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS vn2008.turn__; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/25-warehouse_pickup.sql b/db/versions/10836-limeCordyline/25-warehouse_pickup.sql new file mode 100644 index 000000000..1a2479a43 --- /dev/null +++ b/db/versions/10836-limeCordyline/25-warehouse_pickup.sql @@ -0,0 +1,5 @@ +ALTER TABLE IF EXISTS `vn2008`.`warehouse_pickup` RENAME `vn`.`warehousePickup`; + +ALTER TABLE IF EXISTS `vn`.`warehousePickup` +CHANGE COLUMN IF EXISTS `warehouse_id` `warehouseFk` smallint(5) unsigned NOT NULL, +CHANGE COLUMN IF EXISTS `agency_id` `agencyModeFk` int(11) DEFAULT NULL; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/29-kk.sql b/db/versions/10836-limeCordyline/29-kk.sql new file mode 100644 index 000000000..c21980da9 --- /dev/null +++ b/db/versions/10836-limeCordyline/29-kk.sql @@ -0,0 +1,155 @@ +ALTER TABLE IF EXISTS vn2008.template_bionic_component RENAME vn2008.template_bionic_component__; +ALTER TABLE IF EXISTS vn2008.template_bionic_component__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.template_bionic_lot RENAME vn2008.template_bionic_lot__; +ALTER TABLE IF EXISTS vn2008.template_bionic_lot__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.template_bionic_price RENAME vn2008.template_bionic_price__; +ALTER TABLE IF EXISTS vn2008.template_bionic_price__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.tmpNEWTARIFAS RENAME vn2008.tmpNEWTARIFAS__; +ALTER TABLE IF EXISTS vn2008.tmpNEWTARIFAS__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.unaryScanFilter RENAME vn2008.unaryScanFilter__; +ALTER TABLE IF EXISTS vn2008.unaryScanFilter__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.unary_source RENAME vn2008.unary_source__; +ALTER TABLE IF EXISTS vn2008.unary_source__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.viaxpress RENAME vn2008.viaxpress__; +ALTER TABLE IF EXISTS vn2008.viaxpress__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.warehouse_filtro RENAME vn2008.warehouse_filtro__; +ALTER TABLE IF EXISTS vn2008.warehouse_filtro__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.warehouse_group RENAME vn2008.warehouse_group__; +ALTER TABLE IF EXISTS vn2008.warehouse_group__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.warehouse_joined RENAME vn2008.warehouse_joined__; +ALTER TABLE IF EXISTS vn2008.warehouse_joined__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.warehouse_lc RENAME vn2008.warehouse_lc__; +ALTER TABLE IF EXISTS vn2008.warehouse_lc__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.wh_selection RENAME vn2008.wh_selection__; +ALTER TABLE IF EXISTS vn2008.wh_selection__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.trolley RENAME vn2008.trolley__; +ALTER TABLE IF EXISTS vn2008.trolley__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.zones RENAME vn2008.zones__; +ALTER TABLE IF EXISTS vn2008.zones__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.tblIVA RENAME vn2008.tblIVA__; +ALTER TABLE IF EXISTS vn2008.tblIVA__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.filtros RENAME vn2008.filtros__; +ALTER TABLE IF EXISTS vn2008.filtros__ COMMENT='refs #6372 @deprecated 2023-11-21;'; + +ALTER TABLE IF EXISTS vn2008.form_query RENAME vn2008.form_query__; +ALTER TABLE IF EXISTS vn2008.form_query__ COMMENT='refs #6372 @deprecated 2023-11-21;'; + +ALTER TABLE IF EXISTS vn2008.guillen RENAME vn2008.guillen__; +ALTER TABLE IF EXISTS vn2008.guillen__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.guillen_carry RENAME vn2008.guillen_carry__; +ALTER TABLE IF EXISTS vn2008.guillen_carry__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.integra2_escala RENAME vn2008.integra2_escala__; +ALTER TABLE IF EXISTS vn2008.integra2_escala__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.invoice_observation RENAME vn2008.invoice_observation__; +ALTER TABLE IF EXISTS vn2008.invoice_observation__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.nichos RENAME vn2008.nichos__; +ALTER TABLE IF EXISTS vn2008.nichos__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.payroll_bonificaciones RENAME vn2008.payroll_bonificaciones__; +ALTER TABLE IF EXISTS vn2008.payroll_bonificaciones__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.payroll_daRENAMEs RENAME vn2008.payroll_daRENAMEs__; +ALTER TABLE IF EXISTS vn2008.payroll_daRENAMEs__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.payroll_embargos RENAME vn2008.payroll_embargos__; +ALTER TABLE IF EXISTS vn2008.payroll_embargos__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.payroll_tipobasess RENAME vn2008.payroll_tipobasess__; +ALTER TABLE IF EXISTS vn2008.payroll_tipobasess__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.preparation_exception RENAME vn2008.preparation_exception__; +ALTER TABLE IF EXISTS vn2008.preparation_exception__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.payrroll_apEmpresarial RENAME vn2008.payrroll_apEmpresarial__; +ALTER TABLE IF EXISTS vn2008.payrroll_apEmpresarial__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.rec_translaRENAMEr RENAME vn2008.rec_translaRENAMEr__; +ALTER TABLE IF EXISTS vn2008.rec_translaRENAMEr__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.recibida_agricola RENAME vn2008.recibida_agricola__; +ALTER TABLE IF EXISTS vn2008.recibida_agricola__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.rounding RENAME vn2008.rounding__; +ALTER TABLE IF EXISTS vn2008.rounding__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.scanTree RENAME vn2008.scanTree__; +ALTER TABLE IF EXISTS vn2008.scanTree__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.sort_merge_results_ernesRENAME RENAME vn2008.sort_merge_results_ernesRENAME__; +ALTER TABLE IF EXISTS vn2008.sort_merge_results_ernesRENAME__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.route RENAME vn2008.route__; +ALTER TABLE IF EXISTS vn2008.route__ COMMENT='refs #6372 @deprecated 2023-11-28;'; + +ALTER TABLE IF EXISTS vn2008.travel_reserve RENAME vn2008.travel_reserve__; +ALTER TABLE IF EXISTS vn2008.travel_reserve__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.wks RENAME vn2008.wks__; +ALTER TABLE IF EXISTS vn2008.wks__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.unary RENAME vn2008.unary__; +ALTER TABLE IF EXISTS vn2008.unary__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.unary_scan RENAME vn2008.unary_scan__; +ALTER TABLE IF EXISTS vn2008.unary_scan__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.unary_scan_line RENAME vn2008.unary_scan_line__; +ALTER TABLE IF EXISTS vn2008.unary_scan_line__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.unary_scan_line_buy RENAME vn2008.unary_scan_line_buy__; +ALTER TABLE IF EXISTS vn2008.unary_scan_line_buy__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.unary_scan_line_expedition RENAME vn2008.unary_scan_line_expedition__; +ALTER TABLE IF EXISTS vn2008.unary_scan_line_expedition__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.widget RENAME vn2008.widget__; +ALTER TABLE IF EXISTS vn2008.widget__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.scan RENAME vn2008.scan__; +ALTER TABLE IF EXISTS vn2008.scan__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.scan_line RENAME vn2008.scan_line__; +ALTER TABLE IF EXISTS vn2008.scan_line__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.tipsa RENAME vn2008.tipsa__; +ALTER TABLE IF EXISTS vn2008.tipsa__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.payroll_basess RENAME vn2008.payroll_basess__; +ALTER TABLE IF EXISTS vn2008.payroll_basess__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.movement_label RENAME vn2008.movement_label__; +ALTER TABLE IF EXISTS vn2008.movement_label__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.pago_sdc RENAME vn2008.pago_sdc__; +ALTER TABLE IF EXISTS vn2008.pago_sdc__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.transport RENAME vn2008.transport__; +ALTER TABLE IF EXISTS vn2008.transport__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.travel_pattern RENAME vn2008.travel_pattern__; +ALTER TABLE IF EXISTS vn2008.travel_pattern__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.jerarquia RENAME vn2008.jerarquia__; +ALTER TABLE IF EXISTS vn2008.jerarquia__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.language RENAME vn2008.language__; +ALTER TABLE IF EXISTS vn2008.language__ COMMENT='refs #6372 @deprecated 2023-12-13;'; diff --git a/db/versions/10836-limeCordyline/30-permissions.sql b/db/versions/10836-limeCordyline/30-permissions.sql new file mode 100644 index 000000000..c27ee1e88 --- /dev/null +++ b/db/versions/10836-limeCordyline/30-permissions.sql @@ -0,0 +1,36 @@ +-- flight +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`flight` AS + SELECT 1; +GRANT SELECT, INSERT, UPDATE ON TABLE vn2008.flight TO `logistic`; +GRANT SELECT, INSERT, UPDATE ON TABLE vn.flight TO `logistic`; +-- integra2_province +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`integra2_province` AS + SELECT 1; +GRANT SELECT ON TABLE vn2008.integra2_province TO `employee`; +GRANT SELECT ON TABLE vn.integra2Province TO `employee`; +-- link +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`link` AS + SELECT 1; +GRANT SELECT ON TABLE vn2008.link TO `administrative`; +GRANT SELECT ON TABLE vn.link TO `administrative`; +GRANT SELECT ON TABLE vn2008.link TO `hr`; +GRANT SELECT ON TABLE vn.link TO `hr`; +-- warehouse_pickup +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`warehouse_pickup` AS + SELECT 1; +GRANT SELECT ON TABLE vn2008.warehouse_pickup TO `logistic`; +GRANT SELECT ON TABLE vn.warehousePickup TO `logistic`; +GRANT SELECT ON TABLE vn2008.warehouse_pickup TO `claimManager`; +GRANT SELECT ON TABLE vn.warehousePickup TO `claimManager`; +GRANT SELECT ON TABLE vn2008.warehouse_pickup TO `employee`; +GRANT SELECT ON TABLE vn.warehousePickup TO `employee`; +GRANT SELECT ON TABLE vn2008.warehouse_pickup TO `deliveryAssistant`; +GRANT SELECT ON TABLE vn.warehousePickup TO `deliveryAssistant`; From abbda268f5b3e7d91adae658d0df0e82c95db08a Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 29 Jan 2024 09:18:11 +0100 Subject: [PATCH 02/86] refs #6372 feat: vn2008 to vn --- db/dump/fixtures.after.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 57ccb8626..c8ed8a84a 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -139,9 +139,6 @@ INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressF INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded) VALUES (1, 24, 'Ranged weapon longbow 2m', 1.00, NULL, 8.07, 0, 0.00, 0, 0, 0, '2022-07-06 00:00:00', 0); */ -INSERT INTO vn2008.zones (zone_id,name,printingOrder) - VALUES (1,'zone Test',1); - -- XXX: lab INSERT INTO `vn`.`businessReasonEnd` (`id`, `reason`) From afa34c6296507b3b130b83ea83ef8d2b48d6a85d Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 30 Jan 2024 14:00:08 +0100 Subject: [PATCH 03/86] feat: refs #6776 makeMulti --- .../back/methods/item-shelving/makeMulti.js | 71 +++++++++++++++++++ .../item-shelving/specs/makeMulti.spec.js | 54 ++++++++++++++ modules/item/back/models/item-shelving.js | 1 + 3 files changed, 126 insertions(+) create mode 100644 modules/item/back/methods/item-shelving/makeMulti.js create mode 100644 modules/item/back/methods/item-shelving/specs/makeMulti.spec.js diff --git a/modules/item/back/methods/item-shelving/makeMulti.js b/modules/item/back/methods/item-shelving/makeMulti.js new file mode 100644 index 000000000..e3a3b1cf5 --- /dev/null +++ b/modules/item/back/methods/item-shelving/makeMulti.js @@ -0,0 +1,71 @@ +module.exports = Self => { + Self.remoteMethod('makeMulti', { + description: 'Add a record or update it if it already exists.', + accessType: 'WRITE', + accepts: [{ + arg: 'shelvingFk', + type: 'string', + required: true, + }, + { + arg: 'items', + type: ['number'], + required: true, + description: 'array of item foreign keys' + }, + { + arg: 'warehouseFk', + type: 'number', + required: true + }], + + http: { + path: `/makeMulti`, + verb: 'POST' + } + }); + + Self.makeMulti = async(shelvingFk, items, warehouseFk, options) => { + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + const discardItems = []; + + try { + for (let item of items) { + if (!discardItems.includes(item)) { + let quantity = items.reduce((acc, cur) => { + return acc + (cur === item ? 1 : 0); + }, 0); + discardItems.push(item); + + const [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?) itemPacking', + [item, warehouseFk], myOptions); + let packing; + + if (result) packing = result.itemPacking; + if (!packing) packing = 1; + + quantity = quantity * packing; + + await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, ?, ?)', + [shelvingFk, item, quantity, packing, warehouseFk], myOptions + ); + } + } + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js new file mode 100644 index 000000000..a8d0c197e --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js @@ -0,0 +1,54 @@ +const {models} = require('vn-loopback/server/server'); + +describe('ItemShelving makeMulti()', () => { + const warehouseFk = 1; + + beforeAll(async() => { + ctx = { + accessToken: {userId: 9}, + req: { + headers: {origin: 'http://localhost'}, + } + }; + }); + + it('should add two new records', async() => { + const shelvingFk = 'ZPP'; + const items = [1, 1, 1, 2]; + const tx = await models.ItemShelving.beginTransaction({}); + const options = {transaction: tx}; + + try { + await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); + const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); + + expect(itemShelvings.length).toEqual(2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should update the visible items', async() => { + const shelvingFk = 'GVC'; + const items = [2, 2]; + const tx = await models.ItemShelving.beginTransaction({}); + const options = {transaction: tx}; + try { + const {visible: itemsBefore} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); + const {visible: itemsAfter} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + + expect(itemsAfter).toEqual(itemsBefore + 2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index 98ff18931..9bc94fa1e 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/item-shelving/deleteItemShelvings')(Self); + require('../methods/item-shelving/makeMulti')(Self); require('../methods/item-shelving/getInventory')(Self); }; From 5690da0a1888db4a2712794aa1e684dfe1e8a5bc Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 30 Jan 2024 16:05:56 +0100 Subject: [PATCH 04/86] fix: refs #6776 add userId --- modules/item/back/methods/item-shelving/makeMulti.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/item/back/methods/item-shelving/makeMulti.js b/modules/item/back/methods/item-shelving/makeMulti.js index e3a3b1cf5..4fd895eec 100644 --- a/modules/item/back/methods/item-shelving/makeMulti.js +++ b/modules/item/back/methods/item-shelving/makeMulti.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('makeMulti', { + Self.remoteMethodCtx('makeMulti', { description: 'Add a record or update it if it already exists.', accessType: 'WRITE', accepts: [{ @@ -25,8 +25,8 @@ module.exports = Self => { } }); - Self.makeMulti = async(shelvingFk, items, warehouseFk, options) => { - const myOptions = {}; + Self.makeMulti = async(ctx, shelvingFk, items, warehouseFk, options) => { + const myOptions = {userId: ctx.req.accessToken.userId}; let tx; if (typeof options == 'object') From 8a978a2539d472f156d36c18dfef4e96ccc08741 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jan 2024 12:54:52 +0100 Subject: [PATCH 05/86] refs #6669 fix:ticket_isOutClosureZone --- db/routines/vn/functions/ticket_isOutClosureZone.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/functions/ticket_isOutClosureZone.sql b/db/routines/vn/functions/ticket_isOutClosureZone.sql index ebddcf505..30589c87a 100644 --- a/db/routines/vn/functions/ticket_isOutClosureZone.sql +++ b/db/routines/vn/functions/ticket_isOutClosureZone.sql @@ -9,7 +9,7 @@ BEGIN * @param vSelf Ticket id * @return true o false */ - DECLARE vIsTicketInTime BOOL; + DECLARE vIsTicketInTime BOOL DEFAULT FALSE; SELECT TIMEDIFF(CURRENT_TIME(), zc.hour + INTERVAL tc.packingDelay HOUR) > 0 INTO vIsTicketInTime FROM vn.ticket t From bad00167fa4224169b3685e94386bc72d59e4574 Mon Sep 17 00:00:00 2001 From: davidd Date: Wed, 31 Jan 2024 14:50:56 +0100 Subject: [PATCH 06/86] refs #6372 feat: vn2008 to vn --- db/routines/vn2008/views/flight.sql | 6 +++--- db/versions/10836-limeCordyline/02-flight.sql | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db/routines/vn2008/views/flight.sql b/db/routines/vn2008/views/flight.sql index e671801c0..2df5362f7 100644 --- a/db/routines/vn2008/views/flight.sql +++ b/db/routines/vn2008/views/flight.sql @@ -4,10 +4,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` AS SELECT `f`.`id` AS `flight_id`, `f`.`duration` AS `duration`, - `f`.`route` AS `route`, + `f`.`flightPath` AS `route`, `f`.`days` AS `days`, `f`.`airlineFk` AS `airline_id`, - `f`.`airportOutFk` AS `airport_out`, - `f`.`airportInFk` AS `airport_in` + `f`.`airportArrivalFk` AS `airport_out`, + `f`.`airportDepartureFk` AS `airport_in` FROM `vn`.`flight` `f`; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/02-flight.sql b/db/versions/10836-limeCordyline/02-flight.sql index 37849d037..657fa2aa1 100644 --- a/db/versions/10836-limeCordyline/02-flight.sql +++ b/db/versions/10836-limeCordyline/02-flight.sql @@ -3,5 +3,6 @@ ALTER TABLE IF EXISTS `vn2008`.`flight` RENAME `vn`.`flight`; ALTER TABLE IF EXISTS `vn`.`flight` CHANGE COLUMN IF EXISTS `flight_id` `id` varchar(10) NOT NULL, CHANGE COLUMN IF EXISTS `airline_id` `airlineFk` smallint(2) unsigned DEFAULT NULL, -CHANGE COLUMN IF EXISTS `airport_out` `airportOutFk` varchar(3) NOT NULL, -CHANGE COLUMN IF EXISTS `airport_in` `airportInFk` varchar(3) NOT NULL; \ No newline at end of file +CHANGE COLUMN IF EXISTS `route` `flightPath` varchar(20) DEFAULT NULL, +CHANGE COLUMN IF EXISTS `airport_out` `airportArrivalFk` varchar(3) NOT NULL, +CHANGE COLUMN IF EXISTS `airport_in` `airportDepartureFk` varchar(3) NOT NULL; \ No newline at end of file From 6f4c0f655ded04e0ab53c04482221b2e17acfdc5 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 2 Feb 2024 08:05:17 +0100 Subject: [PATCH 07/86] 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 b7bb1b97847885c24502645a9f01c9454014536f Mon Sep 17 00:00:00 2001 From: davidd Date: Tue, 6 Feb 2024 07:37:33 +0100 Subject: [PATCH 08/86] refs #6372 feat: vn2008 to vn --- db/routines/vn2008/views/link.sql | 8 -------- db/versions/10836-limeCordyline/09-link.sql | 11 ----------- db/versions/10836-limeCordyline/29-kk.sql | 3 +++ db/versions/10836-limeCordyline/30-permissions.sql | 12 ++++-------- 4 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 db/routines/vn2008/views/link.sql delete mode 100644 db/versions/10836-limeCordyline/09-link.sql diff --git a/db/routines/vn2008/views/link.sql b/db/routines/vn2008/views/link.sql deleted file mode 100644 index f5fb9bd2b..000000000 --- a/db/routines/vn2008/views/link.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`link` -AS SELECT - `l`.`clientFk` AS `Id_Cliente`, - `l`.`supplierFk` AS `Id_Proveedor` -FROM - `vn`.`link` `l`; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/09-link.sql b/db/versions/10836-limeCordyline/09-link.sql deleted file mode 100644 index a1a671270..000000000 --- a/db/versions/10836-limeCordyline/09-link.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE IF EXISTS `vn2008`.`link` RENAME `vn`.`link`; - -ALTER TABLE IF EXISTS `vn`.`link` -CHANGE COLUMN IF EXISTS `Id_Cliente` `clientFk` int(11) NOT NULL, -CHANGE COLUMN IF EXISTS `Id_Proveedor` `supplierFk` int(11) NOT NULL; - -ALTER TABLE IF EXISTS vn.link MODIFY COLUMN supplierFk int(10) unsigned NOT NULL; - -ALTER TABLE IF EXISTS vn.link ADD CONSTRAINT link_client_FK FOREIGN KEY (clientFk) REFERENCES vn.client(id) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE IF EXISTS vn.link ADD CONSTRAINT link_supplier_FK FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE CASCADE ON UPDATE CASCADE; - diff --git a/db/versions/10836-limeCordyline/29-kk.sql b/db/versions/10836-limeCordyline/29-kk.sql index c21980da9..9ec27358f 100644 --- a/db/versions/10836-limeCordyline/29-kk.sql +++ b/db/versions/10836-limeCordyline/29-kk.sql @@ -153,3 +153,6 @@ ALTER TABLE IF EXISTS vn2008.jerarquia__ COMMENT='refs #6372 @deprecated 2023-12 ALTER TABLE IF EXISTS vn2008.language RENAME vn2008.language__; ALTER TABLE IF EXISTS vn2008.language__ COMMENT='refs #6372 @deprecated 2023-12-13;'; + +ALTER TABLE IF EXISTS vn2008.link RENAME vn2008.link__; +ALTER TABLE IF EXISTS vn2008.link__ COMMENT='refs #6372 @deprecated 2023-12-13;'; diff --git a/db/versions/10836-limeCordyline/30-permissions.sql b/db/versions/10836-limeCordyline/30-permissions.sql index c27ee1e88..fd7c6c58e 100644 --- a/db/versions/10836-limeCordyline/30-permissions.sql +++ b/db/versions/10836-limeCordyline/30-permissions.sql @@ -13,14 +13,10 @@ VIEW `vn2008`.`integra2_province` AS GRANT SELECT ON TABLE vn2008.integra2_province TO `employee`; GRANT SELECT ON TABLE vn.integra2Province TO `employee`; -- link -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER -VIEW `vn2008`.`link` AS - SELECT 1; -GRANT SELECT ON TABLE vn2008.link TO `administrative`; -GRANT SELECT ON TABLE vn.link TO `administrative`; -GRANT SELECT ON TABLE vn2008.link TO `hr`; -GRANT SELECT ON TABLE vn.link TO `hr`; + +GRANT SELECT ON TABLE vn.company TO `administrative`; +GRANT SELECT ON TABLE vn.company TO `hr`; + -- warehouse_pickup CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER From 6a738627e7644f81da5052f64f2b9c01624c1933 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 6 Feb 2024 15:42:03 +0100 Subject: [PATCH 09/86] 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 10/86] 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 11/86] 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 c2360ca154aa34b94075a954525229d58b650ad1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 9 Feb 2024 06:59:39 +0100 Subject: [PATCH 12/86] refs #6559 feat:quit call get_sectors --- back/methods/collection/getSectors.js | 20 ------------------- .../collection/spec/getSectors.spec.js | 11 ---------- db/routines/vn/procedures/sector_get.sql | 13 ------------ 3 files changed, 44 deletions(-) delete mode 100644 back/methods/collection/getSectors.js delete mode 100644 back/methods/collection/spec/getSectors.spec.js delete mode 100644 db/routines/vn/procedures/sector_get.sql diff --git a/back/methods/collection/getSectors.js b/back/methods/collection/getSectors.js deleted file mode 100644 index 12ad0dc06..000000000 --- a/back/methods/collection/getSectors.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('getSectors', { - description: 'Get all sectors', - accessType: 'READ', - returns: { - type: 'Object', - root: true - }, - http: { - path: `/getSectors`, - verb: 'GET' - } - }); - - Self.getSectors = async() => { - const query = `CALL vn.sector_get()`; - const [result] = await Self.rawSql(query); - return result; - }; -}; diff --git a/back/methods/collection/spec/getSectors.spec.js b/back/methods/collection/spec/getSectors.spec.js deleted file mode 100644 index d8fa60663..000000000 --- a/back/methods/collection/spec/getSectors.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -const {models} = require('vn-loopback/server/server'); - -describe('getSectors()', () => { - it('return list of sectors', async() => { - let response = await models.Collection.getSectors(); - - expect(response.length).toBeGreaterThan(0); - expect(response[0].id).toEqual(1); - expect(response[0].description).toEqual('First sector'); - }); -}); diff --git a/db/routines/vn/procedures/sector_get.sql b/db/routines/vn/procedures/sector_get.sql deleted file mode 100644 index fe978203a..000000000 --- a/db/routines/vn/procedures/sector_get.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sector_get`() -BEGIN - -/** - * Obtiene los sectores -*/ - - SELECT s.id,s.description,s.warehouseFk - FROM vn.sector s; - -END$$ -DELIMITER ; From 36683597ec4f10294f3a0e5231b6c5ffbe2dad00 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 9 Feb 2024 07:02:00 +0100 Subject: [PATCH 13/86] refs #6559 feat:quit call get_sectors --- back/models/collection.js | 1 - 1 file changed, 1 deletion(-) diff --git a/back/models/collection.js b/back/models/collection.js index 1c10d49fa..52ef26e88 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -1,6 +1,5 @@ module.exports = Self => { require('../methods/collection/getCollection')(Self); - require('../methods/collection/getSectors')(Self); require('../methods/collection/setSaleQuantity')(Self); require('../methods/collection/previousLabel')(Self); require('../methods/collection/getTickets')(Self); From 463b3fb6f3d4a37b5c4812ff0919fe04aa6a10a4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 9 Feb 2024 11:35:47 +0100 Subject: [PATCH 14/86] 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 b712b65d76cd3eb8e41bb52a1fd57439073119ba Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 12 Feb 2024 07:44:40 +0100 Subject: [PATCH 15/86] refs #6372 --- db/routines/vn/triggers/movementLabel_afterUpdate.sql | 8 ++++++++ db/routines/vn2008/views/movement_label.sql | 10 ++++++++++ db/versions/10836-limeCordyline/14-movement_label.sql | 6 ++++++ db/versions/10836-limeCordyline/29-kk.sql | 3 --- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 db/routines/vn/triggers/movementLabel_afterUpdate.sql create mode 100644 db/routines/vn2008/views/movement_label.sql create mode 100644 db/versions/10836-limeCordyline/14-movement_label.sql diff --git a/db/routines/vn/triggers/movementLabel_afterUpdate.sql b/db/routines/vn/triggers/movementLabel_afterUpdate.sql new file mode 100644 index 000000000..cef8e2b43 --- /dev/null +++ b/db/routines/vn/triggers/movementLabel_afterUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`movementLabel_afterUpdate` + AFTER UPDATE ON `vn`.`movementLabel` + FOR EACH ROW +IF NEW.stem >= (SELECT s.quantity FROM sale s WHERE s.id = NEW.saleFk) THEN + UPDATE sale s SET s.isPicked = 1 WHERE s.id = NEW.saleFk; +END IF$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn2008/views/movement_label.sql b/db/routines/vn2008/views/movement_label.sql new file mode 100644 index 000000000..738750507 --- /dev/null +++ b/db/routines/vn2008/views/movement_label.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`movement_label` +AS SELECT + `m`.`saleFk` AS `Id_movimiento`, + `m`.`label`, + `m`.`stem`, + `m`.`created` +FROM + `vn`.`movementLabel` `m`; \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/14-movement_label.sql b/db/versions/10836-limeCordyline/14-movement_label.sql new file mode 100644 index 000000000..bb762e1ba --- /dev/null +++ b/db/versions/10836-limeCordyline/14-movement_label.sql @@ -0,0 +1,6 @@ +DROP TRIGGER IF EXISTS `vn2008`.`movement_label_au`; + +ALTER TABLE IF EXISTS `vn2008`.`movement_label` RENAME `vn`.`movementLabel`; + +ALTER TABLE IF EXISTS `vn`.`movementLabel` +CHANGE COLUMN IF EXISTS `Id_movimiento` `saleFk` int(11) NOT NULL; diff --git a/db/versions/10836-limeCordyline/29-kk.sql b/db/versions/10836-limeCordyline/29-kk.sql index 9ec27358f..4683ae8a1 100644 --- a/db/versions/10836-limeCordyline/29-kk.sql +++ b/db/versions/10836-limeCordyline/29-kk.sql @@ -136,9 +136,6 @@ ALTER TABLE IF EXISTS vn2008.tipsa__ COMMENT='refs #6372 @deprecated 2023-12-13; ALTER TABLE IF EXISTS vn2008.payroll_basess RENAME vn2008.payroll_basess__; ALTER TABLE IF EXISTS vn2008.payroll_basess__ COMMENT='refs #6372 @deprecated 2023-12-13;'; -ALTER TABLE IF EXISTS vn2008.movement_label RENAME vn2008.movement_label__; -ALTER TABLE IF EXISTS vn2008.movement_label__ COMMENT='refs #6372 @deprecated 2023-12-13;'; - ALTER TABLE IF EXISTS vn2008.pago_sdc RENAME vn2008.pago_sdc__; ALTER TABLE IF EXISTS vn2008.pago_sdc__ COMMENT='refs #6372 @deprecated 2023-12-13;'; From c81860155288d00050a7d40f3314e6d0cc27255f Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 12 Feb 2024 08:45:47 +0100 Subject: [PATCH 16/86] 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 e1567dfb9e2fd64b35c89df60e52fea03014fb84 Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 12 Feb 2024 11:20:12 +0100 Subject: [PATCH 17/86] refs #6372 --- db/routines/vn2008/procedures/clean.sql | 1 - db/versions/10836-limeCordyline/29-kk.sql | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/db/routines/vn2008/procedures/clean.sql b/db/routines/vn2008/procedures/clean.sql index bd8a324c6..eaaa22c3f 100644 --- a/db/routines/vn2008/procedures/clean.sql +++ b/db/routines/vn2008/procedures/clean.sql @@ -53,7 +53,6 @@ proc: BEGIN DELETE FROM cl_main WHERE Fecha < vDate18; DELETE FROM hedera.`order` WHERE date_send < vDate18; DELETE FROM vn.message WHERE sendDate < vDate; - DELETE FROM travel_reserve WHERE odbc_date < vDate; DELETE FROM cache.departure_limit WHERE Fecha < util.VN_CURDATE() - INTERVAL 1 MONTH; diff --git a/db/versions/10836-limeCordyline/29-kk.sql b/db/versions/10836-limeCordyline/29-kk.sql index 4683ae8a1..201a1c806 100644 --- a/db/versions/10836-limeCordyline/29-kk.sql +++ b/db/versions/10836-limeCordyline/29-kk.sql @@ -67,8 +67,8 @@ ALTER TABLE IF EXISTS vn2008.nichos__ COMMENT='refs #6372 @deprecated 2023-11-28 ALTER TABLE IF EXISTS vn2008.payroll_bonificaciones RENAME vn2008.payroll_bonificaciones__; ALTER TABLE IF EXISTS vn2008.payroll_bonificaciones__ COMMENT='refs #6372 @deprecated 2023-11-28;'; -ALTER TABLE IF EXISTS vn2008.payroll_daRENAMEs RENAME vn2008.payroll_daRENAMEs__; -ALTER TABLE IF EXISTS vn2008.payroll_daRENAMEs__ COMMENT='refs #6372 @deprecated 2023-11-28;'; +ALTER TABLE IF EXISTS vn2008.payroll_datos RENAME vn2008.payroll_datos__; +ALTER TABLE IF EXISTS vn2008.payroll_datos__ COMMENT='refs #6372 @deprecated 2023-11-28;'; ALTER TABLE IF EXISTS vn2008.payroll_embargos RENAME vn2008.payroll_embargos__; ALTER TABLE IF EXISTS vn2008.payroll_embargos__ COMMENT='refs #6372 @deprecated 2023-11-28;'; @@ -82,8 +82,8 @@ ALTER TABLE IF EXISTS vn2008.preparation_exception__ COMMENT='refs #6372 @deprec ALTER TABLE IF EXISTS vn2008.payrroll_apEmpresarial RENAME vn2008.payrroll_apEmpresarial__; ALTER TABLE IF EXISTS vn2008.payrroll_apEmpresarial__ COMMENT='refs #6372 @deprecated 2023-11-28;'; -ALTER TABLE IF EXISTS vn2008.rec_translaRENAMEr RENAME vn2008.rec_translaRENAMEr__; -ALTER TABLE IF EXISTS vn2008.rec_translaRENAMEr__ COMMENT='refs #6372 @deprecated 2023-11-28;'; +ALTER TABLE IF EXISTS vn2008.rec_translator RENAME vn2008.rec_translator__; +ALTER TABLE IF EXISTS vn2008.rec_translator__ COMMENT='refs #6372 @deprecated 2023-11-28;'; ALTER TABLE IF EXISTS vn2008.recibida_agricola RENAME vn2008.recibida_agricola__; ALTER TABLE IF EXISTS vn2008.recibida_agricola__ COMMENT='refs #6372 @deprecated 2023-11-28;'; @@ -94,8 +94,8 @@ ALTER TABLE IF EXISTS vn2008.rounding__ COMMENT='refs #6372 @deprecated 2023-11- ALTER TABLE IF EXISTS vn2008.scanTree RENAME vn2008.scanTree__; ALTER TABLE IF EXISTS vn2008.scanTree__ COMMENT='refs #6372 @deprecated 2023-11-28;'; -ALTER TABLE IF EXISTS vn2008.sort_merge_results_ernesRENAME RENAME vn2008.sort_merge_results_ernesRENAME__; -ALTER TABLE IF EXISTS vn2008.sort_merge_results_ernesRENAME__ COMMENT='refs #6372 @deprecated 2023-11-28;'; +ALTER TABLE IF EXISTS vn2008.sort_merge_results_ernesto RENAME vn2008.sort_merge_results_ernesto__; +ALTER TABLE IF EXISTS vn2008.sort_merge_results_ernesto__ COMMENT='refs #6372 @deprecated 2023-11-28;'; ALTER TABLE IF EXISTS vn2008.route RENAME vn2008.route__; ALTER TABLE IF EXISTS vn2008.route__ COMMENT='refs #6372 @deprecated 2023-11-28;'; From 37a47edfdc1ef9fa67ab5cf52cf7b0aa653ec74f Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 12 Feb 2024 12:25:58 +0100 Subject: [PATCH 18/86] refs #6372 --- .../vn/functions/isPalletHomogeneus.sql | 27 ------------------- .../vn/views/exchangeInsuranceInPrevious.sql | 9 ------- db/routines/vn/views/unaryScanLineBuy.sql | 6 ----- .../vn/views/unaryScanLineExpedition.sql | 6 ----- db/routines/vn2008/views/pago_sdc.sql | 16 +++++++++++ .../10836-limeCordyline/15-pago_sdc.sql | 11 ++++++++ 6 files changed, 27 insertions(+), 48 deletions(-) delete mode 100644 db/routines/vn/functions/isPalletHomogeneus.sql delete mode 100644 db/routines/vn/views/exchangeInsuranceInPrevious.sql delete mode 100644 db/routines/vn/views/unaryScanLineBuy.sql delete mode 100644 db/routines/vn/views/unaryScanLineExpedition.sql create mode 100644 db/routines/vn2008/views/pago_sdc.sql create mode 100644 db/versions/10836-limeCordyline/15-pago_sdc.sql diff --git a/db/routines/vn/functions/isPalletHomogeneus.sql b/db/routines/vn/functions/isPalletHomogeneus.sql deleted file mode 100644 index 39c6461ae..000000000 --- a/db/routines/vn/functions/isPalletHomogeneus.sql +++ /dev/null @@ -1,27 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`isPalletHomogeneus`(vExpedition INT) - RETURNS tinyint(1) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - DECLARE vScanId INT; - DECLARE vDistinctRoutesInThePallet INT; - - SELECT scan_id INTO vScanId - FROM vn2008.scan_line - WHERE code = vExpedition - LIMIT 1; - - SELECT COUNT(*) INTO vDistinctRoutesInThePallet - FROM ( - SELECT DISTINCT t.Id_Ruta - FROM vn2008.scan_line sl - JOIN vn2008.expeditions e ON e.expeditions_id = sl.code - JOIN vn2008.Tickets t ON t.Id_Ticket = e.ticket_id - WHERE sl.scan_id = vScanId - AND t.Id_Ruta - ) t1; - - RETURN vDistinctRoutesInThePallet = 1; -END$$ -DELIMITER ; diff --git a/db/routines/vn/views/exchangeInsuranceInPrevious.sql b/db/routines/vn/views/exchangeInsuranceInPrevious.sql deleted file mode 100644 index 097728bc7..000000000 --- a/db/routines/vn/views/exchangeInsuranceInPrevious.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`exchangeInsuranceInPrevious` -AS SELECT `ei`.`finished` AS `dated`, - `ei`.`amount` AS `amount`, - `ei`.`rate` AS `rate` -FROM `vn`.`exchangeInsurance` `ei` -WHERE `ei`.`amount` <> 0 - AND `ei`.`financialProductTypefk` = 'SC' diff --git a/db/routines/vn/views/unaryScanLineBuy.sql b/db/routines/vn/views/unaryScanLineBuy.sql deleted file mode 100644 index 26f178a45..000000000 --- a/db/routines/vn/views/unaryScanLineBuy.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`unaryScanLineBuy` -AS SELECT `u`.`scan_line_id` AS `unaryScanLineFk`, - `u`.`Id_Article` AS `itemFk` -FROM `vn2008`.`unary_scan_line_buy` `u` diff --git a/db/routines/vn/views/unaryScanLineExpedition.sql b/db/routines/vn/views/unaryScanLineExpedition.sql deleted file mode 100644 index e71c2423e..000000000 --- a/db/routines/vn/views/unaryScanLineExpedition.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`unaryScanLineExpedition` -AS SELECT `u`.`scan_line_id` AS `unaryScanLineFk`, - `u`.`expedition_id` AS `expeditionFk` -FROM `vn2008`.`unary_scan_line_expedition` `u` diff --git a/db/routines/vn2008/views/pago_sdc.sql b/db/routines/vn2008/views/pago_sdc.sql new file mode 100644 index 000000000..0fb6a172d --- /dev/null +++ b/db/routines/vn2008/views/pago_sdc.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`pago_sdc` +AS SELECT `ei`.`id` AS `pago_sdc_id`, + `ei`.`amount` AS `importe`, + `ei`.`dated` AS `fecha`, + `ei`.`finished` AS `vencimiento`, + `ei`.`entityFk` AS `entity_id`, + `ei`.`ref` AS `ref`, + `ei`.`rate` AS `rate`, + `ei`.`companyFk` AS `empresa_id`, + `ei`.`financialProductTypefk` AS `financialProductTypefk`, + `ei`.`upperBarrier` AS `upperBarrier`, + `ei`.`lowerBarrier` AS `lowerBarrier`, + `ei`.`strike` AS `strike` +FROM `vn`.`exchangeInsurance` `ei` \ No newline at end of file diff --git a/db/versions/10836-limeCordyline/15-pago_sdc.sql b/db/versions/10836-limeCordyline/15-pago_sdc.sql new file mode 100644 index 000000000..3225e2c4d --- /dev/null +++ b/db/versions/10836-limeCordyline/15-pago_sdc.sql @@ -0,0 +1,11 @@ +DROP VIEW IF EXISTS `vn`.`exchangeInsurance`; + +ALTER TABLE IF EXISTS `vn2008`.`pago_sdc` RENAME `vn`.`exchangeInsurance`; + +ALTER TABLE IF EXISTS `vn`.`exchangeInsurance` +CHANGE COLUMN IF EXISTS `pago_sdc_id` `id` int(11) NOT NULL AUTO_INCREMENT, +CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) NOT NULL, +CHANGE COLUMN IF EXISTS `fecha` `dated` date NOT NULL, +CHANGE COLUMN IF EXISTS `vencimiento` `finished` date NOT NULL, +CHANGE COLUMN IF EXISTS `entity_id` `entityFk` int(10) unsigned NOT NULL, +CHANGE COLUMN IF EXISTS `empresa_id` `companyFk`int(10) unsigned NOT NULL DEFAULT 442; From 51afb87122e498280031bbcff35c5928d7bd8560 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 13 Feb 2024 09:54:26 +0100 Subject: [PATCH 19/86] 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 20/86] 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 21/86] 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 22/86] 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 fd785ee429bbfe5d1bbeb6cd137a0becb1d12352 Mon Sep 17 00:00:00 2001 From: davidd Date: Wed, 14 Feb 2024 11:01:37 +0100 Subject: [PATCH 23/86] refs #6372 --- db/routines/vn/triggers/movementLabel_afterUpdate.sql | 2 +- db/routines/vn2008/views/pago_sdc.sql | 2 +- db/versions/10836-limeCordyline/15-pago_sdc.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/triggers/movementLabel_afterUpdate.sql b/db/routines/vn/triggers/movementLabel_afterUpdate.sql index cef8e2b43..7dd8a9eb9 100644 --- a/db/routines/vn/triggers/movementLabel_afterUpdate.sql +++ b/db/routines/vn/triggers/movementLabel_afterUpdate.sql @@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`movementLabel_afterUp AFTER UPDATE ON `vn`.`movementLabel` FOR EACH ROW IF NEW.stem >= (SELECT s.quantity FROM sale s WHERE s.id = NEW.saleFk) THEN - UPDATE sale s SET s.isPicked = 1 WHERE s.id = NEW.saleFk; + UPDATE sale s SET s.isPicked = TRUE WHERE s.id = NEW.saleFk; END IF$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn2008/views/pago_sdc.sql b/db/routines/vn2008/views/pago_sdc.sql index 0fb6a172d..3d9f188d3 100644 --- a/db/routines/vn2008/views/pago_sdc.sql +++ b/db/routines/vn2008/views/pago_sdc.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn2008`.`pago_sdc` AS SELECT `ei`.`id` AS `pago_sdc_id`, `ei`.`amount` AS `importe`, - `ei`.`dated` AS `fecha`, + `ei`.`dueDated` AS `fecha`, `ei`.`finished` AS `vencimiento`, `ei`.`entityFk` AS `entity_id`, `ei`.`ref` AS `ref`, diff --git a/db/versions/10836-limeCordyline/15-pago_sdc.sql b/db/versions/10836-limeCordyline/15-pago_sdc.sql index 3225e2c4d..002de4adc 100644 --- a/db/versions/10836-limeCordyline/15-pago_sdc.sql +++ b/db/versions/10836-limeCordyline/15-pago_sdc.sql @@ -5,7 +5,7 @@ ALTER TABLE IF EXISTS `vn2008`.`pago_sdc` RENAME `vn`.`exchangeInsurance`; ALTER TABLE IF EXISTS `vn`.`exchangeInsurance` CHANGE COLUMN IF EXISTS `pago_sdc_id` `id` int(11) NOT NULL AUTO_INCREMENT, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) NOT NULL, -CHANGE COLUMN IF EXISTS `fecha` `dated` date NOT NULL, +CHANGE COLUMN IF EXISTS `fecha` `dueDated` date NOT NULL, CHANGE COLUMN IF EXISTS `vencimiento` `finished` date NOT NULL, CHANGE COLUMN IF EXISTS `entity_id` `entityFk` int(10) unsigned NOT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk`int(10) unsigned NOT NULL DEFAULT 442; From 32f8d133594d27d6930810ff3a349b0133cb1865 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 14 Feb 2024 13:15:31 +0100 Subject: [PATCH 24/86] fix: refs #6760 back modified & revoke update on ticket.clientFk --- .../vn/triggers/ticket_beforeUpdate.sql | 10 --- .../00-revokeUpdateClient.sql | 37 ++++++++++ .../ticket/specs/transferClient.spec.js | 71 ++++++++++-------- .../back/methods/ticket/transferClient.js | 73 ++++++++++++------- 4 files changed, 126 insertions(+), 65 deletions(-) create mode 100644 db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql diff --git a/db/routines/vn/triggers/ticket_beforeUpdate.sql b/db/routines/vn/triggers/ticket_beforeUpdate.sql index 0836b2486..72831bc3d 100644 --- a/db/routines/vn/triggers/ticket_beforeUpdate.sql +++ b/db/routines/vn/triggers/ticket_beforeUpdate.sql @@ -4,7 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_beforeUpdate` FOR EACH ROW BEGIN DECLARE vNewTime TIME; - DECLARE vHasTicketRefund BOOL; SET NEW.editorFk = account.myUser_getId(); @@ -64,14 +63,5 @@ BEGIN CALL vn.routeUpdateM3(NEW.routeFk); END IF; - - SELECT COUNT(*) INTO vHasTicketRefund - FROM ticketRefund - WHERE originalTicketFk = NEW.id - OR refundTicketFk = NEW.id; - - IF vHasTicketRefund AND NEW.clientFk <> OLD.clientFk THEN - CALL util.throw('The ticket has a refund associated'); - END IF; END$$ DELIMITER ; diff --git a/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql b/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql new file mode 100644 index 000000000..b22e09615 --- /dev/null +++ b/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql @@ -0,0 +1,37 @@ +REVOKE UPDATE ON vn.ticket FROM employee; + +GRANT UPDATE (id, + warehouseFk, + shipped, + nickname, + refFk, + addressFk, + workerFk, + observations, + isSigned, + isLabeled, + isPrinted, + packages, + location, + hour, + created, + isBlocked, + solution, + routeFk, + priority, + hasPriority, + companyFk, + agencyModeFk, + landed, + isBoxed, + isDeleted, + zoneFk, + zonePrice, + zoneBonus, + totalWithVat, + totalWithoutVat, + weight, + clonedFrom, + cmrFk, + editorFk) + ON vn.ticket TO employee; diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 5a9edd17e..5f1c09776 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -1,49 +1,60 @@ const models = require('vn-loopback/server/server').models; describe('Ticket transferClient()', () => { - const userId = 9; - const activeCtx = { - accessToken: {userId: userId}, - }; - const ctx = {req: activeCtx}; + const originalTicketId = 8; + const refundTicketId = 24; + const clientId = 1; + let ctx; + let options; + let tx; + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} + }; + + options = {transaction: tx}; + tx = await models.Ticket.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); it('should throw an error as the ticket is not editable', async() => { - const tx = await models.Ticket.beginTransaction({}); - let error; - try { - const options = {transaction: tx}; const ticketId = 4; const clientId = 1; await models.Ticket.transferClient(ctx, ticketId, clientId, options); - - await tx.rollback(); } catch (e) { - await tx.rollback(); - error = e; + expect(e.message).toEqual(`This ticket is locked`); } - - expect(error.message).toEqual(`This ticket is locked`); }); - it('should be assigned a different clientFk', async() => { - const tx = await models.Ticket.beginTransaction({}); - let updatedTicket; - const ticketId = 10; - const clientId = 1; + it('should be assigned a different clientFk in the original ticket', async() => { + await models.Ticket.transferClient(ctx, 2, clientId, options); + const afterTransfer = await models.Ticket.findById(2, null, options); - try { - const options = {transaction: tx}; + expect(afterTransfer.clientFk).toEqual(clientId); + }); - await models.Ticket.transferClient(ctx, ticketId, clientId, options); - updatedTicket = await models.Ticket.findById(ticketId, {fields: ['clientFk']}, options); + it('should be assigned a different clientFk in the original and refund ticket and claim', async() => { + await models.Ticket.transferClient(ctx, originalTicketId, clientId, options); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + const [originalTicket, refundTicket] = await models.Ticket.find({ + where: {id: {inq: [originalTicketId, refundTicketId]}} + }, options); - expect(updatedTicket.clientFk).toEqual(clientId); + const claim = await models.Claim.findOne({ + where: {ticketFk: originalTicketId} + }, options); + + expect(originalTicket.clientFk).toEqual(clientId); + expect(refundTicket.clientFk).toEqual(clientId); + expect(claim.clientFk).toEqual(clientId); }); }); diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 60e70d710..1db49b274 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -2,20 +2,17 @@ module.exports = Self => { Self.remoteMethodCtx('transferClient', { description: 'Transfering ticket to another client', accessType: 'WRITE', - accepts: [ - { - arg: 'id', - type: 'number', - required: true, - description: 'the ticket id', - http: {source: 'path'} - }, - { - arg: 'clientFk', - type: 'number', - required: true, - }, - ], + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'the ticket id', + http: {source: 'path'} + }, { + arg: 'clientFk', + type: 'number', + required: true, + }], http: { path: `/:id/transferClient`, verb: 'PATCH' @@ -25,21 +22,47 @@ module.exports = Self => { Self.transferClient = async(ctx, id, clientFk, options) => { const models = Self.app.models; const myOptions = {}; + const tickets = []; + let tx; + if (typeof options == 'object') Object.assign(myOptions, options); - await Self.isEditableOrThrow(ctx, id, myOptions); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } - const ticket = await models.Ticket.findById( - id, - {fields: ['id', 'shipped', 'clientFk', 'addressFk']}, - myOptions - ); - const client = await models.Client.findById(clientFk, {fields: ['id', 'defaultAddressFk']}, myOptions); + try { + await Self.isEditableOrThrow(ctx, id, myOptions); - await ticket.updateAttributes({ - clientFk, - addressFk: client.defaultAddressFk, - }); + const ticketRelation = await models.TicketRefund.findOne({ + where: {or: [{originalTicketFk: id}, {refundTicketFk: id}]}, + include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}] + }, myOptions); + + const {defaultAddressFk: addressFk} = await models.Client.findById(clientFk, + {fields: ['id', 'defaultAddressFk']}, myOptions); + + const attributes = {clientFk, addressFk}; + + if (ticketRelation) { + const {refundTicket, originalTicket} = ticketRelation; + tickets.push(refundTicket(), originalTicket()); + + for (const ticket of tickets) + await ticket.updateAttributes(attributes, myOptions); + } else + await Self.updateAll({id}, attributes, myOptions); + + const ticketIds = tickets.length ? tickets.map(ticket => ticket.id) : [id]; + + await models.Claim.updateAll({ticketFk: {inq: ticketIds}}, {clientFk}, myOptions); + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } }; }; From 05b7c37b94c6c51ecb1fb0c9754de2950f1f1c0b Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 15 Feb 2024 07:49:17 +0100 Subject: [PATCH 25/86] 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 26/86] 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 27/86] 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 be7a570314d9d57df8e1b86e72a8d4dce6e08115 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 15 Feb 2024 11:18:01 +0100 Subject: [PATCH 28/86] fix: refs #6776 test --- .../item-shelving/specs/makeMulti.spec.js | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js index a8d0c197e..97b7e772f 100644 --- a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js +++ b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js @@ -1,54 +1,55 @@ const {models} = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); -describe('ItemShelving makeMulti()', () => { +fdescribe('ItemShelving makeMulti()', () => { const warehouseFk = 1; + let ctx; + let options; + let tx; - beforeAll(async() => { + beforeEach(async() => { ctx = { - accessToken: {userId: 9}, req: { - headers: {origin: 'http://localhost'}, - } + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx.req + }); + + options = {transaction: tx}; + tx = await models.ItemShelving.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); }); it('should add two new records', async() => { const shelvingFk = 'ZPP'; const items = [1, 1, 1, 2]; - const tx = await models.ItemShelving.beginTransaction({}); - const options = {transaction: tx}; - try { - await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); - const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); + await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options); + const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); - expect(itemShelvings.length).toEqual(2); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(itemShelvings.length).toEqual(2); }); it('should update the visible items', async() => { const shelvingFk = 'GVC'; const items = [2, 2]; - const tx = await models.ItemShelving.beginTransaction({}); - const options = {transaction: tx}; - try { - const {visible: itemsBefore} = await models.ItemShelving.findOne({ - where: {shelvingFk, itemFk: items[0]} - }, options); - await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); - const {visible: itemsAfter} = await models.ItemShelving.findOne({ - where: {shelvingFk, itemFk: items[0]} - }, options); + const {visible: itemsBefore} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options); + const {visible: itemsAfter} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); - expect(itemsAfter).toEqual(itemsBefore + 2); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(itemsAfter).toEqual(itemsBefore + 2); }); }); From 98d2b5a0ffcfd3a7099c12955c0105867a2ebd04 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 15 Feb 2024 12:59:30 +0100 Subject: [PATCH 29/86] hotfix creditClient --- .../client/back/methods/client/setRating.js | 2 +- .../methods/client/specs/setRating.spec.js | 22 +++++++++++++++++++ modules/client/back/models/client.js | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/setRating.js b/modules/client/back/methods/client/setRating.js index 21ac0c914..e3f866683 100644 --- a/modules/client/back/methods/client/setRating.js +++ b/modules/client/back/methods/client/setRating.js @@ -28,7 +28,6 @@ module.exports = Self => { Self.setRating = async function(ctx, id, rating, recommendedCredit, options) { let tx; const myOptions = {}; - if (typeof options == 'object') Object.assign(myOptions, options); @@ -42,6 +41,7 @@ module.exports = Self => { const clientUpdated = await client.updateAttributes({ rating: rating, recommendedCredit: recommendedCredit + }, myOptions); if (tx) await tx.commit(); diff --git a/modules/client/back/methods/client/specs/setRating.spec.js b/modules/client/back/methods/client/specs/setRating.spec.js index a7d0fb03a..353095e31 100644 --- a/modules/client/back/methods/client/specs/setRating.spec.js +++ b/modules/client/back/methods/client/specs/setRating.spec.js @@ -40,4 +40,26 @@ describe('Client setRating()', () => { throw e; } }); + + it('should change rating and recommendedCredit to 0', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const clientId = 1101; + const newRating = 0; + const newRecommendedCredit = 0; + + const updatedClient = await models.Client.setRating(ctx, clientId, newRating, newRecommendedCredit, options); + + expect(updatedClient.rating).toEqual(newRating); + expect(updatedClient.recommendedCredit).toEqual(newRecommendedCredit); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index a9e14effa..0a8ebcae5 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -319,7 +319,8 @@ module.exports = Self => { await Self.changeCredit(ctx, finalState, changes); // Credit management changes - if (changes?.rating || changes?.recommendedCredit) + + if (changes?.rating >= 0 || changes?.recommendedCredit >= 0) await Self.changeCreditManagement(ctx, finalState, changes); const oldInstance = {}; From 04fe6a8596e2e8994aa6b1ff0f0a2187c08e4d3f Mon Sep 17 00:00:00 2001 From: davidd Date: Thu, 15 Feb 2024 13:58:12 +0100 Subject: [PATCH 30/86] refs #6372 --- db/versions/10836-limeCordyline/14-movement_label.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10836-limeCordyline/14-movement_label.sql b/db/versions/10836-limeCordyline/14-movement_label.sql index bb762e1ba..5ce130cf8 100644 --- a/db/versions/10836-limeCordyline/14-movement_label.sql +++ b/db/versions/10836-limeCordyline/14-movement_label.sql @@ -1,4 +1,4 @@ -DROP TRIGGER IF EXISTS `vn2008`.`movement_label_au`; +DROP TRIGGER IF EXISTS `vn2008`.`movement_label_afterUpdate`; ALTER TABLE IF EXISTS `vn2008`.`movement_label` RENAME `vn`.`movementLabel`; From 27627017c5f6c065815f7061b77527fef65e4b48 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 15 Feb 2024 14:21:49 +0100 Subject: [PATCH 31/86] 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 f11aa2605ba6ac09d1481ab46b1c278e15915b57 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 15 Feb 2024 14:48:30 +0100 Subject: [PATCH 32/86] feat: refs #6776 back & procedure modified --- .../vn/procedures/itemShelving_add.sql | 4 +++ .../back/methods/item-shelving/makeMulti.js | 27 +++++++------------ .../item-shelving/specs/makeMulti.spec.js | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 02762fa0b..2a4676b50 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -19,6 +19,10 @@ BEGIN DECLARE vItemFk INT; SELECT barcodeToItem(vBarcode) INTO vItemFk; + + SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)); + + SET vQuantity = vQuantity * vPacking; IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN diff --git a/modules/item/back/methods/item-shelving/makeMulti.js b/modules/item/back/methods/item-shelving/makeMulti.js index 4fd895eec..9992eaf57 100644 --- a/modules/item/back/methods/item-shelving/makeMulti.js +++ b/modules/item/back/methods/item-shelving/makeMulti.js @@ -37,27 +37,20 @@ module.exports = Self => { myOptions.transaction = tx; } - const discardItems = []; + const discardItems = new Set(); + const itemCounts = items.reduce((acc, item) => { + acc[item] = (acc[item] || 0) + 1; + return acc; + }, {}); try { for (let item of items) { - if (!discardItems.includes(item)) { - let quantity = items.reduce((acc, cur) => { - return acc + (cur === item ? 1 : 0); - }, 0); - discardItems.push(item); + if (!discardItems.has(item)) { + let quantity = itemCounts[item]; + discardItems.add(item); - const [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?) itemPacking', - [item, warehouseFk], myOptions); - let packing; - - if (result) packing = result.itemPacking; - if (!packing) packing = 1; - - quantity = quantity * packing; - - await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, ?, ?)', - [shelvingFk, item, quantity, packing, warehouseFk], myOptions + await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, NULL, ?)', + [shelvingFk, item, quantity, warehouseFk], myOptions ); } } diff --git a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js index 97b7e772f..d5df0493c 100644 --- a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js +++ b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -fdescribe('ItemShelving makeMulti()', () => { +describe('ItemShelving makeMulti()', () => { const warehouseFk = 1; let ctx; let options; From 78583751ec227a10305271afa07f1d4c4f03274f Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 15 Feb 2024 16:22:13 +0100 Subject: [PATCH 33/86] refactor: refs #6760 ticketsIds improved --- .../back/methods/ticket/transferClient.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 1db49b274..d38c0e8a7 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -22,7 +22,6 @@ module.exports = Self => { Self.transferClient = async(ctx, id, clientFk, options) => { const models = Self.app.models; const myOptions = {}; - const tickets = []; let tx; if (typeof options == 'object') @@ -36,7 +35,7 @@ module.exports = Self => { try { await Self.isEditableOrThrow(ctx, id, myOptions); - const ticketRelation = await models.TicketRefund.findOne({ + const ticketRefund = await models.TicketRefund.findOne({ where: {or: [{originalTicketFk: id}, {refundTicketFk: id}]}, include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}] }, myOptions); @@ -46,16 +45,21 @@ module.exports = Self => { const attributes = {clientFk, addressFk}; - if (ticketRelation) { - const {refundTicket, originalTicket} = ticketRelation; + const tickets = []; + const ticketIds = []; + + if (ticketRefund) { + const {refundTicket, originalTicket} = ticketRefund; tickets.push(refundTicket(), originalTicket()); - for (const ticket of tickets) + for (const ticket of tickets) { await ticket.updateAttributes(attributes, myOptions); - } else + ticketIds.push(ticket.id); + } + } else { await Self.updateAll({id}, attributes, myOptions); - - const ticketIds = tickets.length ? tickets.map(ticket => ticket.id) : [id]; + ticketIds.push(id); + } await models.Claim.updateAll({ticketFk: {inq: ticketIds}}, {clientFk}, myOptions); From ae0ce91127bd780e33ab9263fd3cb0edd09276bd Mon Sep 17 00:00:00 2001 From: davidd Date: Fri, 16 Feb 2024 06:10:09 +0100 Subject: [PATCH 34/86] refs #6685 --- db/routines/vn2008/views/credit.sql | 11 +++++++++++ db/versions/10888-brownBirch/00-firstScript.sql | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 db/routines/vn2008/views/credit.sql create mode 100644 db/versions/10888-brownBirch/00-firstScript.sql diff --git a/db/routines/vn2008/views/credit.sql b/db/routines/vn2008/views/credit.sql new file mode 100644 index 000000000..04b44f42b --- /dev/null +++ b/db/routines/vn2008/views/credit.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`credit` +AS SELECT + `c`.`id` AS `id`, + `c`.`clientFk` AS `Id_Cliente`, + `c`.`workerFk` AS `Id_Trabajador`, + `c`.`amount` AS `amount`, + `c`.`created` AS `odbc_date` +FROM + `vn`.`clientCredit` `c` \ No newline at end of file diff --git a/db/versions/10888-brownBirch/00-firstScript.sql b/db/versions/10888-brownBirch/00-firstScript.sql new file mode 100644 index 000000000..7c8f96339 --- /dev/null +++ b/db/versions/10888-brownBirch/00-firstScript.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`credit`AS + SELECT 1; + +GRANT SELECT ON TABLE vn2008.credit TO financialBoss; From a76872a082f7428a2aeb98b4d3332533ad1dc52e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 16 Feb 2024 07:08:01 +0100 Subject: [PATCH 35/86] refs #6669 fix:ticket_isOutClosureZone --- db/routines/vn/functions/ticket_isOutClosureZone.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/functions/ticket_isOutClosureZone.sql b/db/routines/vn/functions/ticket_isOutClosureZone.sql index 30589c87a..ebddcf505 100644 --- a/db/routines/vn/functions/ticket_isOutClosureZone.sql +++ b/db/routines/vn/functions/ticket_isOutClosureZone.sql @@ -9,7 +9,7 @@ BEGIN * @param vSelf Ticket id * @return true o false */ - DECLARE vIsTicketInTime BOOL DEFAULT FALSE; + DECLARE vIsTicketInTime BOOL; SELECT TIMEDIFF(CURRENT_TIME(), zc.hour + INTERVAL tc.packingDelay HOUR) > 0 INTO vIsTicketInTime FROM vn.ticket t From 59ea47a8c33acf5d4de6beea36a46eeb9248c282 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 16 Feb 2024 13:06:33 +0100 Subject: [PATCH 36/86] refs #6414 tback --- .../back/methods/worker/specs/new.spec.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index d0830b00f..f5deb86ef 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -36,6 +36,26 @@ describe('Worker new', () => { payMethodFk: 1, roleFk: 1 }; + + const clientWorker = { + fi: '09412983A', + name: 'CLIENTWORKER', + firstName: 'CLIENT', + lastNames: 'WORKER', + email: 'clientWorker@mydomain.com', + street: 'S/ DEFAULTWORKERSTREET', + city: 'defaultWorkerCity', + provinceFk: 1, + companyFk: 442, + postcode: '46680', + phone: '123456489', + code: 'CCW', + bossFk: 9, + birth: '2022-12-11T23:00:00.000Z', + payMethodFk: 1, + roleFk: 1 + }; + const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -149,6 +169,18 @@ describe('Worker new', () => { expect(newWorker.id).toBeDefined(); }); + it('should create a new client', async() => { + const newWorker = await models.Worker.new({args: clientWorker, req}); + + await models.Worker.destroyById(newWorker.id); + await models.Address.destroyAll({clientFk: newWorker.id}); + await models.Mandate.destroyAll({clientFk: newWorker.id}); + await models.Client.destroyById(newWorker.id); + await models.VnUser.destroyById(newWorker.id); + + expect(newWorker.id).toBeDefined(); + }); + it('should create a new worker in client', async() => { const bruceWayneId = 1101; const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']}); From 69acebb43c8cde41aa15603e52d32b41a6c046a4 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 16 Feb 2024 13:48:55 +0100 Subject: [PATCH 37/86] fix: refs #6776 replace name --- .../item-shelving/{makeMulti.js => addListByItem.js} | 6 +++--- .../specs/{makeMulti.spec.js => addListByItem.spec.js} | 6 +++--- modules/item/back/models/item-shelving.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename modules/item/back/methods/item-shelving/{makeMulti.js => addListByItem.js} (90%) rename modules/item/back/methods/item-shelving/specs/{makeMulti.spec.js => addListByItem.spec.js} (85%) diff --git a/modules/item/back/methods/item-shelving/makeMulti.js b/modules/item/back/methods/item-shelving/addListByItem.js similarity index 90% rename from modules/item/back/methods/item-shelving/makeMulti.js rename to modules/item/back/methods/item-shelving/addListByItem.js index 9992eaf57..da8ed0e1b 100644 --- a/modules/item/back/methods/item-shelving/makeMulti.js +++ b/modules/item/back/methods/item-shelving/addListByItem.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('makeMulti', { + Self.remoteMethodCtx('addListByItem', { description: 'Add a record or update it if it already exists.', accessType: 'WRITE', accepts: [{ @@ -20,12 +20,12 @@ module.exports = Self => { }], http: { - path: `/makeMulti`, + path: `/addListByItem`, verb: 'POST' } }); - Self.makeMulti = async(ctx, shelvingFk, items, warehouseFk, options) => { + Self.addListByItem = async(ctx, shelvingFk, items, warehouseFk, options) => { const myOptions = {userId: ctx.req.accessToken.userId}; let tx; diff --git a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js similarity index 85% rename from modules/item/back/methods/item-shelving/specs/makeMulti.spec.js rename to modules/item/back/methods/item-shelving/specs/addListByItem.spec.js index d5df0493c..2d9dd600a 100644 --- a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js +++ b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -describe('ItemShelving makeMulti()', () => { +describe('ItemShelving addListByItem()', () => { const warehouseFk = 1; let ctx; let options; @@ -33,7 +33,7 @@ describe('ItemShelving makeMulti()', () => { const shelvingFk = 'ZPP'; const items = [1, 1, 1, 2]; - await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options); + await models.ItemShelving.addListByItem(ctx, shelvingFk, items, warehouseFk, options); const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); expect(itemShelvings.length).toEqual(2); @@ -45,7 +45,7 @@ describe('ItemShelving makeMulti()', () => { const {visible: itemsBefore} = await models.ItemShelving.findOne({ where: {shelvingFk, itemFk: items[0]} }, options); - await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options); + await models.ItemShelving.addListByItem(ctx, shelvingFk, items, warehouseFk, options); const {visible: itemsAfter} = await models.ItemShelving.findOne({ where: {shelvingFk, itemFk: items[0]} }, options); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index 9bc94fa1e..a3c596f94 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -1,5 +1,5 @@ module.exports = Self => { require('../methods/item-shelving/deleteItemShelvings')(Self); - require('../methods/item-shelving/makeMulti')(Self); + require('../methods/item-shelving/addListByItem')(Self); require('../methods/item-shelving/getInventory')(Self); }; From 15de4f0b73c767f118d86c99f5bdc32dd07e818b Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 16 Feb 2024 15:56:40 +0100 Subject: [PATCH 38/86] refs #6531 feat:showLastTickets --- .../10890-redOrchid/00-firstScript.sql | 3 +++ .../methods/ticket/getLastTicketsByWorker.js | 25 +++++++++++++++++++ .../specs/getLastTicketsByWorker.spec.js | 10 ++++++++ modules/ticket/back/models/ticket-methods.js | 1 + 4 files changed, 39 insertions(+) create mode 100644 db/versions/10890-redOrchid/00-firstScript.sql create mode 100644 modules/ticket/back/methods/ticket/getLastTicketsByWorker.js create mode 100644 modules/ticket/back/methods/ticket/specs/getLastTicketsByWorker.spec.js diff --git a/db/versions/10890-redOrchid/00-firstScript.sql b/db/versions/10890-redOrchid/00-firstScript.sql new file mode 100644 index 000000000..13d3b3c13 --- /dev/null +++ b/db/versions/10890-redOrchid/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES( 'Ticket', 'getLastTicketsByWorker', '*', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/getLastTicketsByWorker.js b/modules/ticket/back/methods/ticket/getLastTicketsByWorker.js new file mode 100644 index 000000000..2a3108a42 --- /dev/null +++ b/modules/ticket/back/methods/ticket/getLastTicketsByWorker.js @@ -0,0 +1,25 @@ +module.exports = Self => { + Self.remoteMethodCtx('getLastTicketsByWorker', { + description: 'Get list of last tickets which user has modified', + accessType: 'READ', + returns: { + type: 'object', + root: true + }, + http: { + path: `/getLastTicketsByWorker`, + verb: 'GET' + } + }); + + Self.getLastTicketsByWorker = async ctx => { + const userId = ctx.req.accessToken.userId; + const query = + `SELECT ticketFk, MAX(created) created + FROM ticketTracking tt + WHERE tt.userFk = ? + GROUP BY ticketFk + LIMIT 5;`; + return await Self.rawSql(query, [userId]); + }; +}; diff --git a/modules/ticket/back/methods/ticket/specs/getLastTicketsByWorker.spec.js b/modules/ticket/back/methods/ticket/specs/getLastTicketsByWorker.spec.js new file mode 100644 index 000000000..ef26bafed --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/getLastTicketsByWorker.spec.js @@ -0,0 +1,10 @@ +const {models} = require('vn-loopback/server/server'); + +describe('getLastTicketsByWorker()', () => { + it('return list of last tickets which user has modified', async() => { + let ctx = {req: {accessToken: {userId: 100}}}; + let response = await models.Ticket.getLastTicketsByWorker(ctx); + + expect(response.length).toBeGreaterThan(0); + }); +}); diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 8914e9c4f..c3cfe33c2 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -45,4 +45,5 @@ module.exports = function(Self) { require('../methods/ticket/invoiceTickets')(Self); require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/docuwareDownload')(Self); + require('../methods/ticket/getLastTicketsByWorker')(Self); }; From 3ef26bfd7d2b1ccbadb8c0f62ba42c25b2e695e2 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 19 Feb 2024 08:34:17 +0100 Subject: [PATCH 39/86] packing --- db/routines/vn/procedures/sale_getBoxPickingList.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 84ae45614..0af23e945 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -28,7 +28,7 @@ BEGIN MAKETIME(pb.HH,pb.mm,0) etd, pb.routeFk, FLOOR(s.quantity / ish.packing) stickers, - ish.packing, + IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, b.packagingFk FROM sale s JOIN item i ON i.id = s.itemFk From 5b541aa8040a7144692deef988d5a6131ef223f5 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 19 Feb 2024 09:13:03 +0100 Subject: [PATCH 40/86] refs #6531 feat:modify name --- db/versions/10890-redOrchid/00-firstScript.sql | 2 +- .../ticket/{getLastTicketsByWorker.js => myLastModified.js} | 2 +- .../{getLastTicketsByWorker.spec.js => myLastModified.spec.js} | 0 modules/ticket/back/models/ticket-methods.js | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename modules/ticket/back/methods/ticket/{getLastTicketsByWorker.js => myLastModified.js} (89%) rename modules/ticket/back/methods/ticket/specs/{getLastTicketsByWorker.spec.js => myLastModified.spec.js} (100%) diff --git a/db/versions/10890-redOrchid/00-firstScript.sql b/db/versions/10890-redOrchid/00-firstScript.sql index 13d3b3c13..17bf974a1 100644 --- a/db/versions/10890-redOrchid/00-firstScript.sql +++ b/db/versions/10890-redOrchid/00-firstScript.sql @@ -1,3 +1,3 @@ -- Place your SQL code here INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) -VALUES( 'Ticket', 'getLastTicketsByWorker', '*', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file +VALUES( 'Ticket', 'myLastModified', '*', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/getLastTicketsByWorker.js b/modules/ticket/back/methods/ticket/myLastModified.js similarity index 89% rename from modules/ticket/back/methods/ticket/getLastTicketsByWorker.js rename to modules/ticket/back/methods/ticket/myLastModified.js index 2a3108a42..84812eec1 100644 --- a/modules/ticket/back/methods/ticket/getLastTicketsByWorker.js +++ b/modules/ticket/back/methods/ticket/myLastModified.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('getLastTicketsByWorker', { + Self.remoteMethodCtx('myLastModified', { description: 'Get list of last tickets which user has modified', accessType: 'READ', returns: { diff --git a/modules/ticket/back/methods/ticket/specs/getLastTicketsByWorker.spec.js b/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js similarity index 100% rename from modules/ticket/back/methods/ticket/specs/getLastTicketsByWorker.spec.js rename to modules/ticket/back/methods/ticket/specs/myLastModified.spec.js diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index c3cfe33c2..d204a8102 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -45,5 +45,5 @@ module.exports = function(Self) { require('../methods/ticket/invoiceTickets')(Self); require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/docuwareDownload')(Self); - require('../methods/ticket/getLastTicketsByWorker')(Self); + require('../methods/ticket/myLastModified')(Self); }; From adeca2bb2268088ae01d27720ad48892f8eda5bf Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 19 Feb 2024 09:17:57 +0100 Subject: [PATCH 41/86] refs #6531 feat:modify name --- .../back/methods/ticket/myLastModified.js | 50 +++++++++---------- .../ticket/specs/myLastModified.spec.js | 20 ++++---- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/modules/ticket/back/methods/ticket/myLastModified.js b/modules/ticket/back/methods/ticket/myLastModified.js index 84812eec1..a47ea570f 100644 --- a/modules/ticket/back/methods/ticket/myLastModified.js +++ b/modules/ticket/back/methods/ticket/myLastModified.js @@ -1,25 +1,25 @@ -module.exports = Self => { - Self.remoteMethodCtx('myLastModified', { - description: 'Get list of last tickets which user has modified', - accessType: 'READ', - returns: { - type: 'object', - root: true - }, - http: { - path: `/getLastTicketsByWorker`, - verb: 'GET' - } - }); - - Self.getLastTicketsByWorker = async ctx => { - const userId = ctx.req.accessToken.userId; - const query = - `SELECT ticketFk, MAX(created) created - FROM ticketTracking tt - WHERE tt.userFk = ? - GROUP BY ticketFk - LIMIT 5;`; - return await Self.rawSql(query, [userId]); - }; -}; +module.exports = Self => { + Self.remoteMethodCtx('myLastModified', { + description: 'Get list of last tickets which user has modified', + accessType: 'READ', + returns: { + type: 'object', + root: true + }, + http: { + path: `/myLastModified`, + verb: 'GET' + } + }); + + Self.myLastModified = async ctx => { + const userId = ctx.req.accessToken.userId; + const query = + `SELECT ticketFk, MAX(created) created + FROM ticketTracking tt + WHERE tt.userFk = ? + GROUP BY ticketFk + LIMIT 5;`; + return await Self.rawSql(query, [userId]); + }; +}; diff --git a/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js b/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js index ef26bafed..6f245a032 100644 --- a/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js +++ b/modules/ticket/back/methods/ticket/specs/myLastModified.spec.js @@ -1,10 +1,10 @@ -const {models} = require('vn-loopback/server/server'); - -describe('getLastTicketsByWorker()', () => { - it('return list of last tickets which user has modified', async() => { - let ctx = {req: {accessToken: {userId: 100}}}; - let response = await models.Ticket.getLastTicketsByWorker(ctx); - - expect(response.length).toBeGreaterThan(0); - }); -}); +const {models} = require('vn-loopback/server/server'); + +describe('myLastModified()', () => { + it('return list of last tickets which user has modified', async() => { + let ctx = {req: {accessToken: {userId: 100}}}; + let response = await models.Ticket.myLastModified(ctx); + + expect(response.length).toBeGreaterThan(0); + }); +}); From 12f3af68bf6d85bc9cbd2297ef6c03a9cd2205d0 Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 19 Feb 2024 11:04:07 +0100 Subject: [PATCH 42/86] refs #6372 --- db/routines/vn2008/views/pago_sdc.sql | 2 +- db/versions/10836-limeCordyline/15-pago_sdc.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn2008/views/pago_sdc.sql b/db/routines/vn2008/views/pago_sdc.sql index 3d9f188d3..0fb6a172d 100644 --- a/db/routines/vn2008/views/pago_sdc.sql +++ b/db/routines/vn2008/views/pago_sdc.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn2008`.`pago_sdc` AS SELECT `ei`.`id` AS `pago_sdc_id`, `ei`.`amount` AS `importe`, - `ei`.`dueDated` AS `fecha`, + `ei`.`dated` AS `fecha`, `ei`.`finished` AS `vencimiento`, `ei`.`entityFk` AS `entity_id`, `ei`.`ref` AS `ref`, diff --git a/db/versions/10836-limeCordyline/15-pago_sdc.sql b/db/versions/10836-limeCordyline/15-pago_sdc.sql index 002de4adc..3225e2c4d 100644 --- a/db/versions/10836-limeCordyline/15-pago_sdc.sql +++ b/db/versions/10836-limeCordyline/15-pago_sdc.sql @@ -5,7 +5,7 @@ ALTER TABLE IF EXISTS `vn2008`.`pago_sdc` RENAME `vn`.`exchangeInsurance`; ALTER TABLE IF EXISTS `vn`.`exchangeInsurance` CHANGE COLUMN IF EXISTS `pago_sdc_id` `id` int(11) NOT NULL AUTO_INCREMENT, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) NOT NULL, -CHANGE COLUMN IF EXISTS `fecha` `dueDated` date NOT NULL, +CHANGE COLUMN IF EXISTS `fecha` `dated` date NOT NULL, CHANGE COLUMN IF EXISTS `vencimiento` `finished` date NOT NULL, CHANGE COLUMN IF EXISTS `entity_id` `entityFk` int(10) unsigned NOT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk`int(10) unsigned NOT NULL DEFAULT 442; From fc6e34ddfd2835f32383956743299f7f59a1bdf1 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 19 Feb 2024 11:18:05 +0100 Subject: [PATCH 43/86] fix: refs #6776 replace name --- .../back/methods/item-shelving/specs/addListByItem.spec.js | 6 +++--- .../item-shelving/{addListByItem.js => upsertItem.js} | 6 +++--- modules/item/back/models/item-shelving.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename modules/item/back/methods/item-shelving/{addListByItem.js => upsertItem.js} (90%) diff --git a/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js index 2d9dd600a..e31ff2e61 100644 --- a/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js +++ b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -describe('ItemShelving addListByItem()', () => { +describe('ItemShelving upsertItem()', () => { const warehouseFk = 1; let ctx; let options; @@ -33,7 +33,7 @@ describe('ItemShelving addListByItem()', () => { const shelvingFk = 'ZPP'; const items = [1, 1, 1, 2]; - await models.ItemShelving.addListByItem(ctx, shelvingFk, items, warehouseFk, options); + await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); expect(itemShelvings.length).toEqual(2); @@ -45,7 +45,7 @@ describe('ItemShelving addListByItem()', () => { const {visible: itemsBefore} = await models.ItemShelving.findOne({ where: {shelvingFk, itemFk: items[0]} }, options); - await models.ItemShelving.addListByItem(ctx, shelvingFk, items, warehouseFk, options); + await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); const {visible: itemsAfter} = await models.ItemShelving.findOne({ where: {shelvingFk, itemFk: items[0]} }, options); diff --git a/modules/item/back/methods/item-shelving/addListByItem.js b/modules/item/back/methods/item-shelving/upsertItem.js similarity index 90% rename from modules/item/back/methods/item-shelving/addListByItem.js rename to modules/item/back/methods/item-shelving/upsertItem.js index da8ed0e1b..49c2f1b0d 100644 --- a/modules/item/back/methods/item-shelving/addListByItem.js +++ b/modules/item/back/methods/item-shelving/upsertItem.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('addListByItem', { + Self.remoteMethodCtx('upsertItem', { description: 'Add a record or update it if it already exists.', accessType: 'WRITE', accepts: [{ @@ -20,12 +20,12 @@ module.exports = Self => { }], http: { - path: `/addListByItem`, + path: `/upsertItem`, verb: 'POST' } }); - Self.addListByItem = async(ctx, shelvingFk, items, warehouseFk, options) => { + Self.upsertItem = async(ctx, shelvingFk, items, warehouseFk, options) => { const myOptions = {userId: ctx.req.accessToken.userId}; let tx; diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index a3c596f94..c031d8271 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -1,5 +1,5 @@ module.exports = Self => { require('../methods/item-shelving/deleteItemShelvings')(Self); - require('../methods/item-shelving/addListByItem')(Self); + require('../methods/item-shelving/upsertItem')(Self); require('../methods/item-shelving/getInventory')(Self); }; From 3d47c9e5e8cfc35a0b80966c4268efc370015ec7 Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 19 Feb 2024 11:27:37 +0100 Subject: [PATCH 44/86] refs #6372 --- db/routines/vn2008/views/pago_sdc.sql | 2 +- db/versions/10836-limeCordyline/15-pago_sdc.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn2008/views/pago_sdc.sql b/db/routines/vn2008/views/pago_sdc.sql index 0fb6a172d..29480e376 100644 --- a/db/routines/vn2008/views/pago_sdc.sql +++ b/db/routines/vn2008/views/pago_sdc.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` AS SELECT `ei`.`id` AS `pago_sdc_id`, `ei`.`amount` AS `importe`, `ei`.`dated` AS `fecha`, - `ei`.`finished` AS `vencimiento`, + `ei`.`dueDated` AS `vencimiento`, `ei`.`entityFk` AS `entity_id`, `ei`.`ref` AS `ref`, `ei`.`rate` AS `rate`, diff --git a/db/versions/10836-limeCordyline/15-pago_sdc.sql b/db/versions/10836-limeCordyline/15-pago_sdc.sql index 3225e2c4d..1b63b9c54 100644 --- a/db/versions/10836-limeCordyline/15-pago_sdc.sql +++ b/db/versions/10836-limeCordyline/15-pago_sdc.sql @@ -6,6 +6,6 @@ ALTER TABLE IF EXISTS `vn`.`exchangeInsurance` CHANGE COLUMN IF EXISTS `pago_sdc_id` `id` int(11) NOT NULL AUTO_INCREMENT, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) NOT NULL, CHANGE COLUMN IF EXISTS `fecha` `dated` date NOT NULL, -CHANGE COLUMN IF EXISTS `vencimiento` `finished` date NOT NULL, +CHANGE COLUMN IF EXISTS `vencimiento` `dueDated` date NOT NULL, CHANGE COLUMN IF EXISTS `entity_id` `entityFk` int(10) unsigned NOT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk`int(10) unsigned NOT NULL DEFAULT 442; From 8328dd6f4c9dd85f4d7493e0ed89f46201c3f5c2 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 19 Feb 2024 12:31:14 +0100 Subject: [PATCH 45/86] hotFix: workerTimeControl use department.hasToRefill --- .../worker/back/methods/worker-time-control/sendMail.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 6f67bbea3..7757ba14d 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -149,7 +149,8 @@ module.exports = Self => { FROM tmp.timeControlError tce JOIN vn.workerTimeControl wtc ON wtc.id = tce.id )sub ON sub.userFk = tb.userFk - WHERE sub.userFK IS NULL + WHERE d.hasToRefill + AND sub.userFK IS NULL AND IFNULL(?, u.id) = u.id AND b.companyCodeFk = 'VNL' AND w.businessFk @@ -163,7 +164,7 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const days = await conn.executeStmt(sql, myOptions); - + console.log(days[index][0]); let previousWorkerFk = days[index][0].workerFk; let previousReceiver = days[index][0].receiver; @@ -356,7 +357,7 @@ module.exports = Self => { previousReceiver = day.receiver; } - if (tx) await tx.commit(); + if (tx) await tx.rollback(); } catch (e) { const stmts = []; let stmt; From 231ebf78d76c8dc74f88677890fe67e60c46684a Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 19 Feb 2024 12:33:33 +0100 Subject: [PATCH 46/86] hotFix: remove console.log --- modules/worker/back/methods/worker-time-control/sendMail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 7757ba14d..3c3b0c06f 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -164,7 +164,7 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const days = await conn.executeStmt(sql, myOptions); - console.log(days[index][0]); + let previousWorkerFk = days[index][0].workerFk; let previousReceiver = days[index][0].receiver; @@ -357,7 +357,7 @@ module.exports = Self => { previousReceiver = day.receiver; } - if (tx) await tx.rollback(); + if (tx) await tx.commit(); } catch (e) { const stmts = []; let stmt; From 2c1172bd88c2810a9f710708402916c492bafac6 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 19 Feb 2024 13:56:16 +0100 Subject: [PATCH 47/86] 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 7b0dd6975d5dba526f1b08591902f8ffb646f8c0 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 19 Feb 2024 14:13:36 +0100 Subject: [PATCH 48/86] fix(usesMana): refs #6879 add mana excluded worker --- .../back/methods/sale/specs/usesMana.spec.js | 31 +++++++++++++++---- modules/ticket/back/methods/sale/usesMana.js | 3 ++ modules/worker/back/model-config.json | 3 ++ .../back/models/worker-mana-excluded.json | 22 +++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 modules/worker/back/models/worker-mana-excluded.json diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js index 777bdc8f0..e82645d0b 100644 --- a/modules/ticket/back/methods/sale/specs/usesMana.spec.js +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -1,11 +1,7 @@ const models = require('vn-loopback/server/server').models; -describe('sale usesMana()', () => { - const ctx = { - req: { - accessToken: {userId: 18} - } - }; +fdescribe('sale usesMana()', () => { + const ctx = {req: { accessToken: {userId: 18}}}; it('should return that the worker uses mana', async() => { const tx = await models.Sale.beginTransaction({}); @@ -45,4 +41,27 @@ describe('sale usesMana()', () => { throw e; } }); + + it('should return that the worker does not use mana because it is excluded', async() => { + const tx = await models.Sale.beginTransaction({}); + const buyerId = 35; + const franceDepartmentId = 133; + const buyerCtx = {req: {accessToken: {userId: buyerId}}}; + + try { + const options = {transaction: tx} + + await models.WorkerManaExcluded.create({workerFk: buyerId}, options); + await models.Business.updateAll({workerFk: buyerId}, {departmentFk: franceDepartmentId}, options); + + const usesMana = await models.Sale.usesMana(buyerCtx, options); + + expect(usesMana).toBe(false); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js index 75d8cdda7..31beb3a4c 100644 --- a/modules/ticket/back/methods/sale/usesMana.js +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -21,6 +21,9 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + const isManaExcluded = await models.WorkerManaExcluded.findById(userId, null, myOptions); + if (isManaExcluded) return false; + const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions); const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 8352eb070..e12ceada5 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -86,6 +86,9 @@ "WorkerMana": { "dataSource": "vn" }, + "WorkerManaExcluded": { + "dataSource": "vn" + }, "WorkerMistake": { "dataSource": "vn" }, diff --git a/modules/worker/back/models/worker-mana-excluded.json b/modules/worker/back/models/worker-mana-excluded.json new file mode 100644 index 000000000..6610b701b --- /dev/null +++ b/modules/worker/back/models/worker-mana-excluded.json @@ -0,0 +1,22 @@ +{ + "name": "WorkerManaExcluded", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerManaExcluded" + } + }, + "properties": { + "workerFk": { + "id": true, + "type": "number" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} From 011880eb728ea6029c59e60e5c71b0bce550775a Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 19 Feb 2024 14:15:44 +0100 Subject: [PATCH 49/86] fix(spec): refs #6879 remove f from describe --- modules/ticket/back/methods/sale/specs/usesMana.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js index e82645d0b..74465ab27 100644 --- a/modules/ticket/back/methods/sale/specs/usesMana.spec.js +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('sale usesMana()', () => { +describe('sale usesMana()', () => { const ctx = {req: { accessToken: {userId: 18}}}; it('should return that the worker uses mana', async() => { From c53ff1243ff9d6898bcc331574e92c622022b70e Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 19 Feb 2024 14:37:36 +0100 Subject: [PATCH 50/86] 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 51/86] 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 From 4952e0be20f64ffbe98a9b6f8f902d181661f29a Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 20 Feb 2024 09:04:50 +0100 Subject: [PATCH 52/86] hotFix(getUrl): fix prop name environment --- back/methods/url/getUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/url/getUrl.js b/back/methods/url/getUrl.js index f30719b9f..ef741e5a0 100644 --- a/back/methods/url/getUrl.js +++ b/back/methods/url/getUrl.js @@ -22,7 +22,7 @@ module.exports = Self => { const {url} = await Self.app.models.Url.findOne({ where: { appName, - enviroment: process.env.NODE_ENV || 'development' + environment: process.env.NODE_ENV || 'development' } }); return url; From 668903fa5f67c48c6944b1536945014803f059a2 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 20 Feb 2024 09:08:32 +0100 Subject: [PATCH 53/86] hotFix(getUrl): fix prop name environment --- back/methods/url/getUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/url/getUrl.js b/back/methods/url/getUrl.js index f30719b9f..ef741e5a0 100644 --- a/back/methods/url/getUrl.js +++ b/back/methods/url/getUrl.js @@ -22,7 +22,7 @@ module.exports = Self => { const {url} = await Self.app.models.Url.findOne({ where: { appName, - enviroment: process.env.NODE_ENV || 'development' + environment: process.env.NODE_ENV || 'development' } }); return url; From f3511d4a43b010e273668a861fa84d994d95b94b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 20 Feb 2024 09:53:28 +0100 Subject: [PATCH 54/86] refs #6414 tback --- .../back/methods/worker/specs/new.spec.js | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index f5deb86ef..1f74e9b95 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -37,25 +37,6 @@ describe('Worker new', () => { roleFk: 1 }; - const clientWorker = { - fi: '09412983A', - name: 'CLIENTWORKER', - firstName: 'CLIENT', - lastNames: 'WORKER', - email: 'clientWorker@mydomain.com', - street: 'S/ DEFAULTWORKERSTREET', - city: 'defaultWorkerCity', - provinceFk: 1, - companyFk: 442, - postcode: '46680', - phone: '123456489', - code: 'CCW', - bossFk: 9, - birth: '2022-12-11T23:00:00.000Z', - payMethodFk: 1, - roleFk: 1 - }; - const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -160,25 +141,22 @@ describe('Worker new', () => { it('should create a new worker', async() => { const newWorker = await models.Worker.new({args: defaultWorker, req}); - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); + await removeWorker(newWorker.id); expect(newWorker.id).toBeDefined(); }); it('should create a new client', async() => { - const newWorker = await models.Worker.new({args: clientWorker, req}); + let newWorker; + let client; + try { + newWorker = await models.Worker.new({args: defaultWorker, req}); + client = await models.Client.findById(newWorker.id); + } finally { + await removeWorker(newWorker.id); + } - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); - - expect(newWorker.id).toBeDefined(); + expect(client).toBeDefined(); }); it('should create a new worker in client', async() => { @@ -202,3 +180,11 @@ describe('Worker new', () => { expect(newWorker.id).toEqual(bruceWayneId); }); }); + +async function removeWorker(id) { + await models.Worker.destroyById(id); + await models.Address.destroyAll({clientFk: id}); + await models.Mandate.destroyAll({clientFk: id}); + await models.Client.destroyById(id); + await models.VnUser.destroyById(id); +} From ab9c952afc301909352a0ae595914bfb1f126444 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 20 Feb 2024 12:13:49 +0100 Subject: [PATCH 55/86] hotFix(sendMail): hasToRefill --- .../worker/back/methods/worker-time-control/sendMail.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 3c3b0c06f..e43f4a8ab 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -137,7 +137,8 @@ module.exports = Self => { tb.type, tb.businessFk, tb.permissionRate, - d.isTeleworking + d.isTeleworking, + d.hasToRefill FROM tmp.timeBusinessCalculate tb JOIN account.user u ON u.id = tb.userFk JOIN department d ON d.id = tb.departmentFk @@ -149,8 +150,7 @@ module.exports = Self => { FROM tmp.timeControlError tce JOIN vn.workerTimeControl wtc ON wtc.id = tce.id )sub ON sub.userFk = tb.userFk - WHERE d.hasToRefill - AND sub.userFK IS NULL + WHERE sub.userFK IS NULL AND IFNULL(?, u.id) = u.id AND b.companyCodeFk = 'VNL' AND w.businessFk @@ -175,7 +175,7 @@ module.exports = Self => { myOptions.transaction = tx; try { workerFk = day.workerFk; - if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null + if (day.hasToRefill && day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null && (day.permissionRate == null ? true : day.permissionRate)) { if (day.timeTable == null) { const timed = new Date(day.dated); From 913e7aa1d8c59fd7144185c3a1e9cfb8c44ad10b Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 20 Feb 2024 14:22:07 +0100 Subject: [PATCH 56/86] fix(run): refs #6372 change version --- .../10836-limeCordyline/03-gastos_resumen.sql | 17 ----------------- .../01-financialProductType.sql | 0 .../02-flight.sql | 0 .../10896-salmonOrchid/03-gastos_resumen.sql | 18 ++++++++++++++++++ .../04-integra2.sql | 0 .../05-integra2_province.sql | 0 .../06-intervalos__delete.sql | 0 .../10-mail_templates__delete.sql | 0 .../12-ticket_location__delete.sql | 0 .../13-turn__delete.sql | 0 .../14-movement_label.sql | 0 .../15-pago_sdc.sql | 0 .../25-warehouse_pickup.sql | 0 .../29-kk.sql | 0 .../30-permissions.sql | 0 15 files changed, 18 insertions(+), 17 deletions(-) delete mode 100644 db/versions/10836-limeCordyline/03-gastos_resumen.sql rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/01-financialProductType.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/02-flight.sql (100%) create mode 100644 db/versions/10896-salmonOrchid/03-gastos_resumen.sql rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/04-integra2.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/05-integra2_province.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/06-intervalos__delete.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/10-mail_templates__delete.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/12-ticket_location__delete.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/13-turn__delete.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/14-movement_label.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/15-pago_sdc.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/25-warehouse_pickup.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/29-kk.sql (100%) rename db/versions/{10836-limeCordyline => 10896-salmonOrchid}/30-permissions.sql (100%) diff --git a/db/versions/10836-limeCordyline/03-gastos_resumen.sql b/db/versions/10836-limeCordyline/03-gastos_resumen.sql deleted file mode 100644 index bfec006fa..000000000 --- a/db/versions/10836-limeCordyline/03-gastos_resumen.sql +++ /dev/null @@ -1,17 +0,0 @@ -ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseSummary`; - -ALTER TABLE IF EXISTS `vn`.`expenseSummary` -CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, -CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, -CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; - -ALTER TABLE IF EXISTS vn.expenseSummary COLLATE=utf8mb3_general_ci; - -ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; - -ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN companyFk int(10) unsigned NOT NULL; - -ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_company_FK FOREIGN KEY (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; - diff --git a/db/versions/10836-limeCordyline/01-financialProductType.sql b/db/versions/10896-salmonOrchid/01-financialProductType.sql similarity index 100% rename from db/versions/10836-limeCordyline/01-financialProductType.sql rename to db/versions/10896-salmonOrchid/01-financialProductType.sql diff --git a/db/versions/10836-limeCordyline/02-flight.sql b/db/versions/10896-salmonOrchid/02-flight.sql similarity index 100% rename from db/versions/10836-limeCordyline/02-flight.sql rename to db/versions/10896-salmonOrchid/02-flight.sql diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql new file mode 100644 index 000000000..ea14364d5 --- /dev/null +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -0,0 +1,18 @@ +ALTER TABLE IF EXISTS vn2008.gastos_resumen DROP FOREIGN KEY IF EXISTS gastos_resumen_expense_FK; +ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseSummary`; + +ALTER TABLE IF EXISTS `vn`.`expenseSummary` +CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, +CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, +CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; + +ALTER TABLE IF EXISTS vn.expenseSummary COLLATE=utf8mb3_general_ci; + +ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; + +ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; + +ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; + diff --git a/db/versions/10836-limeCordyline/04-integra2.sql b/db/versions/10896-salmonOrchid/04-integra2.sql similarity index 100% rename from db/versions/10836-limeCordyline/04-integra2.sql rename to db/versions/10896-salmonOrchid/04-integra2.sql diff --git a/db/versions/10836-limeCordyline/05-integra2_province.sql b/db/versions/10896-salmonOrchid/05-integra2_province.sql similarity index 100% rename from db/versions/10836-limeCordyline/05-integra2_province.sql rename to db/versions/10896-salmonOrchid/05-integra2_province.sql diff --git a/db/versions/10836-limeCordyline/06-intervalos__delete.sql b/db/versions/10896-salmonOrchid/06-intervalos__delete.sql similarity index 100% rename from db/versions/10836-limeCordyline/06-intervalos__delete.sql rename to db/versions/10896-salmonOrchid/06-intervalos__delete.sql diff --git a/db/versions/10836-limeCordyline/10-mail_templates__delete.sql b/db/versions/10896-salmonOrchid/10-mail_templates__delete.sql similarity index 100% rename from db/versions/10836-limeCordyline/10-mail_templates__delete.sql rename to db/versions/10896-salmonOrchid/10-mail_templates__delete.sql diff --git a/db/versions/10836-limeCordyline/12-ticket_location__delete.sql b/db/versions/10896-salmonOrchid/12-ticket_location__delete.sql similarity index 100% rename from db/versions/10836-limeCordyline/12-ticket_location__delete.sql rename to db/versions/10896-salmonOrchid/12-ticket_location__delete.sql diff --git a/db/versions/10836-limeCordyline/13-turn__delete.sql b/db/versions/10896-salmonOrchid/13-turn__delete.sql similarity index 100% rename from db/versions/10836-limeCordyline/13-turn__delete.sql rename to db/versions/10896-salmonOrchid/13-turn__delete.sql diff --git a/db/versions/10836-limeCordyline/14-movement_label.sql b/db/versions/10896-salmonOrchid/14-movement_label.sql similarity index 100% rename from db/versions/10836-limeCordyline/14-movement_label.sql rename to db/versions/10896-salmonOrchid/14-movement_label.sql diff --git a/db/versions/10836-limeCordyline/15-pago_sdc.sql b/db/versions/10896-salmonOrchid/15-pago_sdc.sql similarity index 100% rename from db/versions/10836-limeCordyline/15-pago_sdc.sql rename to db/versions/10896-salmonOrchid/15-pago_sdc.sql diff --git a/db/versions/10836-limeCordyline/25-warehouse_pickup.sql b/db/versions/10896-salmonOrchid/25-warehouse_pickup.sql similarity index 100% rename from db/versions/10836-limeCordyline/25-warehouse_pickup.sql rename to db/versions/10896-salmonOrchid/25-warehouse_pickup.sql diff --git a/db/versions/10836-limeCordyline/29-kk.sql b/db/versions/10896-salmonOrchid/29-kk.sql similarity index 100% rename from db/versions/10836-limeCordyline/29-kk.sql rename to db/versions/10896-salmonOrchid/29-kk.sql diff --git a/db/versions/10836-limeCordyline/30-permissions.sql b/db/versions/10896-salmonOrchid/30-permissions.sql similarity index 100% rename from db/versions/10836-limeCordyline/30-permissions.sql rename to db/versions/10896-salmonOrchid/30-permissions.sql From b9fe9900035ba3629c7f77145faea176398bed40 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 20 Feb 2024 16:10:16 +0100 Subject: [PATCH 57/86] refs #6834 feat:handle Error --- .../sectorCollectionSaleGroup_add.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 9e21defc5..2ef932384 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -8,6 +8,25 @@ BEGIN * @param vSaleGroupFk Identificador de vn.saleGroup * @param vSectorCollectionFk Identificador de vn.sectorCollection */ + DECLARE vHasSaleGroup INT; + DECLARE vHasSectorCollection INT; + + SELECT COUNT(id) INTO vHasSaleGroup + FROM vn.saleGroup sg + WHERE sg.id = vSaleGroupFk; + + IF !vHasSaleGroup THEN + CALL util.Throw ("INVALID_SALEGROUP"); + END IF; + + SELECT COUNT(id) INTO vHasSectorCollection + FROM vn.sectorCollection scsg + WHERE scsg.id = vSectorCollectionFk; + + IF !vHasSectorCollection THEN + CALL util.Throw ("INVALID_SECTORCOLLECTION"); + END IF; + REPLACE sectorCollectionSaleGroup SET sectorCollectionFk = vSectorCollectionFk, saleGroupFk = vSaleGroupFk; From be81835474b39e34dc9aadd10cc1d2d8d7725008 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 20 Feb 2024 16:11:59 +0100 Subject: [PATCH 58/86] refs #6834 feat:handle Error --- db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 2ef932384..eb720f31e 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -16,7 +16,7 @@ BEGIN WHERE sg.id = vSaleGroupFk; IF !vHasSaleGroup THEN - CALL util.Throw ("INVALID_SALEGROUP"); + CALL util.throw ("INVALID_SALEGROUP"); END IF; SELECT COUNT(id) INTO vHasSectorCollection @@ -24,7 +24,7 @@ BEGIN WHERE scsg.id = vSectorCollectionFk; IF !vHasSectorCollection THEN - CALL util.Throw ("INVALID_SECTORCOLLECTION"); + CALL util.throw ("INVALID_SECTORCOLLECTION"); END IF; REPLACE sectorCollectionSaleGroup From 614652c35725fa7a4a5cbf08c0e08b1c56317663 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 21 Feb 2024 07:08:45 +0100 Subject: [PATCH 59/86] refs #6834 feat:handle Error --- .../vn/procedures/sectorCollectionSaleGroup_add.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index eb720f31e..999229d64 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -12,19 +12,19 @@ BEGIN DECLARE vHasSectorCollection INT; SELECT COUNT(id) INTO vHasSaleGroup - FROM vn.saleGroup sg - WHERE sg.id = vSaleGroupFk; + FROM vn.saleGroup + WHERE id = vSaleGroupFk; IF !vHasSaleGroup THEN - CALL util.throw ("INVALID_SALEGROUP"); + CALL util.throw ("invalid saleGroup"); END IF; SELECT COUNT(id) INTO vHasSectorCollection - FROM vn.sectorCollection scsg - WHERE scsg.id = vSectorCollectionFk; + FROM vn.sectorCollection + WHERE id = vSectorCollectionFk; IF !vHasSectorCollection THEN - CALL util.throw ("INVALID_SECTORCOLLECTION"); + CALL util.throw ("invalid sectorCollection"); END IF; REPLACE sectorCollectionSaleGroup From 448763ee725a0810df9ae59c391bdbd3c7c631fa Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 21 Feb 2024 07:15:43 +0100 Subject: [PATCH 60/86] refs #6834 feat:handle Error --- db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 999229d64..5ffb30635 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -12,7 +12,7 @@ BEGIN DECLARE vHasSectorCollection INT; SELECT COUNT(id) INTO vHasSaleGroup - FROM vn.saleGroup + FROM saleGroup WHERE id = vSaleGroupFk; IF !vHasSaleGroup THEN @@ -20,7 +20,7 @@ BEGIN END IF; SELECT COUNT(id) INTO vHasSectorCollection - FROM vn.sectorCollection + FROM sectorCollection WHERE id = vSectorCollectionFk; IF !vHasSectorCollection THEN From 1cf17a3d8d3eddb9783e2897c6535351ec0c754e Mon Sep 17 00:00:00 2001 From: davidd Date: Wed, 21 Feb 2024 07:35:57 +0100 Subject: [PATCH 61/86] refs #6372 --- db/routines/vn2008/views/gastos_resumen.sql | 2 +- .../10896-salmonOrchid/03-gastos_resumen.sql | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/db/routines/vn2008/views/gastos_resumen.sql b/db/routines/vn2008/views/gastos_resumen.sql index 1b6b6d877..02231bcbf 100644 --- a/db/routines/vn2008/views/gastos_resumen.sql +++ b/db/routines/vn2008/views/gastos_resumen.sql @@ -8,4 +8,4 @@ AS SELECT `es`.`amount` AS `importe`, `es`.`companyFk` AS `empresa_id` FROM - `vn`.`expenseSummary` `es`; \ No newline at end of file + `vn`.`expenseManual` `es`; \ No newline at end of file diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index ea14364d5..5fa1f31fb 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -1,18 +1,18 @@ ALTER TABLE IF EXISTS vn2008.gastos_resumen DROP FOREIGN KEY IF EXISTS gastos_resumen_expense_FK; -ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseSummary`; +ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseManual`; -ALTER TABLE IF EXISTS `vn`.`expenseSummary` +ALTER TABLE IF EXISTS `vn`.`expenseManual` CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; -ALTER TABLE IF EXISTS vn.expenseSummary COLLATE=utf8mb3_general_ci; +ALTER TABLE IF EXISTS vn.expenseManual COLLATE=utf8mb3_general_ci; -ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; +ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; -ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE IF EXISTS vn.expenseSummary MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; +ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; -ALTER TABLE IF EXISTS vn.expenseSummary ADD CONSTRAINT expenseSummary_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; From 3463b8fcb15976b2488fab3366e84f23fd8e1b74 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 21 Feb 2024 12:09:52 +0100 Subject: [PATCH 62/86] done --- db/routines/vn/procedures/clean.sql | 1 + db/versions/10898-6906-workerActivity/00-table.sql | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 db/versions/10898-6906-workerActivity/00-table.sql diff --git a/db/routines/vn/procedures/clean.sql b/db/routines/vn/procedures/clean.sql index 7b561cfe0..65045bcbd 100644 --- a/db/routines/vn/procedures/clean.sql +++ b/db/routines/vn/procedures/clean.sql @@ -22,6 +22,7 @@ BEGIN SET v2Years = util.VN_CURDATE() - INTERVAL 2 YEAR; SET v5Years = util.VN_CURDATE() - INTERVAL 5 YEAR; + DELETE FROM workerActivity WHERE created < v2Years; DELETE FROM ticketParking WHERE created < vDateShort; DELETE FROM routesMonitor WHERE dated < vDateShort; DELETE FROM workerTimeControlLog WHERE created < vDateShort; diff --git a/db/versions/10898-6906-workerActivity/00-table.sql b/db/versions/10898-6906-workerActivity/00-table.sql new file mode 100644 index 000000000..ec517b929 --- /dev/null +++ b/db/versions/10898-6906-workerActivity/00-table.sql @@ -0,0 +1,13 @@ +-- Place your SQL code here +CREATE TABLE vn.workerActivity ( +id INT PRIMARY KEY AUTO_INCREMENT, +created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +model ENUM('COM', 'ENT', 'TPV', 'ENC', 'LAB', 'ETI') NOT NULL, +workerFk INT(10) UNSIGNED NOT NULL, +event ENUM('open', 'close', 'insert', 'delete', 'update', 'refresh') NOT NULL, +description VARCHAR(255) DEFAULT NULL, +CONSTRAINT fk_workerActivity_worker FOREIGN KEY (workerFk) + REFERENCES vn.worker (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); \ No newline at end of file From f30a5a759767666f9778a7a887c13e179f4f9946 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 21 Feb 2024 13:13:28 +0100 Subject: [PATCH 63/86] refs #6626 invoiceInTax different transactions --- .../vn/procedures/invoiceInTax_afterUpsert.sql | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index 77e989630..3a81cd531 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -8,6 +8,7 @@ BEGIN */ DECLARE vTaxRowLimit INT; DECLARE vLines INT; + DECLARE vHasDistinctTransactions INT; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; @@ -18,6 +19,18 @@ BEGIN IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); - END IF; + END IF; + + SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + JOIN invoiceInSerial iis ON iis.code = ii.serial + WHERE ii.id = vInvoiceInFk + AND iis.taxAreaFk = 'CEE' + AND transactionTypeSageFk; + + IF vHasDistinctTransactions > 1 THEN + CALL util.throw ('This invoice does not allow diferent types of transactions'); + END IF; END$$ DELIMITER ; From 84270d29b8b875411e64ce8e9996406ecc83b900 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 21 Feb 2024 13:15:46 +0100 Subject: [PATCH 64/86] refs #6626 modify invoiceInTax --- db/routines/vn/procedures/invoiceInTax_afterUpsert.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index 3a81cd531..60ec34696 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -30,7 +30,7 @@ BEGIN AND transactionTypeSageFk; IF vHasDistinctTransactions > 1 THEN - CALL util.throw ('This invoice does not allow diferent types of transactions'); + CALL util.throw ('This invoice does not allow different types of transactions'); END IF; END$$ DELIMITER ; From fba353f8e420cd43d4b68796e1ab7e91f6011880 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 21 Feb 2024 13:43:33 +0100 Subject: [PATCH 65/86] feat: refs #6371 restore Proveedores_cargueras --- db/versions/10835-brownCarnation/00-firstScript.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/versions/10835-brownCarnation/00-firstScript.sql b/db/versions/10835-brownCarnation/00-firstScript.sql index 977e20905..e66b84ee5 100644 --- a/db/versions/10835-brownCarnation/00-firstScript.sql +++ b/db/versions/10835-brownCarnation/00-firstScript.sql @@ -81,10 +81,6 @@ ALTER TABLE IF EXISTS vn2008.MovimienRENAMEs_avisar__ COMMENT='refs #6371 deprec ALTER TABLE IF EXISTS vn2008.MovimienRENAMEs_revisar RENAME vn2008.MovimienRENAMEs_revisar__; ALTER TABLE IF EXISTS vn2008.MovimienRENAMEs_revisar__ COMMENT='refs #6371 deprecated 2024-01-11'; --- Para la tabla Proveedores_cargueras -ALTER TABLE IF EXISTS vn2008.Proveedores_cargueras RENAME vn2008.Proveedores_cargueras__; -ALTER TABLE IF EXISTS vn2008.Proveedores_cargueras__ COMMENT='refs #6371 deprecated 2024-01-11'; - -- Para la tabla Proveedores_comunicados ALTER TABLE IF EXISTS vn2008.Proveedores_comunicados RENAME vn2008.Proveedores_comunicados__; ALTER TABLE IF EXISTS vn2008.Proveedores_comunicados__ COMMENT='refs #6371 deprecated 2024-01-11'; From 5bef3989cd9a7e9accf6883ca1c5e18d13518e3c Mon Sep 17 00:00:00 2001 From: davidd Date: Wed, 21 Feb 2024 14:07:52 +0100 Subject: [PATCH 66/86] refs #6372 --- ...Label_afterUpdate.sql => saleLabel_afterUpdate.sql} | 4 ++-- db/routines/vn2008/views/movement_label.sql | 10 ---------- db/versions/10896-salmonOrchid/14-movement_label.sql | 6 ++++-- db/versions/10896-salmonOrchid/25-warehouse_pickup.sql | 4 +++- 4 files changed, 9 insertions(+), 15 deletions(-) rename db/routines/vn/triggers/{movementLabel_afterUpdate.sql => saleLabel_afterUpdate.sql} (56%) delete mode 100644 db/routines/vn2008/views/movement_label.sql diff --git a/db/routines/vn/triggers/movementLabel_afterUpdate.sql b/db/routines/vn/triggers/saleLabel_afterUpdate.sql similarity index 56% rename from db/routines/vn/triggers/movementLabel_afterUpdate.sql rename to db/routines/vn/triggers/saleLabel_afterUpdate.sql index 7dd8a9eb9..ff3787358 100644 --- a/db/routines/vn/triggers/movementLabel_afterUpdate.sql +++ b/db/routines/vn/triggers/saleLabel_afterUpdate.sql @@ -1,6 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`movementLabel_afterUpdate` - AFTER UPDATE ON `vn`.`movementLabel` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleLabel_afterUpdate` + AFTER UPDATE ON `vn`.`saleLabel` FOR EACH ROW IF NEW.stem >= (SELECT s.quantity FROM sale s WHERE s.id = NEW.saleFk) THEN UPDATE sale s SET s.isPicked = TRUE WHERE s.id = NEW.saleFk; diff --git a/db/routines/vn2008/views/movement_label.sql b/db/routines/vn2008/views/movement_label.sql deleted file mode 100644 index 738750507..000000000 --- a/db/routines/vn2008/views/movement_label.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`movement_label` -AS SELECT - `m`.`saleFk` AS `Id_movimiento`, - `m`.`label`, - `m`.`stem`, - `m`.`created` -FROM - `vn`.`movementLabel` `m`; \ No newline at end of file diff --git a/db/versions/10896-salmonOrchid/14-movement_label.sql b/db/versions/10896-salmonOrchid/14-movement_label.sql index 5ce130cf8..a3ccf320d 100644 --- a/db/versions/10896-salmonOrchid/14-movement_label.sql +++ b/db/versions/10896-salmonOrchid/14-movement_label.sql @@ -1,6 +1,8 @@ DROP TRIGGER IF EXISTS `vn2008`.`movement_label_afterUpdate`; -ALTER TABLE IF EXISTS `vn2008`.`movement_label` RENAME `vn`.`movementLabel`; +DROP VIEW IF EXISTS `vn`.`saleLabel`; -ALTER TABLE IF EXISTS `vn`.`movementLabel` +ALTER TABLE IF EXISTS `vn2008`.`movement_label` RENAME `vn`.`saleLabel`; + +ALTER TABLE IF EXISTS `vn`.`saleLabel` CHANGE COLUMN IF EXISTS `Id_movimiento` `saleFk` int(11) NOT NULL; diff --git a/db/versions/10896-salmonOrchid/25-warehouse_pickup.sql b/db/versions/10896-salmonOrchid/25-warehouse_pickup.sql index 1a2479a43..d6f2ae18d 100644 --- a/db/versions/10896-salmonOrchid/25-warehouse_pickup.sql +++ b/db/versions/10896-salmonOrchid/25-warehouse_pickup.sql @@ -2,4 +2,6 @@ ALTER TABLE IF EXISTS `vn2008`.`warehouse_pickup` RENAME `vn`.`warehousePickup`; ALTER TABLE IF EXISTS `vn`.`warehousePickup` CHANGE COLUMN IF EXISTS `warehouse_id` `warehouseFk` smallint(5) unsigned NOT NULL, -CHANGE COLUMN IF EXISTS `agency_id` `agencyModeFk` int(11) DEFAULT NULL; \ No newline at end of file +CHANGE COLUMN IF EXISTS `agency_id` `agencyModeFk` int(11) DEFAULT NULL; + +ALTER TABLE `vn`.`warehousePickup` COMMENT='Agencia de recogida para cada almacén'; From 01f1bd0088ad169e02bb055509c3930ac75b06e0 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 21 Feb 2024 14:44:34 +0100 Subject: [PATCH 67/86] Revert "Merge branch 'dev' into test" This reverts commit c4a64b93cc4f021ebc6268c48033aec3c00e139b, reversing changes made to 2ab1cebb318eda5915c395526b55b496f8d7b50f. --- back/methods/collection/getSectors.js | 20 +++++ .../collection/spec/getSectors.spec.js | 11 +++ back/models/collection.js | 1 + db/dump/.dump/data.sql | 2 + db/dump/fixtures.before.sql | 3 +- .../bs/procedures/ventas_contables_add.sql | 34 ++++---- .../procedures/invoiceInTax_afterUpsert.sql | 15 +--- .../vn/procedures/itemProposal_Add.sql | 70 +++++++++++++++++ .../vn/procedures/itemShelving_add.sql | 4 - .../vn/procedures/sale_getBoxPickingList.sql | 51 ++++++++++-- .../sectorCollectionSaleGroup_add.sql | 19 ----- db/routines/vn/procedures/sector_get.sql | 13 ++++ db/routines/vn/procedures/ticket_getTax.sql | 58 +++++++------- .../vn/triggers/ticket_beforeUpdate.sql | 10 +++ .../00-alterAgencyTermConfig.sql | 3 - .../00-alterGastosResumen.sql | 11 --- .../00-alterInvoiceOutTaxConfig.sql | 5 -- .../00-alterItemGroupToOffer.sql | 5 -- .../01-ventasContablesPk.sql | 14 ---- .../02-updateExpenseRegularize.sql | 8 -- .../10862-navyHydrangea/03-updateExpense.sql | 44 ----------- .../04-updateExpenseConflict.sql | 6 -- .../00-revokeUpdateClient.sql | 37 --------- .../back/methods/invoiceOut/negativeBases.js | 52 +++++++------ .../item-shelving/specs/addListByItem.spec.js | 55 ------------- .../back/methods/item-shelving/upsertItem.js | 64 --------------- modules/item/back/models/item-shelving.js | 1 - .../ticket/specs/transferClient.spec.js | 71 ++++++++--------- .../back/methods/ticket/transferClient.js | 77 ++++++------------- .../back/methods/worker/specs/new.spec.js | 28 ++----- myt.config.yml | 1 + package.json | 2 +- 32 files changed, 309 insertions(+), 486 deletions(-) create mode 100644 back/methods/collection/getSectors.js create mode 100644 back/methods/collection/spec/getSectors.spec.js create mode 100644 db/routines/vn/procedures/itemProposal_Add.sql create mode 100644 db/routines/vn/procedures/sector_get.sql delete mode 100644 db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql delete mode 100644 db/versions/10862-navyHydrangea/00-alterGastosResumen.sql delete mode 100644 db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql delete mode 100644 db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql delete mode 100644 db/versions/10862-navyHydrangea/01-ventasContablesPk.sql delete mode 100644 db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql delete mode 100644 db/versions/10862-navyHydrangea/03-updateExpense.sql delete mode 100644 db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql delete mode 100644 db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql delete mode 100644 modules/item/back/methods/item-shelving/specs/addListByItem.spec.js delete mode 100644 modules/item/back/methods/item-shelving/upsertItem.js diff --git a/back/methods/collection/getSectors.js b/back/methods/collection/getSectors.js new file mode 100644 index 000000000..12ad0dc06 --- /dev/null +++ b/back/methods/collection/getSectors.js @@ -0,0 +1,20 @@ +module.exports = Self => { + Self.remoteMethod('getSectors', { + description: 'Get all sectors', + accessType: 'READ', + returns: { + type: 'Object', + root: true + }, + http: { + path: `/getSectors`, + verb: 'GET' + } + }); + + Self.getSectors = async() => { + const query = `CALL vn.sector_get()`; + const [result] = await Self.rawSql(query); + return result; + }; +}; diff --git a/back/methods/collection/spec/getSectors.spec.js b/back/methods/collection/spec/getSectors.spec.js new file mode 100644 index 000000000..d8fa60663 --- /dev/null +++ b/back/methods/collection/spec/getSectors.spec.js @@ -0,0 +1,11 @@ +const {models} = require('vn-loopback/server/server'); + +describe('getSectors()', () => { + it('return list of sectors', async() => { + let response = await models.Collection.getSectors(); + + expect(response.length).toBeGreaterThan(0); + expect(response[0].id).toEqual(1); + expect(response[0].description).toEqual('First sector'); + }); +}); diff --git a/back/models/collection.js b/back/models/collection.js index 52ef26e88..1c10d49fa 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -1,5 +1,6 @@ module.exports = Self => { require('../methods/collection/getCollection')(Self); + require('../methods/collection/getSectors')(Self); require('../methods/collection/setSaleQuantity')(Self); require('../methods/collection/previousLabel')(Self); require('../methods/collection/getTickets')(Self); diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 6fe6c1414..8367471bc 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -1750,6 +1750,8 @@ 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 43293c9ea..094b956af 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -653,7 +653,6 @@ 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 @@ -729,7 +728,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/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index 12b2738f3..9988c8b29 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 vn.invoiceOut io ON io.id = t.Factura WHERE year(io.issued) = vYear - AND month(io.issued) = vMonth; + AND month(io.issued) = 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 - , a.expenseFk + , 7000000000 + 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 + ) * 1000000 + + tp.reino_id * 10000 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/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index 60ec34696..77e989630 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -8,7 +8,6 @@ BEGIN */ DECLARE vTaxRowLimit INT; DECLARE vLines INT; - DECLARE vHasDistinctTransactions INT; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; @@ -19,18 +18,6 @@ BEGIN IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); - END IF; - - SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions - FROM invoiceIn ii - JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN invoiceInSerial iis ON iis.code = ii.serial - WHERE ii.id = vInvoiceInFk - AND iis.taxAreaFk = 'CEE' - AND transactionTypeSageFk; - - IF vHasDistinctTransactions > 1 THEN - CALL util.throw ('This invoice does not allow different types of transactions'); - END IF; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemProposal_Add.sql b/db/routines/vn/procedures/itemProposal_Add.sql new file mode 100644 index 000000000..ac4dfa5d5 --- /dev/null +++ b/db/routines/vn/procedures/itemProposal_Add.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal_Add`(vSaleFk INT, vMateFk INT, vQuantity INT) +BEGIN +/** + * Añade un nuevo articulo para sustituir a otro, y actualiza la memoria de sustituciones. + * + * @param vSaleFk id de la tabla sale + * @param vMateFk articulo sustituto + * @ param vQuantity cantidad que se va a sustituir + */ + DECLARE vTicketFk INT; + DECLARE vItemFk INT; + DECLARE vWarehouseFk SMALLINT; + DECLARE vDate DATE; + DECLARE vGrouping INT; + DECLARE vBox INT; + DECLARE vPacking INT; + DECLARE vRoundQuantity INT DEFAULT 1; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk + INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE s.id = vSaleFk; + + CALL buyUltimate(vWarehouseFk, vDate); + + SELECT `grouping`, groupingMode, packing INTO vGrouping, vBox, vPacking + FROM buy b + JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk + WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; + + IF vBox = 2 AND vPacking > 0 THEN + SET vRoundQuantity = vPacking; + END IF; + IF vBox = 1 AND vGrouping > 0 THEN + SET vRoundQuantity = vGrouping; + END IF; + + START TRANSACTION; + + UPDATE sale + SET quantity = quantity - vQuantity + WHERE id = vSaleFk; + + INSERT INTO sale(ticketFk, itemFk, quantity, concept) + SELECT vTicketFk, + vMateFk, + CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, + CONCAT('+ ',i.longName) + FROM item i + WHERE id = vMateFk; + + SELECT LAST_INSERT_ID() INTO vSaleFk; + + CALL sale_calculateComponent(vSaleFk, NULL); + + INSERT INTO itemProposal(itemFk, mateFk, counter) + VALUES(vItemFk, vMateFk, 1) + ON DUPLICATE KEY UPDATE counter = counter + 1; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 2a4676b50..02762fa0b 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -19,10 +19,6 @@ BEGIN DECLARE vItemFk INT; SELECT barcodeToItem(vBarcode) INTO vItemFk; - - SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)); - - SET vQuantity = vQuantity * vPacking; IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 0af23e945..0f2b2bc71 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -17,6 +17,7 @@ BEGIN CALL productionControl(vWarehouseFk, 0); + -- Products with vn.item.isBoxPickingMode = TRUE, pay atention to vn.itemShelving.packing CREATE OR REPLACE TEMPORARY TABLE tmp.sale (saleFk INT PRIMARY KEY) SELECT @@ -28,7 +29,7 @@ BEGIN MAKETIME(pb.HH,pb.mm,0) etd, pb.routeFk, FLOOR(s.quantity / ish.packing) stickers, - IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, + ish.packing, b.packagingFk FROM sale s JOIN item i ON i.id = s.itemFk @@ -51,8 +52,8 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN buy b ON b.id = lb.buy_id - WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut) - <= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0)) + WHERE s.quantity BETWEEN ish.packing AND (ish.visible - IFNULL(tISS.reserve,0)) + AND i.isBoxPickingMode AND NOT pb.problem AND sgd.saleFk IS NULL AND p.sectorFk = vSectorFk @@ -63,13 +64,47 @@ BEGIN GROUP BY s.id ORDER BY etd; - SELECT * - FROM tmp.sale - WHERE stickers; + -- Remaining products, vn.item.packingOut + INSERT IGNORE INTO tmp.sale + SELECT + s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + s.quantity / i.packingOut stickers, + i.packingOut, + pc.defaultBigPackageFk + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemShelving ish ON ish.itemFk = s.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk + JOIN agencyMode am ON am.id = pb.agencyModeFk + JOIN packagingConfig pc + LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = p.sectorFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk + WHERE s.quantity >= i.packingOut + AND NOT pb.problem + AND s.quantity > 0 + AND sgd.saleFk IS NULL + AND p.sectorFk = vSectorFk + AND ts.isPreviousPreparable + AND iss.visible >= s.quantity + AND ((rm.bufferFk AND rm.isPickingAllowed) + OR am.code = 'REC_ALG') + AND pb.shipped = vDated + GROUP BY s.id + ORDER BY etd; + + SELECT * FROM tmp.sale; DROP TEMPORARY TABLE tmp.productionBuffer; DROP TEMPORARY TABLE tmp.sale; END$$ DELIMITER ; - -CALL `vn`.`sale_getBoxPickingList`(1, curdate()); \ No newline at end of file diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 5ffb30635..9e21defc5 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -8,25 +8,6 @@ BEGIN * @param vSaleGroupFk Identificador de vn.saleGroup * @param vSectorCollectionFk Identificador de vn.sectorCollection */ - DECLARE vHasSaleGroup INT; - DECLARE vHasSectorCollection INT; - - SELECT COUNT(id) INTO vHasSaleGroup - FROM saleGroup - WHERE id = vSaleGroupFk; - - IF !vHasSaleGroup THEN - CALL util.throw ("invalid saleGroup"); - END IF; - - SELECT COUNT(id) INTO vHasSectorCollection - FROM sectorCollection - WHERE id = vSectorCollectionFk; - - IF !vHasSectorCollection THEN - CALL util.throw ("invalid sectorCollection"); - END IF; - REPLACE sectorCollectionSaleGroup SET sectorCollectionFk = vSectorCollectionFk, saleGroupFk = vSaleGroupFk; diff --git a/db/routines/vn/procedures/sector_get.sql b/db/routines/vn/procedures/sector_get.sql new file mode 100644 index 000000000..fe978203a --- /dev/null +++ b/db/routines/vn/procedures/sector_get.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sector_get`() +BEGIN + +/** + * Obtiene los sectores +*/ + + SELECT s.id,s.description,s.warehouseFk + FROM vn.sector s; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql index b9f5c14e3..7269a1caf 100644 --- a/db/routines/vn/procedures/ticket_getTax.sql +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -9,8 +9,6 @@ BEGIN * @return tmp.ticketAmount (ticketFk, taxableBase, tax, code) * @return tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) Impuesto desglosado para cada ticket. */ - -- 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)) @@ -19,24 +17,24 @@ BEGIN 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 - - CREATE OR REPLACE 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 + */ + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; + CREATE 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 @@ -45,21 +43,22 @@ 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 - ) t3 + HAVING taxableBase <> 0) t3 ORDER BY priority; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax + DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax; + CREATE TEMPORARY TABLE tmp.ticketServiceTax (PRIMARY KEY (ticketFk, code, rate)) ENGINE = MEMORY SELECT tt.ticketFk, @@ -71,22 +70,24 @@ 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; + HAVING taxableBase <> 0; 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 ; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketAmount + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; + CREATE TEMPORARY TABLE tmp.ticketAmount (INDEX (ticketFk)) ENGINE = MEMORY SELECT ticketFk, @@ -96,8 +97,7 @@ BEGIN FROM tmp.ticketTax GROUP BY ticketFk, code; - DROP TEMPORARY TABLE - tmp.addressCompany, - tmp.addressTaxArea; + DROP TEMPORARY TABLE tmp.addressCompany; + DROP TEMPORARY TABLE tmp.addressTaxArea; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_beforeUpdate.sql b/db/routines/vn/triggers/ticket_beforeUpdate.sql index 72831bc3d..0836b2486 100644 --- a/db/routines/vn/triggers/ticket_beforeUpdate.sql +++ b/db/routines/vn/triggers/ticket_beforeUpdate.sql @@ -4,6 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_beforeUpdate` FOR EACH ROW BEGIN DECLARE vNewTime TIME; + DECLARE vHasTicketRefund BOOL; SET NEW.editorFk = account.myUser_getId(); @@ -63,5 +64,14 @@ BEGIN CALL vn.routeUpdateM3(NEW.routeFk); END IF; + + SELECT COUNT(*) INTO vHasTicketRefund + FROM ticketRefund + WHERE originalTicketFk = NEW.id + OR refundTicketFk = NEW.id; + + IF vHasTicketRefund AND NEW.clientFk <> OLD.clientFk THEN + CALL util.throw('The ticket has a refund associated'); + END IF; END$$ DELIMITER ; 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; diff --git a/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql b/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql deleted file mode 100644 index 307b8f205..000000000 --- a/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql +++ /dev/null @@ -1,11 +0,0 @@ -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; - -ALTER TABLE vn2008.gastos_resumen - 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 deleted file mode 100644 index fc5025c18..000000000 --- a/db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 68611c13c..000000000 --- a/db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 3f8bf2c79..000000000 --- a/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql +++ /dev/null @@ -1,14 +0,0 @@ -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/02-updateExpenseRegularize.sql b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql deleted file mode 100644 index 90d865c1d..000000000 --- a/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELETE FROM vn.expense - WHERE id ='' AND id IS NULL AND isWithheld = FALSE; -UPDATE vn.expense - SET id='7002090000' - WHERE id='7002009000'; -UPDATE vn.expense - SET id='7001090000' - WHERE id='7001009000'; diff --git a/db/versions/10862-navyHydrangea/03-updateExpense.sql b/db/versions/10862-navyHydrangea/03-updateExpense.sql deleted file mode 100644 index a44c4c504..000000000 --- a/db/versions/10862-navyHydrangea/03-updateExpense.sql +++ /dev/null @@ -1,44 +0,0 @@ -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 7040008000 - WHEN 7001080000 THEN 7000108000 - 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 -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, - 7002090000, 7002100000, 7001090000, 7001100000, - 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql b/db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql deleted file mode 100644 index 0e008081b..000000000 --- a/db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE vn.expense -SET id = CASE id - WHEN 7000100000 THEN 7001010000 - ELSE id -END -WHERE id IN (7000100000); diff --git a/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql b/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql deleted file mode 100644 index b22e09615..000000000 --- a/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql +++ /dev/null @@ -1,37 +0,0 @@ -REVOKE UPDATE ON vn.ticket FROM employee; - -GRANT UPDATE (id, - warehouseFk, - shipped, - nickname, - refFk, - addressFk, - workerFk, - observations, - isSigned, - isLabeled, - isPrinted, - packages, - location, - hour, - created, - isBlocked, - solution, - routeFk, - priority, - hasPriority, - companyFk, - agencyModeFk, - landed, - isBoxed, - isDeleted, - zoneFk, - zonePrice, - zoneBonus, - totalWithVat, - totalWithoutVat, - weight, - clonedFrom, - cmrFk, - editorFk) - ON vn.ticket TO employee; diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 66440616c..dc9496b4a 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -46,19 +46,23 @@ module.exports = Self => { const stmts = []; let stmt; + stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket`); + stmts.push(new ParameterizedSQL( - `CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + `CREATE TEMPORARY TABLE tmp.ticket (KEY (ticketFk)) ENGINE = MEMORY SELECT id ticketFk FROM ticket t - WHERE shipped BETWEEN ? AND util.dayEnd(?) + WHERE shipped BETWEEN ? AND ? 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 OR REPLACE TEMPORARY TABLE tmp.filter + `CREATE TEMPORARY TABLE tmp.filter ENGINE = MEMORY - SELECT co.code company, + SELECT + co.code company, cou.country, c.id clientId, c.socialName clientSocialName, @@ -71,26 +75,28 @@ 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 - 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') - 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 + 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 ? + 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 * FROM tmp.filter`); + stmt = new ParameterizedSQL(` + SELECT f.* + FROM tmp.filter f`); if (args.filter) { stmt.merge(conn.makeWhere(args.filter.where)); diff --git a/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js deleted file mode 100644 index e31ff2e61..000000000 --- a/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js +++ /dev/null @@ -1,55 +0,0 @@ -const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); - -describe('ItemShelving upsertItem()', () => { - const warehouseFk = 1; - let ctx; - let options; - let tx; - - beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - - options = {transaction: tx}; - tx = await models.ItemShelving.beginTransaction({}); - options.transaction = tx; - }); - - afterEach(async() => { - await tx.rollback(); - }); - - it('should add two new records', async() => { - const shelvingFk = 'ZPP'; - const items = [1, 1, 1, 2]; - - await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); - const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); - - expect(itemShelvings.length).toEqual(2); - }); - - it('should update the visible items', async() => { - const shelvingFk = 'GVC'; - const items = [2, 2]; - const {visible: itemsBefore} = await models.ItemShelving.findOne({ - where: {shelvingFk, itemFk: items[0]} - }, options); - await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); - const {visible: itemsAfter} = await models.ItemShelving.findOne({ - where: {shelvingFk, itemFk: items[0]} - }, options); - - expect(itemsAfter).toEqual(itemsBefore + 2); - }); -}); diff --git a/modules/item/back/methods/item-shelving/upsertItem.js b/modules/item/back/methods/item-shelving/upsertItem.js deleted file mode 100644 index 49c2f1b0d..000000000 --- a/modules/item/back/methods/item-shelving/upsertItem.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('upsertItem', { - description: 'Add a record or update it if it already exists.', - accessType: 'WRITE', - accepts: [{ - arg: 'shelvingFk', - type: 'string', - required: true, - }, - { - arg: 'items', - type: ['number'], - required: true, - description: 'array of item foreign keys' - }, - { - arg: 'warehouseFk', - type: 'number', - required: true - }], - - http: { - path: `/upsertItem`, - verb: 'POST' - } - }); - - Self.upsertItem = async(ctx, shelvingFk, items, warehouseFk, options) => { - const myOptions = {userId: ctx.req.accessToken.userId}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - const discardItems = new Set(); - const itemCounts = items.reduce((acc, item) => { - acc[item] = (acc[item] || 0) + 1; - return acc; - }, {}); - - try { - for (let item of items) { - if (!discardItems.has(item)) { - let quantity = itemCounts[item]; - discardItems.add(item); - - await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, NULL, ?)', - [shelvingFk, item, quantity, warehouseFk], myOptions - ); - } - } - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index c031d8271..98ff18931 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -1,5 +1,4 @@ module.exports = Self => { require('../methods/item-shelving/deleteItemShelvings')(Self); - require('../methods/item-shelving/upsertItem')(Self); require('../methods/item-shelving/getInventory')(Self); }; diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 5f1c09776..5a9edd17e 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -1,60 +1,49 @@ const models = require('vn-loopback/server/server').models; describe('Ticket transferClient()', () => { - const originalTicketId = 8; - const refundTicketId = 24; - const clientId = 1; - let ctx; - let options; - let tx; - beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - options = {transaction: tx}; - tx = await models.Ticket.beginTransaction({}); - options.transaction = tx; - }); - - afterEach(async() => { - await tx.rollback(); - }); + const userId = 9; + const activeCtx = { + accessToken: {userId: userId}, + }; + const ctx = {req: activeCtx}; it('should throw an error as the ticket is not editable', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + try { + const options = {transaction: tx}; const ticketId = 4; const clientId = 1; await models.Ticket.transferClient(ctx, ticketId, clientId, options); + + await tx.rollback(); } catch (e) { - expect(e.message).toEqual(`This ticket is locked`); + await tx.rollback(); + error = e; } + + expect(error.message).toEqual(`This ticket is locked`); }); - it('should be assigned a different clientFk in the original ticket', async() => { - await models.Ticket.transferClient(ctx, 2, clientId, options); - const afterTransfer = await models.Ticket.findById(2, null, options); + it('should be assigned a different clientFk', async() => { + const tx = await models.Ticket.beginTransaction({}); + let updatedTicket; + const ticketId = 10; + const clientId = 1; - expect(afterTransfer.clientFk).toEqual(clientId); - }); + try { + const options = {transaction: tx}; - it('should be assigned a different clientFk in the original and refund ticket and claim', async() => { - await models.Ticket.transferClient(ctx, originalTicketId, clientId, options); + await models.Ticket.transferClient(ctx, ticketId, clientId, options); + updatedTicket = await models.Ticket.findById(ticketId, {fields: ['clientFk']}, options); - const [originalTicket, refundTicket] = await models.Ticket.find({ - where: {id: {inq: [originalTicketId, refundTicketId]}} - }, options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } - const claim = await models.Claim.findOne({ - where: {ticketFk: originalTicketId} - }, options); - - expect(originalTicket.clientFk).toEqual(clientId); - expect(refundTicket.clientFk).toEqual(clientId); - expect(claim.clientFk).toEqual(clientId); + expect(updatedTicket.clientFk).toEqual(clientId); }); }); diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index d38c0e8a7..60e70d710 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -2,17 +2,20 @@ module.exports = Self => { Self.remoteMethodCtx('transferClient', { description: 'Transfering ticket to another client', accessType: 'WRITE', - accepts: [{ - arg: 'id', - type: 'number', - required: true, - description: 'the ticket id', - http: {source: 'path'} - }, { - arg: 'clientFk', - type: 'number', - required: true, - }], + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'the ticket id', + http: {source: 'path'} + }, + { + arg: 'clientFk', + type: 'number', + required: true, + }, + ], http: { path: `/:id/transferClient`, verb: 'PATCH' @@ -22,51 +25,21 @@ module.exports = Self => { Self.transferClient = async(ctx, id, clientFk, options) => { const models = Self.app.models; const myOptions = {}; - let tx; - if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } + await Self.isEditableOrThrow(ctx, id, myOptions); - try { - await Self.isEditableOrThrow(ctx, id, myOptions); + const ticket = await models.Ticket.findById( + id, + {fields: ['id', 'shipped', 'clientFk', 'addressFk']}, + myOptions + ); + const client = await models.Client.findById(clientFk, {fields: ['id', 'defaultAddressFk']}, myOptions); - const ticketRefund = await models.TicketRefund.findOne({ - where: {or: [{originalTicketFk: id}, {refundTicketFk: id}]}, - include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}] - }, myOptions); - - const {defaultAddressFk: addressFk} = await models.Client.findById(clientFk, - {fields: ['id', 'defaultAddressFk']}, myOptions); - - const attributes = {clientFk, addressFk}; - - const tickets = []; - const ticketIds = []; - - if (ticketRefund) { - const {refundTicket, originalTicket} = ticketRefund; - tickets.push(refundTicket(), originalTicket()); - - for (const ticket of tickets) { - await ticket.updateAttributes(attributes, myOptions); - ticketIds.push(ticket.id); - } - } else { - await Self.updateAll({id}, attributes, myOptions); - ticketIds.push(id); - } - - await models.Claim.updateAll({ticketFk: {inq: ticketIds}}, {clientFk}, myOptions); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } + await ticket.updateAttributes({ + clientFk, + addressFk: client.defaultAddressFk, + }); }; }; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index 1f74e9b95..d0830b00f 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -36,7 +36,6 @@ describe('Worker new', () => { payMethodFk: 1, roleFk: 1 }; - const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -141,24 +140,15 @@ describe('Worker new', () => { it('should create a new worker', async() => { const newWorker = await models.Worker.new({args: defaultWorker, req}); - await removeWorker(newWorker.id); + await models.Worker.destroyById(newWorker.id); + await models.Address.destroyAll({clientFk: newWorker.id}); + await models.Mandate.destroyAll({clientFk: newWorker.id}); + await models.Client.destroyById(newWorker.id); + await models.VnUser.destroyById(newWorker.id); expect(newWorker.id).toBeDefined(); }); - it('should create a new client', async() => { - let newWorker; - let client; - try { - newWorker = await models.Worker.new({args: defaultWorker, req}); - client = await models.Client.findById(newWorker.id); - } finally { - await removeWorker(newWorker.id); - } - - expect(client).toBeDefined(); - }); - it('should create a new worker in client', async() => { const bruceWayneId = 1101; const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']}); @@ -180,11 +170,3 @@ describe('Worker new', () => { expect(newWorker.id).toEqual(bruceWayneId); }); }); - -async function removeWorker(id) { - await models.Worker.destroyById(id); - await models.Address.destroyAll({clientFk: id}); - await models.Mandate.destroyAll({clientFk: id}); - await models.Client.destroyById(id); - await models.VnUser.destroyById(id); -} diff --git a/myt.config.yml b/myt.config.yml index 0b1d62d25..2e37a0d97 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -44,6 +44,7 @@ fixtures: - module - defaultViewConfig vn: + - agencyTermConfig - alertLevel - bookingPlanner - businessType diff --git a/package.json b/package.json index 47b3a1564..6f0624360 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.10.0", + "version": "24.8.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 92f228263216e94b5e7155f369ac0fe73a8d7604 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 21 Feb 2024 14:52:28 +0100 Subject: [PATCH 68/86] Revert "Merge pull request 'Revert "Merge branch 'dev' into test"' (!2064) from test_revert into test" This reverts commit cbe23d8df5c4eeade7c9203b05013705c3015f89, reversing changes made to c4a64b93cc4f021ebc6268c48033aec3c00e139b. --- back/methods/collection/getSectors.js | 20 ----- .../collection/spec/getSectors.spec.js | 11 --- back/models/collection.js | 1 - db/dump/.dump/data.sql | 2 - db/dump/fixtures.before.sql | 3 +- .../bs/procedures/ventas_contables_add.sql | 34 ++++---- .../procedures/invoiceInTax_afterUpsert.sql | 15 +++- .../vn/procedures/itemProposal_Add.sql | 70 ----------------- .../vn/procedures/itemShelving_add.sql | 4 + .../vn/procedures/sale_getBoxPickingList.sql | 51 ++---------- .../sectorCollectionSaleGroup_add.sql | 19 +++++ db/routines/vn/procedures/sector_get.sql | 13 ---- db/routines/vn/procedures/ticket_getTax.sql | 58 +++++++------- .../vn/triggers/ticket_beforeUpdate.sql | 10 --- .../00-alterAgencyTermConfig.sql | 3 + .../00-alterGastosResumen.sql | 11 +++ .../00-alterInvoiceOutTaxConfig.sql | 5 ++ .../00-alterItemGroupToOffer.sql | 5 ++ .../01-ventasContablesPk.sql | 14 ++++ .../02-updateExpenseRegularize.sql | 8 ++ .../10862-navyHydrangea/03-updateExpense.sql | 44 +++++++++++ .../04-updateExpenseConflict.sql | 6 ++ .../00-revokeUpdateClient.sql | 37 +++++++++ .../back/methods/invoiceOut/negativeBases.js | 52 ++++++------- .../item-shelving/specs/addListByItem.spec.js | 55 +++++++++++++ .../back/methods/item-shelving/upsertItem.js | 64 +++++++++++++++ modules/item/back/models/item-shelving.js | 1 + .../ticket/specs/transferClient.spec.js | 71 +++++++++-------- .../back/methods/ticket/transferClient.js | 77 +++++++++++++------ .../back/methods/worker/specs/new.spec.js | 28 +++++-- myt.config.yml | 1 - package.json | 2 +- 32 files changed, 486 insertions(+), 309 deletions(-) delete mode 100644 back/methods/collection/getSectors.js delete mode 100644 back/methods/collection/spec/getSectors.spec.js delete mode 100644 db/routines/vn/procedures/itemProposal_Add.sql delete mode 100644 db/routines/vn/procedures/sector_get.sql create mode 100644 db/versions/10862-navyHydrangea/00-alterAgencyTermConfig.sql create mode 100644 db/versions/10862-navyHydrangea/00-alterGastosResumen.sql create mode 100644 db/versions/10862-navyHydrangea/00-alterInvoiceOutTaxConfig.sql create mode 100644 db/versions/10862-navyHydrangea/00-alterItemGroupToOffer.sql create mode 100644 db/versions/10862-navyHydrangea/01-ventasContablesPk.sql create mode 100644 db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql create mode 100644 db/versions/10862-navyHydrangea/03-updateExpense.sql create mode 100644 db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql create mode 100644 db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql create mode 100644 modules/item/back/methods/item-shelving/specs/addListByItem.spec.js create mode 100644 modules/item/back/methods/item-shelving/upsertItem.js diff --git a/back/methods/collection/getSectors.js b/back/methods/collection/getSectors.js deleted file mode 100644 index 12ad0dc06..000000000 --- a/back/methods/collection/getSectors.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('getSectors', { - description: 'Get all sectors', - accessType: 'READ', - returns: { - type: 'Object', - root: true - }, - http: { - path: `/getSectors`, - verb: 'GET' - } - }); - - Self.getSectors = async() => { - const query = `CALL vn.sector_get()`; - const [result] = await Self.rawSql(query); - return result; - }; -}; diff --git a/back/methods/collection/spec/getSectors.spec.js b/back/methods/collection/spec/getSectors.spec.js deleted file mode 100644 index d8fa60663..000000000 --- a/back/methods/collection/spec/getSectors.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -const {models} = require('vn-loopback/server/server'); - -describe('getSectors()', () => { - it('return list of sectors', async() => { - let response = await models.Collection.getSectors(); - - expect(response.length).toBeGreaterThan(0); - expect(response[0].id).toEqual(1); - expect(response[0].description).toEqual('First sector'); - }); -}); diff --git a/back/models/collection.js b/back/models/collection.js index 1c10d49fa..52ef26e88 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -1,6 +1,5 @@ module.exports = Self => { require('../methods/collection/getCollection')(Self); - require('../methods/collection/getSectors')(Self); require('../methods/collection/setSaleQuantity')(Self); require('../methods/collection/previousLabel')(Self); require('../methods/collection/getTickets')(Self); 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/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index 9988c8b29..12b2738f3 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 vn.invoiceOut io ON io.id = t.Factura WHERE year(io.issued) = vYear - AND month(io.issued) = vMonth; + AND month(io.issued) = 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/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index 77e989630..60ec34696 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -8,6 +8,7 @@ BEGIN */ DECLARE vTaxRowLimit INT; DECLARE vLines INT; + DECLARE vHasDistinctTransactions INT; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; @@ -18,6 +19,18 @@ BEGIN IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); - END IF; + END IF; + + SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + JOIN invoiceInSerial iis ON iis.code = ii.serial + WHERE ii.id = vInvoiceInFk + AND iis.taxAreaFk = 'CEE' + AND transactionTypeSageFk; + + IF vHasDistinctTransactions > 1 THEN + CALL util.throw ('This invoice does not allow different types of transactions'); + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemProposal_Add.sql b/db/routines/vn/procedures/itemProposal_Add.sql deleted file mode 100644 index ac4dfa5d5..000000000 --- a/db/routines/vn/procedures/itemProposal_Add.sql +++ /dev/null @@ -1,70 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal_Add`(vSaleFk INT, vMateFk INT, vQuantity INT) -BEGIN -/** - * Añade un nuevo articulo para sustituir a otro, y actualiza la memoria de sustituciones. - * - * @param vSaleFk id de la tabla sale - * @param vMateFk articulo sustituto - * @ param vQuantity cantidad que se va a sustituir - */ - DECLARE vTicketFk INT; - DECLARE vItemFk INT; - DECLARE vWarehouseFk SMALLINT; - DECLARE vDate DATE; - DECLARE vGrouping INT; - DECLARE vBox INT; - DECLARE vPacking INT; - DECLARE vRoundQuantity INT DEFAULT 1; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk - INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - WHERE s.id = vSaleFk; - - CALL buyUltimate(vWarehouseFk, vDate); - - SELECT `grouping`, groupingMode, packing INTO vGrouping, vBox, vPacking - FROM buy b - JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk - WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; - - IF vBox = 2 AND vPacking > 0 THEN - SET vRoundQuantity = vPacking; - END IF; - IF vBox = 1 AND vGrouping > 0 THEN - SET vRoundQuantity = vGrouping; - END IF; - - START TRANSACTION; - - UPDATE sale - SET quantity = quantity - vQuantity - WHERE id = vSaleFk; - - INSERT INTO sale(ticketFk, itemFk, quantity, concept) - SELECT vTicketFk, - vMateFk, - CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, - CONCAT('+ ',i.longName) - FROM item i - WHERE id = vMateFk; - - SELECT LAST_INSERT_ID() INTO vSaleFk; - - CALL sale_calculateComponent(vSaleFk, NULL); - - INSERT INTO itemProposal(itemFk, mateFk, counter) - VALUES(vItemFk, vMateFk, 1) - ON DUPLICATE KEY UPDATE counter = counter + 1; - - COMMIT; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 02762fa0b..2a4676b50 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -19,6 +19,10 @@ BEGIN DECLARE vItemFk INT; SELECT barcodeToItem(vBarcode) INTO vItemFk; + + SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)); + + SET vQuantity = vQuantity * vPacking; IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 0f2b2bc71..0af23e945 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -17,7 +17,6 @@ BEGIN CALL productionControl(vWarehouseFk, 0); - -- Products with vn.item.isBoxPickingMode = TRUE, pay atention to vn.itemShelving.packing CREATE OR REPLACE TEMPORARY TABLE tmp.sale (saleFk INT PRIMARY KEY) SELECT @@ -29,7 +28,7 @@ BEGIN MAKETIME(pb.HH,pb.mm,0) etd, pb.routeFk, FLOOR(s.quantity / ish.packing) stickers, - ish.packing, + IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, b.packagingFk FROM sale s JOIN item i ON i.id = s.itemFk @@ -52,8 +51,8 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN buy b ON b.id = lb.buy_id - WHERE s.quantity BETWEEN ish.packing AND (ish.visible - IFNULL(tISS.reserve,0)) - AND i.isBoxPickingMode + WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut) + <= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0)) AND NOT pb.problem AND sgd.saleFk IS NULL AND p.sectorFk = vSectorFk @@ -64,47 +63,13 @@ BEGIN GROUP BY s.id ORDER BY etd; - -- Remaining products, vn.item.packingOut - INSERT IGNORE INTO tmp.sale - SELECT - s.ticketFk, - s.id saleFk, - s.itemFk, - s.concept, - s.quantity, - MAKETIME(pb.HH,pb.mm,0) etd, - pb.routeFk, - s.quantity / i.packingOut stickers, - i.packingOut, - pc.defaultBigPackageFk - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN itemShelving ish ON ish.itemFk = s.itemFk - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk - JOIN agencyMode am ON am.id = pb.agencyModeFk - JOIN packagingConfig pc - LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk - LEFT JOIN itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = p.sectorFk - LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id - LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk - WHERE s.quantity >= i.packingOut - AND NOT pb.problem - AND s.quantity > 0 - AND sgd.saleFk IS NULL - AND p.sectorFk = vSectorFk - AND ts.isPreviousPreparable - AND iss.visible >= s.quantity - AND ((rm.bufferFk AND rm.isPickingAllowed) - OR am.code = 'REC_ALG') - AND pb.shipped = vDated - GROUP BY s.id - ORDER BY etd; - - SELECT * FROM tmp.sale; + SELECT * + FROM tmp.sale + WHERE stickers; DROP TEMPORARY TABLE tmp.productionBuffer; DROP TEMPORARY TABLE tmp.sale; END$$ DELIMITER ; + +CALL `vn`.`sale_getBoxPickingList`(1, curdate()); \ No newline at end of file diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 9e21defc5..5ffb30635 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -8,6 +8,25 @@ BEGIN * @param vSaleGroupFk Identificador de vn.saleGroup * @param vSectorCollectionFk Identificador de vn.sectorCollection */ + DECLARE vHasSaleGroup INT; + DECLARE vHasSectorCollection INT; + + SELECT COUNT(id) INTO vHasSaleGroup + FROM saleGroup + WHERE id = vSaleGroupFk; + + IF !vHasSaleGroup THEN + CALL util.throw ("invalid saleGroup"); + END IF; + + SELECT COUNT(id) INTO vHasSectorCollection + FROM sectorCollection + WHERE id = vSectorCollectionFk; + + IF !vHasSectorCollection THEN + CALL util.throw ("invalid sectorCollection"); + END IF; + REPLACE sectorCollectionSaleGroup SET sectorCollectionFk = vSectorCollectionFk, saleGroupFk = vSaleGroupFk; diff --git a/db/routines/vn/procedures/sector_get.sql b/db/routines/vn/procedures/sector_get.sql deleted file mode 100644 index fe978203a..000000000 --- a/db/routines/vn/procedures/sector_get.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sector_get`() -BEGIN - -/** - * Obtiene los sectores -*/ - - SELECT s.id,s.description,s.warehouseFk - FROM vn.sector s; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql index 7269a1caf..b9f5c14e3 100644 --- a/db/routines/vn/procedures/ticket_getTax.sql +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -9,6 +9,8 @@ BEGIN * @return tmp.ticketAmount (ticketFk, taxableBase, tax, code) * @return tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) Impuesto desglosado para cada ticket. */ + -- 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)) @@ -17,24 +19,24 @@ BEGIN 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 +45,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 +71,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 +96,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/db/routines/vn/triggers/ticket_beforeUpdate.sql b/db/routines/vn/triggers/ticket_beforeUpdate.sql index 0836b2486..72831bc3d 100644 --- a/db/routines/vn/triggers/ticket_beforeUpdate.sql +++ b/db/routines/vn/triggers/ticket_beforeUpdate.sql @@ -4,7 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_beforeUpdate` FOR EACH ROW BEGIN DECLARE vNewTime TIME; - DECLARE vHasTicketRefund BOOL; SET NEW.editorFk = account.myUser_getId(); @@ -64,14 +63,5 @@ BEGIN CALL vn.routeUpdateM3(NEW.routeFk); END IF; - - SELECT COUNT(*) INTO vHasTicketRefund - FROM ticketRefund - WHERE originalTicketFk = NEW.id - OR refundTicketFk = NEW.id; - - IF vHasTicketRefund AND NEW.clientFk <> OLD.clientFk THEN - CALL util.throw('The ticket has a refund associated'); - END IF; END$$ DELIMITER ; 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/00-alterGastosResumen.sql b/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql new file mode 100644 index 000000000..307b8f205 --- /dev/null +++ b/db/versions/10862-navyHydrangea/00-alterGastosResumen.sql @@ -0,0 +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; + +ALTER TABLE vn2008.gastos_resumen + 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 new file mode 100644 index 000000000..3f8bf2c79 --- /dev/null +++ b/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql @@ -0,0 +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/02-updateExpenseRegularize.sql b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql new file mode 100644 index 000000000..90d865c1d --- /dev/null +++ b/db/versions/10862-navyHydrangea/02-updateExpenseRegularize.sql @@ -0,0 +1,8 @@ +DELETE FROM vn.expense + WHERE id ='' AND id IS NULL AND isWithheld = FALSE; +UPDATE vn.expense + SET id='7002090000' + WHERE id='7002009000'; +UPDATE vn.expense + SET id='7001090000' + WHERE id='7001009000'; diff --git a/db/versions/10862-navyHydrangea/03-updateExpense.sql b/db/versions/10862-navyHydrangea/03-updateExpense.sql new file mode 100644 index 000000000..a44c4c504 --- /dev/null +++ b/db/versions/10862-navyHydrangea/03-updateExpense.sql @@ -0,0 +1,44 @@ +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 7040008000 + WHEN 7001080000 THEN 7000108000 + 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 +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, + 7002090000, 7002100000, 7001090000, 7001100000, + 7000120000, 7002120000, 7000130000, 7000140000); diff --git a/db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql b/db/versions/10862-navyHydrangea/04-updateExpenseConflict.sql new file mode 100644 index 000000000..0e008081b --- /dev/null +++ b/db/versions/10862-navyHydrangea/04-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/10885-wheatHydrangea/00-revokeUpdateClient.sql b/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql new file mode 100644 index 000000000..b22e09615 --- /dev/null +++ b/db/versions/10885-wheatHydrangea/00-revokeUpdateClient.sql @@ -0,0 +1,37 @@ +REVOKE UPDATE ON vn.ticket FROM employee; + +GRANT UPDATE (id, + warehouseFk, + shipped, + nickname, + refFk, + addressFk, + workerFk, + observations, + isSigned, + isLabeled, + isPrinted, + packages, + location, + hour, + created, + isBlocked, + solution, + routeFk, + priority, + hasPriority, + companyFk, + agencyModeFk, + landed, + isBoxed, + isDeleted, + zoneFk, + zonePrice, + zoneBonus, + totalWithVat, + totalWithoutVat, + weight, + clonedFrom, + cmrFk, + editorFk) + ON vn.ticket TO employee; diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index dc9496b4a..66440616c 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, @@ -75,28 +71,26 @@ 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 - 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 ? - 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 + 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') + 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)); diff --git a/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js new file mode 100644 index 000000000..e31ff2e61 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/addListByItem.spec.js @@ -0,0 +1,55 @@ +const {models} = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); + +describe('ItemShelving upsertItem()', () => { + const warehouseFk = 1; + let ctx; + let options; + let tx; + + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx.req + }); + + options = {transaction: tx}; + tx = await models.ItemShelving.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should add two new records', async() => { + const shelvingFk = 'ZPP'; + const items = [1, 1, 1, 2]; + + await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); + const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); + + expect(itemShelvings.length).toEqual(2); + }); + + it('should update the visible items', async() => { + const shelvingFk = 'GVC'; + const items = [2, 2]; + const {visible: itemsBefore} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); + const {visible: itemsAfter} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + + expect(itemsAfter).toEqual(itemsBefore + 2); + }); +}); diff --git a/modules/item/back/methods/item-shelving/upsertItem.js b/modules/item/back/methods/item-shelving/upsertItem.js new file mode 100644 index 000000000..49c2f1b0d --- /dev/null +++ b/modules/item/back/methods/item-shelving/upsertItem.js @@ -0,0 +1,64 @@ +module.exports = Self => { + Self.remoteMethodCtx('upsertItem', { + description: 'Add a record or update it if it already exists.', + accessType: 'WRITE', + accepts: [{ + arg: 'shelvingFk', + type: 'string', + required: true, + }, + { + arg: 'items', + type: ['number'], + required: true, + description: 'array of item foreign keys' + }, + { + arg: 'warehouseFk', + type: 'number', + required: true + }], + + http: { + path: `/upsertItem`, + verb: 'POST' + } + }); + + Self.upsertItem = async(ctx, shelvingFk, items, warehouseFk, options) => { + const myOptions = {userId: ctx.req.accessToken.userId}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + const discardItems = new Set(); + const itemCounts = items.reduce((acc, item) => { + acc[item] = (acc[item] || 0) + 1; + return acc; + }, {}); + + try { + for (let item of items) { + if (!discardItems.has(item)) { + let quantity = itemCounts[item]; + discardItems.add(item); + + await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, NULL, ?)', + [shelvingFk, item, quantity, warehouseFk], myOptions + ); + } + } + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index 98ff18931..c031d8271 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/item-shelving/deleteItemShelvings')(Self); + require('../methods/item-shelving/upsertItem')(Self); require('../methods/item-shelving/getInventory')(Self); }; diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 5a9edd17e..5f1c09776 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -1,49 +1,60 @@ const models = require('vn-loopback/server/server').models; describe('Ticket transferClient()', () => { - const userId = 9; - const activeCtx = { - accessToken: {userId: userId}, - }; - const ctx = {req: activeCtx}; + const originalTicketId = 8; + const refundTicketId = 24; + const clientId = 1; + let ctx; + let options; + let tx; + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} + }; + + options = {transaction: tx}; + tx = await models.Ticket.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); it('should throw an error as the ticket is not editable', async() => { - const tx = await models.Ticket.beginTransaction({}); - let error; - try { - const options = {transaction: tx}; const ticketId = 4; const clientId = 1; await models.Ticket.transferClient(ctx, ticketId, clientId, options); - - await tx.rollback(); } catch (e) { - await tx.rollback(); - error = e; + expect(e.message).toEqual(`This ticket is locked`); } - - expect(error.message).toEqual(`This ticket is locked`); }); - it('should be assigned a different clientFk', async() => { - const tx = await models.Ticket.beginTransaction({}); - let updatedTicket; - const ticketId = 10; - const clientId = 1; + it('should be assigned a different clientFk in the original ticket', async() => { + await models.Ticket.transferClient(ctx, 2, clientId, options); + const afterTransfer = await models.Ticket.findById(2, null, options); - try { - const options = {transaction: tx}; + expect(afterTransfer.clientFk).toEqual(clientId); + }); - await models.Ticket.transferClient(ctx, ticketId, clientId, options); - updatedTicket = await models.Ticket.findById(ticketId, {fields: ['clientFk']}, options); + it('should be assigned a different clientFk in the original and refund ticket and claim', async() => { + await models.Ticket.transferClient(ctx, originalTicketId, clientId, options); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + const [originalTicket, refundTicket] = await models.Ticket.find({ + where: {id: {inq: [originalTicketId, refundTicketId]}} + }, options); - expect(updatedTicket.clientFk).toEqual(clientId); + const claim = await models.Claim.findOne({ + where: {ticketFk: originalTicketId} + }, options); + + expect(originalTicket.clientFk).toEqual(clientId); + expect(refundTicket.clientFk).toEqual(clientId); + expect(claim.clientFk).toEqual(clientId); }); }); diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 60e70d710..d38c0e8a7 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -2,20 +2,17 @@ module.exports = Self => { Self.remoteMethodCtx('transferClient', { description: 'Transfering ticket to another client', accessType: 'WRITE', - accepts: [ - { - arg: 'id', - type: 'number', - required: true, - description: 'the ticket id', - http: {source: 'path'} - }, - { - arg: 'clientFk', - type: 'number', - required: true, - }, - ], + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'the ticket id', + http: {source: 'path'} + }, { + arg: 'clientFk', + type: 'number', + required: true, + }], http: { path: `/:id/transferClient`, verb: 'PATCH' @@ -25,21 +22,51 @@ module.exports = Self => { Self.transferClient = async(ctx, id, clientFk, options) => { const models = Self.app.models; const myOptions = {}; + let tx; + if (typeof options == 'object') Object.assign(myOptions, options); - await Self.isEditableOrThrow(ctx, id, myOptions); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } - const ticket = await models.Ticket.findById( - id, - {fields: ['id', 'shipped', 'clientFk', 'addressFk']}, - myOptions - ); - const client = await models.Client.findById(clientFk, {fields: ['id', 'defaultAddressFk']}, myOptions); + try { + await Self.isEditableOrThrow(ctx, id, myOptions); - await ticket.updateAttributes({ - clientFk, - addressFk: client.defaultAddressFk, - }); + const ticketRefund = await models.TicketRefund.findOne({ + where: {or: [{originalTicketFk: id}, {refundTicketFk: id}]}, + include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}] + }, myOptions); + + const {defaultAddressFk: addressFk} = await models.Client.findById(clientFk, + {fields: ['id', 'defaultAddressFk']}, myOptions); + + const attributes = {clientFk, addressFk}; + + const tickets = []; + const ticketIds = []; + + if (ticketRefund) { + const {refundTicket, originalTicket} = ticketRefund; + tickets.push(refundTicket(), originalTicket()); + + for (const ticket of tickets) { + await ticket.updateAttributes(attributes, myOptions); + ticketIds.push(ticket.id); + } + } else { + await Self.updateAll({id}, attributes, myOptions); + ticketIds.push(id); + } + + await models.Claim.updateAll({ticketFk: {inq: ticketIds}}, {clientFk}, myOptions); + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } }; }; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index d0830b00f..1f74e9b95 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -36,6 +36,7 @@ describe('Worker new', () => { payMethodFk: 1, roleFk: 1 }; + const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -140,15 +141,24 @@ describe('Worker new', () => { it('should create a new worker', async() => { const newWorker = await models.Worker.new({args: defaultWorker, req}); - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); + await removeWorker(newWorker.id); expect(newWorker.id).toBeDefined(); }); + it('should create a new client', async() => { + let newWorker; + let client; + try { + newWorker = await models.Worker.new({args: defaultWorker, req}); + client = await models.Client.findById(newWorker.id); + } finally { + await removeWorker(newWorker.id); + } + + expect(client).toBeDefined(); + }); + it('should create a new worker in client', async() => { const bruceWayneId = 1101; const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']}); @@ -170,3 +180,11 @@ describe('Worker new', () => { expect(newWorker.id).toEqual(bruceWayneId); }); }); + +async function removeWorker(id) { + await models.Worker.destroyById(id); + await models.Address.destroyAll({clientFk: id}); + await models.Mandate.destroyAll({clientFk: id}); + await models.Client.destroyById(id); + await models.VnUser.destroyById(id); +} 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 diff --git a/package.json b/package.json index 6f0624360..47b3a1564 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.8.0", + "version": "24.10.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 0a16335eaa0b11e8efa4514a00ca807be695ee07 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 21 Feb 2024 18:48:39 +0100 Subject: [PATCH 69/86] fix: refs #6371 restore tables --- db/versions/10835-brownCarnation/00-firstScript.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/db/versions/10835-brownCarnation/00-firstScript.sql b/db/versions/10835-brownCarnation/00-firstScript.sql index e66b84ee5..be53d866c 100644 --- a/db/versions/10835-brownCarnation/00-firstScript.sql +++ b/db/versions/10835-brownCarnation/00-firstScript.sql @@ -97,10 +97,6 @@ ALTER TABLE IF EXISTS vn2008.Tickets_stack__ COMMENT='refs #6371 deprecated 2024 ALTER TABLE IF EXISTS vn2008.Tipos_f11 RENAME vn2008.Tipos_f11__; ALTER TABLE IF EXISTS vn2008.Tipos_f11__ COMMENT='refs #6371 deprecated 2024-01-11'; --- Para la tabla Tramos -ALTER TABLE IF EXISTS vn2008.Tramos RENAME vn2008.Tramos__; -ALTER TABLE IF EXISTS vn2008.Tramos__ COMMENT='refs #6371 deprecated 2024-01-11'; - -- Para la tabla accion_dits ALTER TABLE IF EXISTS vn2008.accion_dits RENAME vn2008.accion_dits__; ALTER TABLE IF EXISTS vn2008.accion_dits__ COMMENT='refs #6371 deprecated 2024-01-11'; @@ -161,10 +157,6 @@ ALTER TABLE IF EXISTS vn2008.cyc__ COMMENT='refs #6371 deprecated 2024-01-11'; ALTER TABLE IF EXISTS vn2008.cyc_declaration RENAME vn2008.cyc_declaration__; ALTER TABLE IF EXISTS vn2008.cyc_declaration__ COMMENT='refs #6371 deprecated 2024-01-11'; --- Para la tabla dock -ALTER TABLE IF EXISTS vn2008.dock RENAME vn2008.dock__; -ALTER TABLE IF EXISTS vn2008.dock__ COMMENT='refs #6371 deprecated 2024-01-11'; - -- Para la tabla edi_testigos ALTER TABLE IF EXISTS vn2008.edi_testigos RENAME vn2008.edi_testigos__; ALTER TABLE IF EXISTS vn2008.edi_testigos__ COMMENT='refs #6371 deprecated 2024-01-11'; From 5110d6e71d3f26b288e64a18fa5d8f91399792b0 Mon Sep 17 00:00:00 2001 From: davidd Date: Thu, 22 Feb 2024 07:09:35 +0100 Subject: [PATCH 70/86] fix error refs #6372 --- .../00-table.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/versions/{10898-6906-workerActivity => 10898-workerActivity}/00-table.sql (100%) diff --git a/db/versions/10898-6906-workerActivity/00-table.sql b/db/versions/10898-workerActivity/00-table.sql similarity index 100% rename from db/versions/10898-6906-workerActivity/00-table.sql rename to db/versions/10898-workerActivity/00-table.sql From d48fd77f48ce87037cd683fe2bd43dafcefab7ea Mon Sep 17 00:00:00 2001 From: davidd Date: Thu, 22 Feb 2024 08:25:38 +0100 Subject: [PATCH 71/86] refs #6372 --- db/versions/10896-salmonOrchid/03-gastos_resumen.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index 5fa1f31fb..2308cb1fd 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -14,5 +14,11 @@ ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK F ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; +ALTER TABLE vn.expenseManual MODIFY COLUMN companyFk int(10) unsigned NULL; + +UPDATE vn.expenseManual + SET companyFK= NULL + WHERE companyFk= 0 + ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; From f4f6eeb6feb1bcf65b2f59a5a972793500fcd2c5 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 22 Feb 2024 08:36:14 +0100 Subject: [PATCH 72/86] fix(version): refs #6372 add semicolon --- db/versions/10896-salmonOrchid/03-gastos_resumen.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index 2308cb1fd..dbb71bca2 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -18,7 +18,7 @@ ALTER TABLE vn.expenseManual MODIFY COLUMN companyFk int(10) unsigned NULL; UPDATE vn.expenseManual SET companyFK= NULL - WHERE companyFk= 0 + WHERE companyFk= 0; ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; From 0344a8178510b156253257a3c49b2453aa75aec9 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 22 Feb 2024 09:08:37 +0100 Subject: [PATCH 73/86] fix: refs #6780 Rollback vn2008.versiones --- db/routines/vn2008/views/versiones.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/routines/vn2008/views/versiones.sql diff --git a/db/routines/vn2008/views/versiones.sql b/db/routines/vn2008/views/versiones.sql new file mode 100644 index 000000000..3d27f4f92 --- /dev/null +++ b/db/routines/vn2008/views/versiones.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`versiones` +AS SELECT `m`.`app` AS `programa`, + `m`.`version` AS `version`, + 0 AS `critical` +FROM `vn`.`mdbVersion` `m` +WHERE `m`.`branchFk` = 'master' \ No newline at end of file From 03ebac78fc9ae9b4dda5d97ea9c5923dbd039fee Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 22 Feb 2024 09:36:14 +0100 Subject: [PATCH 74/86] ci: HOTFIX Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index d508da8bf..20cfbd31d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -235,6 +235,7 @@ pipeline { if (index != -1) message = message.substring(0, index) + setEnv() rocketSend( channel: 'vn-database', message: "*DB version uploaded:* ${message}" From dd3249ea59af1a34d74774be7a1e7cbd88aec5c9 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 22 Feb 2024 09:36:48 +0100 Subject: [PATCH 75/86] ci: HOTFIX Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index c77c88201..a39540173 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -172,6 +172,7 @@ pipeline { if (index != -1) message = message.substring(0, index) + setEnv() rocketSend( channel: 'vn-database', message: "*DB version uploaded:* ${message}" From 80fc9e4472bb29e879d511dd0694aa4955c0f8a1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 22 Feb 2024 10:16:29 +0100 Subject: [PATCH 76/86] fix: refs #6184 Quitadas transacciones en los SELECT en saveSign.js --- modules/ticket/back/methods/ticket/saveSign.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 9c6e8181a..d7cc63ada 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -47,7 +47,7 @@ module.exports = Self => { const dmsTypeTicket = await models.DmsType.findOne({ where: {code: 'ticket'}, fields: ['id'] - }, myOptions); + }); async function setLocation(ticketId) { await models.Delivery.create({ @@ -70,7 +70,7 @@ module.exports = Self => { } } ] - }, myOptions); + }); if (ticketDms?.dms()?.id) return true; } @@ -113,17 +113,17 @@ module.exports = Self => { fields: ['id'] } }] - }, myOptions); + }); const ticketState = await models.TicketState.findOne({ where: {ticketFk: ticketId}, fields: ['alertLevel'] - }, myOptions); + }); const packedAlertLevel = await models.AlertLevel.findOne({ where: {code: 'PACKED'}, fields: ['id'] - }, myOptions); + }); if (!ticketState) throw new UserError('Ticket does not exist'); @@ -141,7 +141,7 @@ module.exports = Self => { const deliveryState = await models.State.findOne({ where: {code: 'DELIVERED'} - }, myOptions); + }); await models.Ticket.state(ctx, { ticketFk: ticketId, From 9f067fc9b3113913eb9d4cb1b28e8b62a51a1054 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 22 Feb 2024 10:20:15 +0100 Subject: [PATCH 77/86] build: HOTFIX Myt updated --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6f0624360..d7dea767e 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.7", + "@verdnatura/myt": "^1.6.8", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 025be234e..36bff2fe1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -131,8 +131,8 @@ devDependencies: specifier: ^7.7.7 version: 7.23.7(@babel/core@7.23.9) '@verdnatura/myt': - specifier: ^1.6.7 - version: 1.6.7 + specifier: ^1.6.8 + version: 1.6.8 angular-mocks: specifier: ^1.7.9 version: 1.8.3 @@ -2633,8 +2633,8 @@ packages: dev: false optional: true - /@verdnatura/myt@1.6.7: - resolution: {integrity: sha512-t/Q1T3QzHpZFdxwIyQL/CV5g+HJvWE6Q65VeA9k0svZdX/vezgnQ21nkI+wuvIurIl6BXqq2Arx7EWYkAhGNNA==} + /@verdnatura/myt@1.6.8: + resolution: {integrity: sha512-jpadr6yAR9TQXPv+has5yOYAolR/YEzsxbLgMR7BoDrpLyVFLHJEy4Dfe+Hy11r3AmxCB/8lWM+La1YGvXMWOA==} hasBin: true dependencies: '@sqltools/formatter': 1.2.5 From b6086e74c119c64e9f280c6262aa8e35557cf89e Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 22 Feb 2024 10:39:34 +0100 Subject: [PATCH 78/86] refs #6922 change order --- print/templates/reports/invoice/sql/sales.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/print/templates/reports/invoice/sql/sales.sql b/print/templates/reports/invoice/sql/sales.sql index 3833a3700..8e5ad1102 100644 --- a/print/templates/reports/invoice/sql/sales.sql +++ b/print/templates/reports/invoice/sql/sales.sql @@ -7,7 +7,8 @@ SELECT s.discount, s.itemFk, s.concept, - tc.code vatType + tc.code vatType, + it.isPackaging FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.supplier su ON su.id = io.companyFk @@ -34,9 +35,10 @@ SELECT ts.quantity, ts.price, 0 discount, - '', - ts.description concept, - tc.code vatType + NULL, + ts.description, + tc.code, + NULL FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.ticketService ts ON ts.ticketFk = t.id @@ -46,3 +48,4 @@ SELECT JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk JOIN vn.taxClass tc ON tc.id = ts.taxClassFk WHERE t.refFk = ? +ORDER BY (isPackaging), concept, itemFk From 13249fae0888203210551726f4e0b02398d6e4cb Mon Sep 17 00:00:00 2001 From: davidd Date: Thu, 22 Feb 2024 10:47:27 +0100 Subject: [PATCH 79/86] refs #6372 --- .../10896-salmonOrchid/03-gastos_resumen.sql | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql index 2308cb1fd..29152bdd8 100644 --- a/db/versions/10896-salmonOrchid/03-gastos_resumen.sql +++ b/db/versions/10896-salmonOrchid/03-gastos_resumen.sql @@ -1,24 +1,33 @@ ALTER TABLE IF EXISTS vn2008.gastos_resumen DROP FOREIGN KEY IF EXISTS gastos_resumen_expense_FK; ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseManual`; -ALTER TABLE IF EXISTS `vn`.`expenseManual` +ALTER TABLE `vn`.`expenseManual` CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL, CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL, CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL; -ALTER TABLE IF EXISTS vn.expenseManual COLLATE=utf8mb3_general_ci; +ALTER TABLE vn.expenseManual COLLATE=utf8mb3_general_ci; -ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; +ALTER TABLE vn.expenseManual MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; -ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE IF EXISTS vn.expenseManual MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; +ALTER TABLE vn.expenseManual DROP PRIMARY KEY; ALTER TABLE vn.expenseManual MODIFY COLUMN companyFk int(10) unsigned NULL; +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.expenseManual ADD IF NOT EXISTS id INT unsigned NOT NULL FIRST; + +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_pk PRIMARY KEY IF NOT EXISTS (id); + +ALTER TABLE vn.expenseManual ADD CONSTRAINT expenseManual_unique UNIQUE KEY IF NOT EXISTS (expenseFk,`year`,`month`,companyFk); + +ALTER TABLE vn.expenseManual MODIFY COLUMN IF EXISTS companyFk int(10) unsigned NOT NULL; + UPDATE vn.expenseManual SET companyFK= NULL - WHERE companyFk= 0 + WHERE companyFk= 0; -ALTER TABLE IF EXISTS vn.expenseManual ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; From 7d3cf162b8579d16d97d01c6c392f597463f557d Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 22 Feb 2024 11:22:39 +0100 Subject: [PATCH 80/86] fix: refs #6184 uploadFile --- back/methods/dms/uploadFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index 8456cf2d3..9748b8225 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -88,7 +88,7 @@ module.exports = Self => { warehouseFk: args.warehouseId, reference: args.reference, description: args.description, - contentType: args.contentType, + contentType: uploadedFile.type, hasFile: args.hasFile }; const extension = await models.DmsContainer.getFileExtension(uploadedFile.name); From 76b143309931d1f5e2d43255548229e90667910e Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 22 Feb 2024 12:48:07 +0100 Subject: [PATCH 81/86] fix: refs #6878 use clockIn procedure on update time --- .../procedures/workerTimeControl_clockIn.sql | 2 +- .../00-professionalCategoryAddCode.sql | 6 +++ .../worker-time-control/specs/clockIn.spec.js | 45 ++++++++++++++++--- .../worker-time-control/updateTimeEntry.js | 37 ++++++++------- modules/worker/front/time-control/index.js | 12 ++--- .../worker/front/time-control/index.spec.js | 2 +- 6 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 db/versions/10903-pinkIvy/00-professionalCategoryAddCode.sql diff --git a/db/routines/vn/procedures/workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql index 23739a515..77a628d10 100644 --- a/db/routines/vn/procedures/workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -75,7 +75,7 @@ BEGIN SET vDated = DATE(vTimed); - SELECT IF(pc.name = 'Conductor +3500kg', + SELECT IF(pc.code = 'driveCE', wc.dayBreakDriver, wc.dayBreak), wc.shortWeekBreak, diff --git a/db/versions/10903-pinkIvy/00-professionalCategoryAddCode.sql b/db/versions/10903-pinkIvy/00-professionalCategoryAddCode.sql new file mode 100644 index 000000000..7caa42f32 --- /dev/null +++ b/db/versions/10903-pinkIvy/00-professionalCategoryAddCode.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.professionalCategory DROP COLUMN IF EXISTS code; +ALTER TABLE IF EXISTS vn.professionalCategory ADD COLUMN code VARCHAR(25) DEFAULT NULL; + +UPDATE vn.professionalCategory + SET code = 'driverCE' + WHERE name = 'Conductor C + E'; \ No newline at end of file diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index ff4cac7b7..0ee439941 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -46,6 +46,31 @@ describe('workerTimeControl clockIn()', () => { } }); + it('should throw an error trying to change a middle hour to out not resting 12h', async() => { + activeCtx.accessToken.userId = HHRRId; + const workerId = teamBossId; + + const tx = await models.WorkerTimeControl.beginTransaction({}); + try { + const options = {transaction: tx}; + + const entryTime = "2000-12-25T11:00:00.000Z"; + ctx.args = {timed: entryTime, direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const middleTime ="2000-12-26T11:00:00.000Z"; + ctx.args = {timed: middleTime, direction: 'middle'}; + const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const direction = 'out'; + await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options); + await tx.rollback(); + } catch (e) { + expect(e.message).toBe('Superado el tiempo máximo entre entrada y salida'); + await tx.rollback(); + } + }); + describe('as Role errors', () => { it('should add if the current user is team boss and the target user is himself', async() => { activeCtx.accessToken.userId = teamBossId; @@ -110,16 +135,22 @@ describe('workerTimeControl clockIn()', () => { todayAtOne.setHours(1, 0, 0, 0); ctx.args = {timed: todayAtOne, direction: 'in'}; - const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + const entryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + expect(entryTime.id).toBeDefined(); + const todayAtTwo = Date.vnNew(); - expect(createdTimeEntry.id).toBeDefined(); - - ctx.args = {direction: 'out'}; - const updatedTimeEntry = await models.WorkerTimeControl.updateTimeEntry( - ctx, createdTimeEntry.id, options + todayAtTwo.setHours(2, 0, 0, 0); + ctx.args = {timed: todayAtTwo, direction: 'middle'}; + const middleTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const direction = 'out'; + const {id:outTimeEntryId} = await models.WorkerTimeControl.updateTimeEntry( + ctx, middleTime.id, direction, options ); - expect(updatedTimeEntry.direction).toEqual('out'); + const {direction: updatedDirection} = await models.WorkerTimeControl.findById(outTimeEntryId,{fields:['direction']},options); + expect(updatedDirection).toEqual('out'); + await tx.rollback(); } catch (e) { await tx.rollback(); diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index e9d35f880..7e4455447 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -26,32 +26,39 @@ module.exports = Self => { } }); - Self.updateTimeEntry = async(ctx, id, options) => { + Self.updateTimeEntry = async(ctx, timeEntryId, direction, options) => { const currentUserId = ctx.req.accessToken.userId; const models = Self.app.models; - const args = ctx.args; - const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); - const targetTimeEntry = await Self.findById(id, null, myOptions); - const isSubordinate = await models.Worker.isSubordinate(ctx, targetTimeEntry.userFk, myOptions); - const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE'); - const isHimself = currentUserId == targetTimeEntry.userFk; + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } - const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss); + try { + const {id, userFk, timed} = await Self.findById(timeEntryId, null, myOptions); + const isSubordinate = await models.Worker.isSubordinate(ctx, userFk, myOptions); + const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE'); + const isHimself = currentUserId == userFk; - if (notAllowed) - throw new UserError(`You don't have enough privileges`); + const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss); + if (notAllowed) throw new UserError(`You don't have enough privileges`); - const timeEntryUpdated = await targetTimeEntry.updateAttributes({ - direction: args.direction - }, myOptions); + await models.WorkerTimeControl.deleteById(id, myOptions); + const timeEntryUpdatedId = await Self.clockIn(userFk, timed, direction, null, myOptions); - await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions); + await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions); - return timeEntryUpdated; + if (tx) await tx.commit(); + return timeEntryUpdatedId; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } }; }; diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index f6a6ed535..094e200a4 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -415,11 +415,13 @@ class Controller extends Section { throw new Error(`The entry type can't be empty`); const query = `WorkerTimeControls/${entry.id}/updateTimeEntry`; - this.$http.post(query, {direction: entry.direction}) - .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) - .then(() => this.$.editEntry.hide()) - .then(() => this.fetchHours()) - .then(() => this.getMailStates(this.date)); + if (entry.direction !== entry.$orgRow.direction) { + this.$http.post(query, {direction: entry.direction}) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) + .then(() => this.$.editEntry.hide()) + .then(() => this.fetchHours()) + .then(() => this.getMailStates(this.date)); + } } catch (e) { this.vnApp.showError(this.$t(e.message)); } diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index 10e8aba0d..8610da46e 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -130,7 +130,7 @@ describe('Component vnWorkerTimeControl', () => { controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())}; controller.date = today; controller.fetchHours = jest.fn(); - controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'}; + controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in', $orgRow: {direction: null}}; controller.$.editEntry = { hide: () => {} }; From fac7071bae86e416fff632385600753437f2c8aa Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 22 Feb 2024 14:38:26 +0100 Subject: [PATCH 82/86] refs #6414 fix(newWorker): back test --- db/dump/fixtures.before.sql | 3 +++ .../back/methods/worker/specs/new.spec.js | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 43293c9ea..7c6a2db6b 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3068,3 +3068,6 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns VALUES (1,'123456A','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',442,1,2,1,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'), (2,'123456N','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',69,3,4,2,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'), (3,'123456B','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',567,5,6,69,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'); + +UPDATE vn.department + SET workerFk = null; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index 1f74e9b95..d3e9cb9d0 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -139,9 +139,12 @@ describe('Worker new', () => { }); it('should create a new worker', async() => { - const newWorker = await models.Worker.new({args: defaultWorker, req}); - - await removeWorker(newWorker.id); + let newWorker; + try { + newWorker = await models.Worker.new({args: defaultWorker, req}); + } finally { + await removeWorker(newWorker.id); + } expect(newWorker.id).toBeDefined(); }); @@ -173,9 +176,12 @@ describe('Worker new', () => { }), req }; - const newWorker = await models.Worker.new(newWorkerData); - - await models.Worker.destroyById(newWorker.id); + let newWorker; + try { + newWorker = await models.Worker.new(newWorkerData); + } finally { + await models.Worker.destroyById(newWorker.id); + } expect(newWorker.id).toEqual(bruceWayneId); }); From df5e9bc830473f6d97e1ae714804a1045abc4828 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 22 Feb 2024 14:46:10 +0100 Subject: [PATCH 83/86] fix: refs #6184 Rollback saveSign.js --- .../ticket/back/methods/ticket/saveSign.js | 131 ++++++++---------- 1 file changed, 61 insertions(+), 70 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index d7cc63ada..fd40c1c22 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -33,8 +33,8 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; let tx; - let ticket; - let externalTickets = []; + let dms; + let gestDocCreated = false; if (typeof options == 'object') Object.assign(myOptions, options); @@ -44,11 +44,6 @@ module.exports = Self => { myOptions.transaction = tx; } - const dmsTypeTicket = await models.DmsType.findOne({ - where: {code: 'ticket'}, - fields: ['id'] - }); - async function setLocation(ticketId) { await models.Delivery.create({ ticketFk: ticketId, @@ -58,106 +53,102 @@ module.exports = Self => { }, myOptions); } - async function hasSignDms(ticketId) { + async function gestDocExists(ticketId) { const ticketDms = await models.TicketDms.findOne({ where: {ticketFk: ticketId}, - include: [ - { - relation: 'dms', - fields: ['id'], - scope: { - where: {dmsTypeFk: dmsTypeTicket.id} - } - } - ] - }); - if (ticketDms?.dms()?.id) return true; + fields: ['dmsFk'] + }, myOptions); + + if (!ticketDms) return false; + + const ticket = await models.Ticket.findById(ticketId, {fields: ['isSigned']}, myOptions); + if (ticket.isSigned == true) + return true; + else + await models.Dms.destroyAll({where: {reference: ticketId}}, myOptions); + + return false; } - async function createGestDoc() { + async function createGestDoc(id) { + const ticket = await models.Ticket.findById(id, + { + include: [ + { + relation: 'warehouse', + scope: { + fields: ['id'] + } + }, { + relation: 'client', + scope: { + fields: ['name'] + } + }, { + relation: 'route', + scope: { + fields: ['id'] + } + } + ] + }, myOptions); + const dmsType = await models.DmsType.findOne({where: {code: 'Ticket'}, fields: ['id']}, myOptions); const ctxUploadFile = Object.assign({}, ctx); + if (ticket.route() === null) + throw new UserError('Ticket without route'); ctxUploadFile.args = { warehouseId: ticket.warehouseFk, companyId: ticket.companyFk, - dmsTypeId: dmsTypeTicket.id, - reference: ticket.id, + dmsTypeId: dmsType.id, + reference: '', description: `Firma del cliente - Ruta ${ticket.route().id}`, - contentType: 'image/png', - hasFile: true + hasFile: false }; - const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions); - await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); + dms = await models.Dms.uploadFile(ctxUploadFile, myOptions); + gestDocCreated = true; } try { for (const ticketId of tickets) { - ticket = await models.Ticket.findById(ticketId, { - include: [{ - relation: 'address', - scope: { - include: { - relation: 'province', - scope: { - include: { - relation: 'country', - scope: { - fields: ['code'] - } - } - } - } - } - }, { - relation: 'route', - scope: { - fields: ['id'] - } - }] - }); + const ticketState = await models.TicketState.findOne( + {where: {ticketFk: ticketId}, + fields: ['alertLevel'] + }, myOptions); - const ticketState = await models.TicketState.findOne({ - where: {ticketFk: ticketId}, - fields: ['alertLevel'] - }); - - const packedAlertLevel = await models.AlertLevel.findOne({ - where: {code: 'PACKED'}, + const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'}, fields: ['id'] - }); + }, myOptions); if (!ticketState) throw new UserError('Ticket does not exist'); - if (!ticket.route()) - throw new UserError('Ticket without route'); if (ticketState.alertLevel < packedAlertLevel.id) throw new UserError('This ticket cannot be signed because it has not been boxed'); - if (await ticket.isSigned) + if (await gestDocExists(ticketId)) throw new UserError('Ticket is already signed'); if (location) await setLocation(ticketId); - if (!await hasSignDms(ticketId)) - await createGestDoc(ticketId); + if (!gestDocCreated) await createGestDoc(ticketId); + await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions); + const ticket = await models.Ticket.findById(ticketId, null, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); const deliveryState = await models.State.findOne({ - where: {code: 'DELIVERED'} - }); + where: { + code: 'DELIVERED' + } + }, myOptions); await models.Ticket.state(ctx, { ticketFk: ticketId, stateFk: deliveryState.id }, myOptions); - - if (ticket?.address()?.province()?.country()?.code != 'ES') { - await models.Ticket.saveCmr(ctx, [ticketId], myOptions); - externalTickets.push(ticketId); - } } + if (tx) await tx.commit(); + return; } catch (e) { if (tx) await tx.rollback(); throw e; } - await models.Route.cmrEmail(ctx, externalTickets); }; }; From 20e5eda4d14ddd7292b077f3b59a41f0f20bccc6 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 22 Feb 2024 16:16:32 +0100 Subject: [PATCH 84/86] fix: refs #6915 broken view vn.doc removed --- db/routines/vn/views/doc.sql | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 db/routines/vn/views/doc.sql diff --git a/db/routines/vn/views/doc.sql b/db/routines/vn/views/doc.sql deleted file mode 100644 index 31ac20640..000000000 --- a/db/routines/vn/views/doc.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`doc` -AS SELECT `g`.`id` AS `id`, - `g`.`sref` AS `sref`, - `g`.`brief` AS `brief`, - `g`.`emp_id` AS `companyFk`, - `g`.`orden` AS `order`, - `g`.`file` AS `file`, - `g`.`original` AS `original`, - `g`.`trabajador_id` AS `workerFk`, - `g`.`odbc_date` AS `created`, - `g`.`warehouse_id` AS `warehouseFk` -FROM `vn2008`.`gestdoc` `g` From 6580fd44cdabf3804e363a9b477bf3d229d70462 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 23 Feb 2024 07:18:32 +0100 Subject: [PATCH 85/86] fix: refs #6371 bankPolicy_notifyExpired accountingFk --- db/routines/vn/procedures/bankPolicy_notifyExpired.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/bankPolicy_notifyExpired.sql b/db/routines/vn/procedures/bankPolicy_notifyExpired.sql index 6bdc6f759..52b747659 100644 --- a/db/routines/vn/procedures/bankPolicy_notifyExpired.sql +++ b/db/routines/vn/procedures/bankPolicy_notifyExpired.sql @@ -16,7 +16,7 @@ BEGIN LEFT JOIN vn.supplier s ON s.id = bp.supplierFk LEFT JOIN vn.bank b - ON b.id = bp.bankFk + ON b.id = bp.accountingFk WHERE bp.insuranceExpired = util.VN_CURDATE(); END$$ DELIMITER ; From 6345d1ae425b05c9e55e099af61c6856285c00b3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 23 Feb 2024 08:14:58 +0100 Subject: [PATCH 86/86] fix refs #6780 XDiario --- db/routines/vn/procedures/duaInvoiceInBooking.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index b68d23f9d..26580907c 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -48,7 +48,7 @@ BEGIN IF vCounter > 0 OR vASIEN > 0 THEN - UPDATE vn2008.XDiario x + UPDATE XDiario x JOIN ledgerConfig lc ON lc.lastBookEntry = x.ASIEN SET x.ASIEN = vASIEN;