From c4870d52de17c101e17d421f2dd633db8ba92f74 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 13 Jan 2025 14:37:27 +0100 Subject: [PATCH 01/12] feat: refs #257275 defaulterFilter --- modules/client/back/methods/defaulter/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 5359ce4a7..cf8bd855a 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -94,7 +94,7 @@ module.exports = Self => { AND r1.started = r2.maxStarted ) r ON r.clientFk = c.id LEFT JOIN workerDepartment wd ON wd.workerFk = u.id - JOIN department dp ON dp.id = wd.departmentFk + LEFT JOIN department dp ON dp.id = wd.departmentFk WHERE d.created = ? AND d.amount > 0 From e273733832016b0916fa7cccff42a46f1f89a5b6 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 14 Jan 2025 09:33:26 +0100 Subject: [PATCH 02/12] refactor: order by id --- modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index f66221409..78fce348e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -74,7 +74,8 @@ module.exports = Self => { AND t.companyFk = ? AND NOT t.isDeleted GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id) - HAVING SUM(t.totalWithVat) > 0;`; + HAVING SUM(t.totalWithVat) > 0 + ORDER BY c.id`; const addresses = await Self.rawSql(query, [ minShipped, From 01072f7cbc394f4fa7f68768a0c3a5e6c081a417 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 14 Jan 2025 11:36:54 +0100 Subject: [PATCH 03/12] fix: hotfix 7366 6943 --- modules/client/back/models/client-credit.json | 5 ++++- modules/travel/back/methods/travel/filter.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/client/back/models/client-credit.json b/modules/client/back/models/client-credit.json index b92639b80..b57374dc3 100644 --- a/modules/client/back/models/client-credit.json +++ b/modules/client/back/models/client-credit.json @@ -19,6 +19,9 @@ }, "created": { "type": "date" + }, + "workerFk": { + "type": "number" } }, "relations": { @@ -33,4 +36,4 @@ "foreignKey": "workerFk" } } -} \ No newline at end of file +} diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index 30c1a45fa..d10ff080b 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -91,6 +91,11 @@ module.exports = Self => { arg: 'landed', type: 'date', description: 'The landed date' + }, + { + arg: 'awbFk', + type: 'number', + description: 'The awbFk id' } ], returns: { @@ -168,7 +173,9 @@ module.exports = Self => { t.totalEntries, t.isRaid, t.daysInForward, + t.awbFk, am.name agencyModeName, + a.code awbCode, win.name warehouseInName, wout.name warehouseOutName, cnt.code continent @@ -176,6 +183,7 @@ module.exports = Self => { JOIN vn.agencyMode am ON am.id = t.agencyModeFk JOIN vn.warehouse win ON win.id = t.warehouseInFk JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk + JOIN vn.awb a ON a.id = t.awbFk JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN country c ON c.id = wo.countryFk LEFT JOIN continent cnt ON cnt.id = c.continentFk) AS t` From c2ca9cfbe5ca58a699660d6dd437c4291a480f8e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 15 Jan 2025 12:26:16 +0100 Subject: [PATCH 04/12] feat: refs #7531 Added address_hasDelivery --- .../vn/functions/address_hasDelivery.sql | 24 +++++++++++++++++++ .../vn/procedures/zone_getAddresses.sql | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/functions/address_hasDelivery.sql diff --git a/db/routines/vn/functions/address_hasDelivery.sql b/db/routines/vn/functions/address_hasDelivery.sql new file mode 100644 index 000000000..f37edbd34 --- /dev/null +++ b/db/routines/vn/functions/address_hasDelivery.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`address_hasDelivery`(vSelf INT, vLanded DATE) + RETURNS BOOL + DETERMINISTIC +BEGIN +/** + * Retorna si hay reparto disponible para + * la dirección y fecha solicitada. + * + * @param vSelf Id de dirección de envío + * @param vLanded Fecha de entrega + * @return true|false + */ + DECLARE vHasDelivery BOOL; + + CALL zone_getAgency(vSelf, vLanded); + + SELECT EXISTS (SELECT TRUE FROM tmp.zoneGetAgency) INTO vHasDelivery; + + RETURN vHasDelivery; + + DROP TEMPORARY TABLE tmp.zoneGetAgency; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 2e5982c82..0e52abe1c 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -21,6 +21,7 @@ BEGIN SELECT clientFk FROM vn.ticket WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped) + AND NOT isDeleted ) SELECT c.id, c.name, @@ -50,7 +51,8 @@ BEGIN AND c.isActive AND ct.code = 'normal' AND bt.code <> 'worker' - AND (d.id = vDepartmentFk OR NOT vDepartmentFk) + AND (d.id = vDepartmentFk OR vDepartmentFk IS NULL) + AND vn.address_hasDelivery(c.defaultAddressFk, vShipped) GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From c24b00856765fbd09c5d5a73182508619ddeb8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 15 Jan 2025 16:34:44 +0000 Subject: [PATCH 05/12] Actualizar modules/travel/back/methods/travel/filter.js --- modules/travel/back/methods/travel/filter.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index d10ff080b..837e30b30 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -1,4 +1,3 @@ - const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; @@ -179,11 +178,11 @@ module.exports = Self => { win.name warehouseInName, wout.name warehouseOutName, cnt.code continent - FROM vn.travel t - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.warehouse win ON win.id = t.warehouseInFk - JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk - JOIN vn.awb a ON a.id = t.awbFk + FROM travel t + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN warehouse win ON win.id = t.warehouseInFk + JOIN warehouse wout ON wout.id = t.warehouseOutFk + LEFT JOIN awb a ON a.id = t.awbFk JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN country c ON c.id = wo.countryFk LEFT JOIN continent cnt ON cnt.id = c.continentFk) AS t` From 69b78b6bf1b2b36822a043e36b58f04b5f6667d2 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 16 Jan 2025 15:04:21 +0100 Subject: [PATCH 06/12] feat: refs #7531 Added address_hasDelivery --- db/routines/vn/functions/address_hasDelivery.sql | 12 ++++++++++-- db/routines/vn/procedures/zone_getAddresses.sql | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/functions/address_hasDelivery.sql b/db/routines/vn/functions/address_hasDelivery.sql index f37edbd34..719cc14f0 100644 --- a/db/routines/vn/functions/address_hasDelivery.sql +++ b/db/routines/vn/functions/address_hasDelivery.sql @@ -1,5 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`address_hasDelivery`(vSelf INT, vLanded DATE) +CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`address_hasDelivery`( + vSelf INT, + vAgencyModeFk INT, + vLanded DATE +) RETURNS BOOL DETERMINISTIC BEGIN @@ -15,7 +19,11 @@ BEGIN CALL zone_getAgency(vSelf, vLanded); - SELECT EXISTS (SELECT TRUE FROM tmp.zoneGetAgency) INTO vHasDelivery; + SELECT EXISTS( + SELECT TRUE + FROM tmp.zoneGetAgency + WHERE agencyModeFk = vAgencyModeFk + ) INTO vHasDelivery; RETURN vHasDelivery; diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 0e52abe1c..05267c14c 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -1,6 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( vSelf INT, + vAgencyModeFk INT, vShipped DATE, vDepartmentFk INT ) @@ -52,7 +53,7 @@ BEGIN AND ct.code = 'normal' AND bt.code <> 'worker' AND (d.id = vDepartmentFk OR vDepartmentFk IS NULL) - AND vn.address_hasDelivery(c.defaultAddressFk, vShipped) + AND vn.address_hasDelivery(c.defaultAddressFk, vAgencyModeFk, vShipped) GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From 1aa1fbda6cc12818da9071ba0d779a6d440c7699 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 17 Jan 2025 08:10:26 +0100 Subject: [PATCH 07/12] feat: refs #7531 Added address_hasDelivery --- db/routines/vn/procedures/zone_getAddresses.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 05267c14c..90ad89bf3 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -1,7 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( vSelf INT, - vAgencyModeFk INT, vShipped DATE, vDepartmentFk INT ) @@ -16,6 +15,12 @@ BEGIN * @param vDepartmentFk Id de departamento * @return Un select */ + DECLARE vAgencyModeFk INT; + + SELECT agencyModeFk INTO vAgencyModeFk + FROM `zone` + WHERE id = vSelf; + CALL zone_getPostalCode(vSelf); WITH clientWithTicket AS ( From a666cfa4cdbb442e524d7f55ab049669b8d8035d Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 17 Jan 2025 09:40:07 +0100 Subject: [PATCH 08/12] feat: refs #7531 Added address_hasDelivery --- .../vn/functions/address_hasDelivery.sql | 9 ++++++++- .../vn/procedures/zone_getAddresses.sql | 18 ++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/functions/address_hasDelivery.sql b/db/routines/vn/functions/address_hasDelivery.sql index 719cc14f0..6b3962e1d 100644 --- a/db/routines/vn/functions/address_hasDelivery.sql +++ b/db/routines/vn/functions/address_hasDelivery.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`address_hasDelivery`( vSelf INT, - vAgencyModeFk INT, + vZoneFk INT, vLanded DATE ) RETURNS BOOL @@ -12,10 +12,16 @@ BEGIN * la dirección y fecha solicitada. * * @param vSelf Id de dirección de envío + * @param vZoneFk Id de zona * @param vLanded Fecha de entrega * @return true|false */ DECLARE vHasDelivery BOOL; + DECLARE vAgencyModeFk INT; + + SELECT agencyModeFk INTO vAgencyModeFk + FROM `zone` + WHERE id = vZoneFk; CALL zone_getAgency(vSelf, vLanded); @@ -23,6 +29,7 @@ BEGIN SELECT TRUE FROM tmp.zoneGetAgency WHERE agencyModeFk = vAgencyModeFk + AND zoneFk = vZoneFk ) INTO vHasDelivery; RETURN vHasDelivery; diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 90ad89bf3..eeee6c598 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( vSelf INT, - vShipped DATE, + vLanded DATE, vDepartmentFk INT ) BEGIN @@ -11,22 +11,16 @@ BEGIN * vender producto para esa zona. * * @param vSelf Id de zona - * @param vShipped Fecha de envio + * @param vLanded Fecha de entrega * @param vDepartmentFk Id de departamento * @return Un select */ - DECLARE vAgencyModeFk INT; - - SELECT agencyModeFk INTO vAgencyModeFk - FROM `zone` - WHERE id = vSelf; - CALL zone_getPostalCode(vSelf); WITH clientWithTicket AS ( - SELECT clientFk + SELECT DISTINCT clientFk FROM vn.ticket - WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped) + WHERE shipped BETWEEN vLanded - INTERVAL 1 DAY AND util.dayEnd(vLanded - INTERVAL 1 DAY) AND NOT isDeleted ) SELECT c.id, @@ -37,7 +31,7 @@ BEGIN u.name username, aai.invoiced, cnb.lastShipped, - cwt.clientFk + IF(cwt.clientFk, TRUE, FALSE) hasTicket FROM vn.client c JOIN vn.worker w ON w.id = c.salesPersonFk JOIN vn.workerDepartment wd ON wd.workerFk = w.id @@ -58,7 +52,7 @@ BEGIN AND ct.code = 'normal' AND bt.code <> 'worker' AND (d.id = vDepartmentFk OR vDepartmentFk IS NULL) - AND vn.address_hasDelivery(c.defaultAddressFk, vAgencyModeFk, vShipped) + AND vn.address_hasDelivery(c.defaultAddressFk, vSelf, vLanded) GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From e636d43f0492bf161b181fe2d4f147e163652387 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 17 Jan 2025 09:42:15 +0100 Subject: [PATCH 09/12] feat: refs #7531 Added address_hasDelivery --- db/routines/vn/functions/address_hasDelivery.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/functions/address_hasDelivery.sql b/db/routines/vn/functions/address_hasDelivery.sql index 6b3962e1d..c4f1644ce 100644 --- a/db/routines/vn/functions/address_hasDelivery.sql +++ b/db/routines/vn/functions/address_hasDelivery.sql @@ -9,7 +9,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`address_hasDelivery`( BEGIN /** * Retorna si hay reparto disponible para - * la dirección y fecha solicitada. + * la dirección, zona y fecha solicitada. * * @param vSelf Id de dirección de envío * @param vZoneFk Id de zona From 044a22bc3e209faf2ee04fd57de29f6d4776eed9 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 20 Jan 2025 07:13:04 +0100 Subject: [PATCH 10/12] feat: refs #7531 Deleted address_hasDelivery --- .../vn/functions/address_hasDelivery.sql | 39 ------------------- .../vn/procedures/zone_getAddresses.sql | 1 - 2 files changed, 40 deletions(-) delete mode 100644 db/routines/vn/functions/address_hasDelivery.sql diff --git a/db/routines/vn/functions/address_hasDelivery.sql b/db/routines/vn/functions/address_hasDelivery.sql deleted file mode 100644 index c4f1644ce..000000000 --- a/db/routines/vn/functions/address_hasDelivery.sql +++ /dev/null @@ -1,39 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`address_hasDelivery`( - vSelf INT, - vZoneFk INT, - vLanded DATE -) - RETURNS BOOL - DETERMINISTIC -BEGIN -/** - * Retorna si hay reparto disponible para - * la dirección, zona y fecha solicitada. - * - * @param vSelf Id de dirección de envío - * @param vZoneFk Id de zona - * @param vLanded Fecha de entrega - * @return true|false - */ - DECLARE vHasDelivery BOOL; - DECLARE vAgencyModeFk INT; - - SELECT agencyModeFk INTO vAgencyModeFk - FROM `zone` - WHERE id = vZoneFk; - - CALL zone_getAgency(vSelf, vLanded); - - SELECT EXISTS( - SELECT TRUE - FROM tmp.zoneGetAgency - WHERE agencyModeFk = vAgencyModeFk - AND zoneFk = vZoneFk - ) INTO vHasDelivery; - - RETURN vHasDelivery; - - DROP TEMPORARY TABLE tmp.zoneGetAgency; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index eeee6c598..45c82de07 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -52,7 +52,6 @@ BEGIN AND ct.code = 'normal' AND bt.code <> 'worker' AND (d.id = vDepartmentFk OR vDepartmentFk IS NULL) - AND vn.address_hasDelivery(c.defaultAddressFk, vSelf, vLanded) GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From e6abb1d759ac55f7b43b6d7452ee99c91a3ee4ab Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 20 Jan 2025 07:41:41 +0100 Subject: [PATCH 11/12] feat: refs #7531 Minor change --- db/routines/vn/procedures/zone_getAddresses.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 45c82de07..5a1380126 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -8,7 +8,7 @@ BEGIN /** * Devuelve un listado de todos los clientes activos * con consignatarios a los que se les puede - * vender producto para esa zona. + * entregar producto para esa zona. * * @param vSelf Id de zona * @param vLanded Fecha de entrega @@ -20,7 +20,7 @@ BEGIN WITH clientWithTicket AS ( SELECT DISTINCT clientFk FROM vn.ticket - WHERE shipped BETWEEN vLanded - INTERVAL 1 DAY AND util.dayEnd(vLanded - INTERVAL 1 DAY) + WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded) AND NOT isDeleted ) SELECT c.id, From 934507569e8963141036197a44d6e539254c5a95 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 20 Jan 2025 07:48:43 +0100 Subject: [PATCH 12/12] feat: refs #7531 Added comment --- db/routines/vn/procedures/zone_getAddresses.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 5a1380126..9946b0b73 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -12,7 +12,7 @@ BEGIN * * @param vSelf Id de zona * @param vLanded Fecha de entrega - * @param vDepartmentFk Id de departamento + * @param vDepartmentFk Id de departamento | NULL para mostrar todos * @return Un select */ CALL zone_getPostalCode(vSelf);