#5858 - zoneCollisions #1853

Merged
jsegarra merged 78 commits from 5858-zone_Collisions into dev 2024-03-15 12:36:38 +00:00
16 changed files with 142 additions and 67 deletions

View File

@ -7,7 +7,7 @@ describe('NotificationSubscription getList()', () => {
const notifications = await models.Notification.find({});
const totalAvailable = notifications.length - active.length;
expect(active.length).toEqual(2);
expect(active.length).toEqual(3);
expect(available.length).toEqual(totalAvailable);
});
});

View File

@ -70,7 +70,7 @@ UPDATE vn.supplier
UPDATE `vn`.`claimRatio` SET `claimAmount` = '10' WHERE (`clientFk` = '1101');
INSERT INTO `vn`.`agency` (`name`, `warehouseFk`, `isOwn`, `isAnyVolumeAllowed`)
INSERT INTO `vn`.`agency` (`name`, `warehouseFk`, `isOwn`, `isAnyVolumeAllowed`)
VALUES
('Agencia', '1', '1', '1'),
('Otra agencia ', '1', '0', '0');

View File

@ -2809,7 +2809,8 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`)
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured'),
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated'),
(5, 'modified-entry', 'An entry has been modified'),
(6, 'book-entry-deleted', 'accounting entries deleted');
(6, 'book-entry-deleted', 'accounting entries deleted'),
(7, 'zone-included','An email to notify zoneCollisions');
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
VALUES
@ -2819,7 +2820,8 @@ INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
(3, 9),
(4, 1),
(5, 9),
(6, 9);
(6, 9),
(7, 9);
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)
VALUES
@ -2836,8 +2838,8 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
(2, 1109),
(1, 9),
(1, 3),
(6, 9);
(6, 9),
(7, 9);
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
VALUES

View File

@ -1,8 +1,9 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getCollisions`()
BEGIN
/**
* Calcula si para un mismo codigo postal y dia
* Calcula si para un mismo codigo postal y dia
* hay mas de una zona configurada y manda correo
*
*/
@ -10,17 +11,18 @@ BEGIN
DECLARE vZoneFk INT;
DECLARE vIsDone INT DEFAULT FALSE;
DECLARE vTableCollisions TEXT;
DECLARE json_data JSON;
DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
DROP TEMPORARY TABLE IF EXISTS tmp.zone;
CREATE TEMPORARY TABLE tmp.zone
SELECT z.id
SELECT z.id
FROM zone z
JOIN agencyMode am ON am.id = z.agencyModeFk
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
WHERE dm.code IN ('AGENCY','DELIVERY');
WHERE dm.code IN ('AGENCY','DELIVERY');
CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE);
@ -35,7 +37,7 @@ BEGIN
PRIMARY KEY zoneFkk (zoneFk, geoFk),
INDEX(geoFk))
ENGINE = MyISAM;
OPEN cur1;
cur1Loop: LOOP
SET vIsDone = FALSE;
@ -43,82 +45,63 @@ BEGIN
IF vIsDone THEN
LEAVE cur1Loop;
END IF;
CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE);
myLoop: LOOP
myLoop: LOOP
SET vGeoFk = NULL;
SELECT geoFk INTO vGeoFk
SELECT geoFk INTO vGeoFk
FROM tmp.zoneNodes zn
WHERE NOT isChecked
LIMIT 1;
IF vGeoFk IS NULL THEN
LEAVE myLoop;
END IF;
CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE);
UPDATE tmp.zoneNodes
SET isChecked = TRUE
SET isChecked = TRUE
WHERE geoFk = vGeoFk;
END LOOP;
END LOOP;
CLOSE cur1;
DELETE FROM tmp.zoneNodes
DELETE FROM tmp.zoneNodes
WHERE sons > 0;
DROP TEMPORARY TABLE IF EXISTS geoCollision;
CREATE TEMPORARY TABLE geoCollision
SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk
FROM tmp.zoneNodes zn
JOIN zone z ON z.id = zn.zoneFk
JOIN zoneWarehouse zw ON z.id = zw.zoneFk
JOIN zoneWarehouse zw ON z.id = zw.zoneFk
GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk
HAVING count(*) > 1;
SELECT '<table cellspacing="10">
<tr>
<th>C.Postal</th>
<th>Número de zona</th>
<th>Precio</th>
<th>Zona</th>
<th>Almacén</th>
<th>Salix</th>
</tr>' INTO vTableCollisions;
INSERT INTO mail (receiver,replyTo,subject,body)
SELECT 'pepe@verdnatura.es' receiver,
'noreply@verdnatura.es' replyTo,
CONCAT('Colisiones en zonas ', util.VN_CURDATE()) subject,
CONCAT(vTableCollisions,
GROUP_CONCAT(sub.td SEPARATOR ''),
'</table>') body
FROM(SELECT
CONCAT('<tr>
<td>', zn.name, '</td>
<td>', zoneFk,'</td>
<td>', z.price,'</td>
<td>', z.name,'</td>
<td>', w.name, '</td>
<td>', CONCAT('<a href="https://salix.verdnatura.es/#!/zone/',
zoneFk,
'/location?q=%7B%22search%22:%22',
zn.name,
'%22%7D">'
'https://salix.verdnatura.es/#!/zone/',
zoneFk,
'/location?q=%7B%22search%22:%22',
zn.name,
'%22%7D</a>'),'</td>
</tr>') td
FROM tmp.zoneNodes zn
JOIN zone z ON z.id = zn.zoneFk
JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk
JOIN warehouse w ON w.id = gc.warehouseFk) sub;
DROP TEMPORARY TABLE
geoCollision,
-- Recojo los datos de la zona que ha dado conflicto
SELECT JSON_ARRAYAGG(
JSON_OBJECT(
'zoneFk', zoneFk,
'zn', JSON_OBJECT('name', zn.name),
'z', JSON_OBJECT('name', z.name,'price', z.price),
'w', JSON_OBJECT('name', w.name)
)
) FROM tmp.zoneNodes zn
JOIN zone z ON z.id = zn.zoneFk
JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk
JOIN warehouse w ON w.id = gc.warehouseFk
INTO json_data;
-- Creo un registro de la notificacion 'zone-included' para reportar via email
SELECT util.notification_send(
'zone-included',
JSON_OBJECT('zoneCollisions',json_data),
account.myUser_getId()
);
DROP TEMPORARY TABLE
geoCollision,
tmp.zone,
tmp.zoneNodes;
END$$

View File

@ -8,5 +8,6 @@ BEGIN
`changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk,
`userFk` = account.myUser_getId();
END$$
jsegarra marked this conversation as resolved Outdated

no ponemos dos saltos de linea nunca

no ponemos dos saltos de linea nunca
DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeIn
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
END$$
DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeUp
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
END$$
DELIMITER ;

View File

@ -0,0 +1 @@
ALTER TABLE util.notification MODIFY COLUMN id int(11) auto_increment NOT NULL;

View File

@ -0,0 +1,15 @@
INSERT IGNORE INTO util.notification ( `name`,`description`)
jgallego marked this conversation as resolved Outdated

dile a chatgpt que te cambie esta linea y que quieres usar el last_insert_id de forma que primero insertas y luego ya usas el id otorgado.

dile a chatgpt que te cambie esta linea y que quieres usar el last_insert_id de forma que primero insertas y luego ya usas el id otorgado.

No hace falta ir tan lejos...tonto de mi por no haber revisado el resto del proyecto.

Basta con usar LAST_INSERT_ID()

No hace falta ir tan lejos...tonto de mi por no haber revisado el resto del proyecto. Basta con usar LAST_INSERT_ID()

Revisamos porque esta tabla empieza por 0.
Devuelve 0 LAST_INSERT_ID();

Revisamos porque esta tabla empieza por 0. Devuelve 0 LAST_INSERT_ID();

Solved, he modificado la propiedad auto_increment de la columna id de util.notification

Solved, he modificado la propiedad auto_increment de la columna id de util.notification
VALUES
( 'zone-included','An email to notify zoneCollisions');
jgallego marked this conversation as resolved Outdated

pongo esto para descartar y que cuando tengas el nuevo pr me puedas pedir revision de nuevo

pongo esto para descartar y que cuando tengas el nuevo pr me puedas pedir revision de nuevo

Corregido: 4994a836c7

Corregido: 4994a836c7119a6c894e3600a78ba71438ecb410
-- Change value if destionation user should be different
SET @DESTINATION_USER = "pepe";
jgallego marked this conversation as resolved Outdated

porque se la añades al usuario system? deberia de ser el que solicita la tarea no?

porque se la añades al usuario system? deberia de ser el que solicita la tarea no?

Es un evento el que dispara el procedure de zone_getCollisions, por tanto no hay usuario que haga la operación manual, si no que es el systema.

Me basé en los datos de producción util.notification where id=6

Si las especificaciones no son las correctas, hay algún sitio donde pueda tomar la referencia?

Es un evento el que dispara el procedure de zone_getCollisions, por tanto no hay usuario que haga la operación manual, si no que es el systema. Me basé en los datos de producción util.notification where id=6 Si las especificaciones no son las correctas, hay algún sitio donde pueda tomar la referencia?

@jgallego Tras juntarme con Pablo, he cambiado el usuario de systema a root, porque por lo que me ha comentado, si el procedimiento se ejecuta en la BD es root y en salix es system

@jgallego Tras juntarme con Pablo, he cambiado el usuario de systema a root, porque por lo que me ha comentado, si el procedimiento se ejecuta en la BD es root y en salix es system
SET @MaxId = LAST_INSERT_ID();
jgallego marked this conversation as resolved Outdated

que es este 100? el usuario 100 en prod es icef...no me cuadra.
Busca la forma de usar codes para no poner numeros.

que es este 100? el usuario 100 en prod es icef...no me cuadra. Busca la forma de usar codes para no poner numeros.

INSERT IGNORE INTO util.notificationSubscription (notificationFk,userFk)
VALUES(
@MaxId, (SELECT id from account.user where name = "system"));

La solución estaba mas abajo

INSERT IGNORE INTO util.notificationSubscription (notificationFk,userFk) VALUES( @MaxId, (SELECT id from `account`.`user` where name = "system")); La solución estaba mas abajo
INSERT IGNORE INTO util.notificationSubscription (notificationFk,userFk)
VALUES(
@MaxId, (SELECT id from `account`.`user` where name = @DESTINATION_USER));
INSERT IGNORE INTO util.notificationAcl (notificationFk,roleFk)
SELECT @MaxId, (SELECT role from `account`.`user` where name = @DESTINATION_USER) FROM util.notification WHERE name= "zone-included";

View File

@ -1,6 +1,5 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('zone toggleIsIncluded()', () => {
beforeAll(async() => {
const activeCtx = {
@ -58,7 +57,7 @@ describe('zone toggleIsIncluded()', () => {
await models.Zone.toggleIsIncluded(1, 20, false, options);
let result = await models.Zone.toggleIsIncluded(1, 20, undefined, options);
const result = await models.Zone.toggleIsIncluded(1, 20, undefined, options);
expect(result).toEqual({count: 1});

View File

@ -3,10 +3,10 @@
"dataSource": "vn"
},
"AgencyMode": {
"dataSource": "vn"
"dataSource": "vn"
},
"DeliveryMethod": {
"dataSource": "vn"
"dataSource": "vn"
},
"Zone": {
"dataSource": "vn"

View File

@ -0,0 +1,11 @@
const Stylesheet = require(`vn-print/core/stylesheet`);
const path = require('path');
const vnPrintPath = path.resolve('print');
module.exports = new Stylesheet([
`${vnPrintPath}/common/css/spacing.css`,
`${vnPrintPath}/common/css/misc.css`,
`${vnPrintPath}/common/css/layout.css`,
`${vnPrintPath}/common/css/email.css`])
.mergeStyles();

View File

@ -0,0 +1,7 @@
subject: Colisiones en zonas
title: "La zona {0} y localización {1} ha sido registrada en más de un sitio"
postalCode: C. Postal
zoneFk: Número de zona
price: Precio
zone: Zona
warehouse: Almacén

View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html v-bind:lang="$i18n.locale">
<head>
<meta name="viewport" content="width=device-width" />
<meta name="format-detection" content="telephone=no" />
</head>
<body>
<table class="grid column-oriented">
<thead>
<tr>
<th>{{ $t('postalCode') }}</th>
<th>{{ $t('zoneFk') }}</th>
<th>{{ $t('price') }}</th>
<th>{{ $t('zone') }}</th>
<th>{{ $t('warehouse') }}</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="zone in zoneCollisions">
<td>{{ zone.zn.name }}</td>
<td>{{ zone.zoneFk }}</td>
<td>{{ zone.z.price }}</td>
<td>{{ zone.z.name }}</td>
<td>{{ zone.w.name }}</td>
<td>
<a v-bind:href="'https://salix.verdnatura.es/#!/zone/'+
zone.zoneFk+
'/location?q=%7B%22search%22:%22'+
zone.zn.name+
'%22%7D'">
https://salix.verdnatura.es/#!/zone/
{{zone.zoneFk}}
/location?q=%7B%22search%22:%22
{{zone.zn.name}}
%22%7D</a></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,12 @@
const Component = require(`vn-print/core/component`);
const emailHeader = new Component('email-header');
module.exports = {
name: 'zone-included',
components: {
'email-header': emailHeader.build(),
},
props: {
zoneCollisions: {type: Array, required: true}
}
};