#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 notifications = await models.Notification.find({});
const totalAvailable = notifications.length - active.length; const totalAvailable = notifications.length - active.length;
expect(active.length).toEqual(2); expect(active.length).toEqual(3);
expect(available.length).toEqual(totalAvailable); expect(available.length).toEqual(totalAvailable);
}); });
}); });

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'), (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'), (4, 'supplier-pay-method-update', 'A supplier pay method has been updated'),
(5, 'modified-entry', 'An entry has been modified'), (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`) INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
VALUES VALUES
@ -2819,7 +2820,8 @@ INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
(3, 9), (3, 9),
(4, 1), (4, 1),
(5, 9), (5, 9),
(6, 9); (6, 9),
(7, 9);
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)
VALUES VALUES
@ -2836,8 +2838,8 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
(2, 1109), (2, 1109),
(1, 9), (1, 9),
(1, 3), (1, 3),
(6, 9); (6, 9),
(7, 9);
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
VALUES VALUES

View File

@ -1,4 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getCollisions`() CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getCollisions`()
BEGIN BEGIN
/** /**
@ -10,6 +11,7 @@ BEGIN
DECLARE vZoneFk INT; DECLARE vZoneFk INT;
DECLARE vIsDone INT DEFAULT FALSE; DECLARE vIsDone INT DEFAULT FALSE;
DECLARE vTableCollisions TEXT; DECLARE vTableCollisions TEXT;
DECLARE json_data JSON;
DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption; DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
@ -77,45 +79,26 @@ BEGIN
GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk
HAVING count(*) > 1; HAVING count(*) > 1;
SELECT '<table cellspacing="10"> -- Recojo los datos de la zona que ha dado conflicto
<tr> SELECT JSON_ARRAYAGG(
<th>C.Postal</th> JSON_OBJECT(
<th>Número de zona</th> 'zoneFk', zoneFk,
<th>Precio</th> 'zn', JSON_OBJECT('name', zn.name),
<th>Zona</th> 'z', JSON_OBJECT('name', z.name,'price', z.price),
<th>Almacén</th> 'w', JSON_OBJECT('name', w.name)
<th>Salix</th> )
</tr>' INTO vTableCollisions; ) FROM tmp.zoneNodes zn
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 zone z ON z.id = zn.zoneFk
JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk
JOIN warehouse w ON w.id = gc.warehouseFk) sub; 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 DROP TEMPORARY TABLE
geoCollision, geoCollision,

View File

@ -8,5 +8,6 @@ BEGIN
`changedModel` = 'zoneIncluded', `changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk, `changedModelId` = OLD.zoneFk,
`userFk` = account.myUser_getId(); `userFk` = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

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

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeUp
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
END$$ END$$
DELIMITER ; 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`)
VALUES
( 'zone-included','An email to notify zoneCollisions');
-- Change value if destionation user should be different
SET @DESTINATION_USER = "pepe";
SET @MaxId = LAST_INSERT_ID();
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 models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
describe('zone toggleIsIncluded()', () => { describe('zone toggleIsIncluded()', () => {
beforeAll(async() => { beforeAll(async() => {
const activeCtx = { const activeCtx = {
@ -58,7 +57,7 @@ describe('zone toggleIsIncluded()', () => {
await models.Zone.toggleIsIncluded(1, 20, false, options); 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}); expect(result).toEqual({count: 1});

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}
}
};