From c2ca9cfbe5ca58a699660d6dd437c4291a480f8e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 15 Jan 2025 12:26:16 +0100 Subject: [PATCH 1/8] 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 69b78b6bf1b2b36822a043e36b58f04b5f6667d2 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 16 Jan 2025 15:04:21 +0100 Subject: [PATCH 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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);