diff --git a/back/methods/notification/specs/getList.spec.js b/back/methods/notification/specs/getList.spec.js
index 52ac497a5..6c60d3505 100644
--- a/back/methods/notification/specs/getList.spec.js
+++ b/back/methods/notification/specs/getList.spec.js
@@ -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);
});
});
diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql
index bda625a96..d7f3b22e8 100644
--- a/db/dump/fixtures.after.sql
+++ b/db/dump/fixtures.after.sql
@@ -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');
diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql
index 3ffd78695..91be977cb 100644
--- a/db/dump/fixtures.before.sql
+++ b/db/dump/fixtures.before.sql
@@ -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
diff --git a/db/routines/vn/procedures/zone_getCollisions.sql b/db/routines/vn/procedures/zone_getCollisions.sql
index f6779e1b7..023b9aac2 100644
--- a/db/routines/vn/procedures/zone_getCollisions.sql
+++ b/db/routines/vn/procedures/zone_getCollisions.sql
@@ -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 '
-
- C.Postal |
- Número de zona |
- Precio |
- Zona |
- Almacén |
- Salix |
-
' 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 ''),
- '
') body
- FROM(SELECT
- CONCAT('
- ', zn.name, ' |
- ', zoneFk,' |
- ', z.price,' |
- ', z.name,' |
- ', w.name, ' |
- ', CONCAT(''
- 'https://salix.verdnatura.es/#!/zone/',
- zoneFk,
- '/location?q=%7B%22search%22:%22',
- zn.name,
- '%22%7D'),' |
-
') 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$$
diff --git a/db/routines/vn/triggers/zoneIncluded_afterDelete.sql b/db/routines/vn/triggers/zoneIncluded_afterDelete.sql
index 6d184bb12..18332bb55 100644
--- a/db/routines/vn/triggers/zoneIncluded_afterDelete.sql
+++ b/db/routines/vn/triggers/zoneIncluded_afterDelete.sql
@@ -8,5 +8,6 @@ BEGIN
`changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk,
`userFk` = account.myUser_getId();
+
END$$
DELIMITER ;
diff --git a/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql b/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql
index 5eff33efa..18895c9a5 100644
--- a/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql
+++ b/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql
@@ -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 ;
diff --git a/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql b/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql
index 445f37699..e3f0a27e2 100644
--- a/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql
+++ b/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql
@@ -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 ;
diff --git a/db/versions/10881-greenHydrangea/00-alterTableNotification.sql b/db/versions/10881-greenHydrangea/00-alterTableNotification.sql
new file mode 100644
index 000000000..068d77839
--- /dev/null
+++ b/db/versions/10881-greenHydrangea/00-alterTableNotification.sql
@@ -0,0 +1 @@
+ALTER TABLE util.notification MODIFY COLUMN id int(11) auto_increment NOT NULL;
diff --git a/db/versions/10881-greenHydrangea/01-notification.vn.sql b/db/versions/10881-greenHydrangea/01-notification.vn.sql
new file mode 100644
index 000000000..ab5480548
--- /dev/null
+++ b/db/versions/10881-greenHydrangea/01-notification.vn.sql
@@ -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";
diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js
index 746a2d0bd..2da176330 100644
--- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js
+++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js
@@ -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});
diff --git a/modules/zone/back/model-config.json b/modules/zone/back/model-config.json
index 261a89902..3bbbe0d1b 100644
--- a/modules/zone/back/model-config.json
+++ b/modules/zone/back/model-config.json
@@ -3,10 +3,10 @@
"dataSource": "vn"
},
"AgencyMode": {
- "dataSource": "vn"
+ "dataSource": "vn"
},
"DeliveryMethod": {
- "dataSource": "vn"
+ "dataSource": "vn"
},
"Zone": {
"dataSource": "vn"
diff --git a/print/templates/email/zone-included/assets/css/import.js b/print/templates/email/zone-included/assets/css/import.js
new file mode 100644
index 000000000..4b4bb7086
--- /dev/null
+++ b/print/templates/email/zone-included/assets/css/import.js
@@ -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();
diff --git a/print/templates/email/zone-included/locale/es.yml b/print/templates/email/zone-included/locale/es.yml
new file mode 100644
index 000000000..cb35a55cc
--- /dev/null
+++ b/print/templates/email/zone-included/locale/es.yml
@@ -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
diff --git a/print/templates/email/zone-included/sql/zoneIncluded.sql b/print/templates/email/zone-included/sql/zoneIncluded.sql
new file mode 100644
index 000000000..e69de29bb
diff --git a/print/templates/email/zone-included/zone-included.html b/print/templates/email/zone-included/zone-included.html
new file mode 100644
index 000000000..78915faad
--- /dev/null
+++ b/print/templates/email/zone-included/zone-included.html
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/print/templates/email/zone-included/zone-included.js b/print/templates/email/zone-included/zone-included.js
new file mode 100755
index 000000000..4de4777f3
--- /dev/null
+++ b/print/templates/email/zone-included/zone-included.js
@@ -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}
+ }
+};