From 05b0a5342fb80ebc9c23050b6de258867505e73c Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 11 May 2022 14:53:52 +0200 Subject: [PATCH 01/68] feat(zone.events): new dialog when choose 'exclude' --- modules/zone/front/events/index.html | 69 +++++++++++++++++++++++++ modules/zone/front/events/index.js | 61 +++++++++++++++++++--- modules/zone/front/events/locale/es.yml | 3 ++ 3 files changed, 127 insertions(+), 6 deletions(-) diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index e71a1ae26..7bcbba256 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -198,3 +198,72 @@ message="This item will be deleted" question="Are you sure you want to continue?"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index 0df16a42a..c5843e362 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -5,7 +5,7 @@ class Controller extends Section { constructor($element, $, vnWeekDays) { super($element, $); this.vnWeekDays = vnWeekDays; - this.editMode = 'include'; + this.editMode = 'exclude'; } $onInit() { @@ -52,14 +52,23 @@ class Controller extends Section { if (this.editMode == 'include') { if (events.length) this.edit(events[0]); - else + else { this.create(type, days, weekday); + console.log(type); + } } else { - if (exclusions.length) - this.exclusionDelete(exclusions); - else - this.exclusionCreate(days); + console.log(type); + this.selected = { + type: 'all', + dated: days[0] + }; + this.$.excludeDialog.show(); } + + // if (exclusions.length) + // this.exclusionDelete(exclusions); + // else + // this.exclusionCreate(days); } onEditClick(row, event) { @@ -170,6 +179,46 @@ class Controller extends Section { this.$q.all(reqs) .then(() => this.refresh()); } + + onSearch(params) { + this.$.model.applyFilter({}, params).then(() => { + const data = this.$.model.data; + this.$.treeview.data = data; + }); + } + + onFetch(item) { + const params = item ? {parentId: item.id} : null; + return this.$.model.applyFilter({}, params) + .then(() => this.$.model.data); + } + + onSort(a, b) { + if (b.selected !== a.selected) { + if (a.selected == null) + return 1; + if (b.selected == null) + return -1; + return b.selected - a.selected; + } + + return a.name.localeCompare(b.name); + } + + exprBuilder(param, value) { + switch (param) { + case 'search': + return {name: {like: `%${value}%`}}; + } + } + + onSelection2(value, item) { + if (value == null) + value = undefined; + const params = {geoId: item.id, isIncluded: value}; + const path = `zones/${this.zone.id}/toggleIsIncluded`; + this.$http.post(path, params); + } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; diff --git a/modules/zone/front/events/locale/es.yml b/modules/zone/front/events/locale/es.yml index eb581a719..59b05e696 100644 --- a/modules/zone/front/events/locale/es.yml +++ b/modules/zone/front/events/locale/es.yml @@ -4,3 +4,6 @@ Exclude: Excluir Events: Eventos Add event: Añadir evento Edit event: Editar evento +All: Todo +Specific locations: Localizaciones concretas +Locations where it is not distributed: Localizaciones en las que no se reparte \ No newline at end of file From b96d9ea4c2bb3ed8d194bbc1d2f96df182a3e22a Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 May 2022 13:53:13 +0200 Subject: [PATCH 02/68] feat(zone.events): add dialog --- .../00-aclZoneExclusionGeos.sql | 2 + .../10460-mothersDay/00-zoneHoliday.sql | 398 ++++++++++++++++++ modules/zone/back/model-config.json | 3 + .../zone/back/models/zone-exclusion-geo.json | 19 + modules/zone/front/events/index.html | 10 +- modules/zone/front/events/index.js | 60 ++- 6 files changed, 465 insertions(+), 27 deletions(-) create mode 100644 db/changes/10460-mothersDay/00-aclZoneExclusionGeos.sql create mode 100644 db/changes/10460-mothersDay/00-zoneHoliday.sql create mode 100644 modules/zone/back/models/zone-exclusion-geo.json diff --git a/db/changes/10460-mothersDay/00-aclZoneExclusionGeos.sql b/db/changes/10460-mothersDay/00-aclZoneExclusionGeos.sql new file mode 100644 index 000000000..3a157947d --- /dev/null +++ b/db/changes/10460-mothersDay/00-aclZoneExclusionGeos.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES('ZoneExclusionGeo', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10460-mothersDay/00-zoneHoliday.sql b/db/changes/10460-mothersDay/00-zoneHoliday.sql new file mode 100644 index 000000000..cacf5ba84 --- /dev/null +++ b/db/changes/10460-mothersDay/00-zoneHoliday.sql @@ -0,0 +1,398 @@ +CREATE TABLE `vn`.`zoneExclusionGeo` ( + `zoneExclusionFk` int(11) NOT NULL, + `geoFk` int(11) NOT NULL, + PRIMARY KEY (`zoneExclusionFk`,`geoFk`), + KEY `zoneExclusionGeo2_FK_1` (`geoFk`), + CONSTRAINT `zoneExclusionGeo2_FK` FOREIGN KEY (`zoneExclusionFk`) REFERENCES `zoneExclusion` (`id`) ON UPDATE CASCADE, + CONSTRAINT `zoneExclusionGeo2_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + + +DROP PROCEDURE IF EXISTS `vn`.`zone_excludeFromGeo`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_excludeFromGeo`(vZoneGeo INT) +BEGIN +/** + * Excluye zonas a partir un geoFk. + * + * @table tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, landed, shipped) The computed options + * @param vZoneGeo The zone geo + * @return tmp.zoneOption The computed options + */ + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vZoneGeo + WHERE zg2.`path` LIKE CONCAT(zg1.`path`,'%'); +END$$ +DELIMITER ; + + +DROP PROCEDURE IF EXISTS `vn`.`zone_getEvents`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getEvents`( + vGeoFk INT, + vAgencyModeFk INT) +BEGIN +/** + * Returns available events for the passed province/postcode and agency. + * + * @param vGeoFk The geo id + * @param vAgencyModeFk The agency mode id + */ + DECLARE vDeliveryMethodFk VARCHAR(255); + + DROP TEMPORARY TABLE IF EXISTS tZone; + CREATE TEMPORARY TABLE tZone + (id INT PRIMARY KEY) + ENGINE = MEMORY; + + SELECT dm.`code` INTO vDeliveryMethodFk + FROM agencyMode am + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE am.id = vAgencyModeFk; + + IF vDeliveryMethodFk = 'PICKUP' THEN + INSERT INTO tZone + SELECT id + FROM zone + WHERE agencyModeFk = vAgencyModeFk; + ELSE + CALL zone_getFromGeo(vGeoFk); + IF vAgencyModeFk IS NOT NULL THEN + INSERT INTO tZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + WHERE z.agencyModeFk = vAgencyModeFk; + ELSE + INSERT INTO tZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.`code` IN ('AGENCY', 'DELIVERY'); + END IF; + DROP TEMPORARY TABLE tmp.zone; + END IF; + + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + FROM tZone t + JOIN zoneEvent e ON e.zoneFk = t.id; + SELECT e.zoneFk, e.dated + FROM tZone t + JOIN zoneExclusion e ON e.zoneFk = t.id + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + + DROP TEMPORARY TABLE tZone; +END$$ +DELIMITER ; + +DROP PROCEDURE IF EXISTS `vn`.`zone_getLanded`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Devuelve una tabla temporal con el dia de recepcion para vShipped. + * Excluye las que tengan cajas preparadas + * + * @param vShipped Fecha de preparacion de mercancia + * @param vAddressFk Id de consignatario, %NULL para recogida + * @param vAgencyModeFk Id agencia + * @param vWarehouseFk vWarehouseFk + * @table tmp.zoneGetLanded Datos de recepción + */ + DECLARE vZoneGeo INT; + SELECT address_getGeo(vAddressFk) INTO vZoneGeo; + CALL vn.zone_getFromGeo(vZoneGeo); + CALL vn.zone_getOptionsForShipment(vShipped, vShowExpiredZones); + CALL vn.zone_excludeFromGeo(vZoneGeo); + CALL vn.zone_getClosed(); + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; + CREATE TEMPORARY TABLE tmp.zoneGetLanded + ENGINE = MEMORY + SELECT vWarehouseFk warehouseFk, + TIMESTAMPADD(DAY,zo.travelingDays, vShipped) landed, + zo.zoneFk + FROM tmp.zoneOption zo + JOIN vn.`zone` z ON z.id = zo.zoneFk + JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk + AND cz.zoneFk = zw.zoneFk + AND zo.shipped = CURDATE() + WHERE z.agencyModeFk = vAgencyModeFk + AND zw.warehouseFk = vWarehouseFk + AND (ISNULL(cz.zoneFk) OR vShowExpiredZones); + DROP TEMPORARY TABLE + tmp.`zone`, + tmp.zoneOption, + tmp.closedZones; +END$$ +DELIMITER ; + +DROP PROCEDURE IF EXISTS `vn`.`zone_getOptionsForLanding`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getOptionsForLanding`(vLanded DATE, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Gets computed options for the passed zones and delivery date. + * + * @table tmp.zone(id) The zones ids + * @param vLanded The delivery date + * @return tmp.zoneOption The computed options + */ + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + CREATE TEMPORARY TABLE tmp.zoneOption + ENGINE = MEMORY + SELECT + zoneFk, + `hour`, + travelingDays, + price, + bonus, + vLanded landed, + TIMESTAMPADD(DAY, -travelingDays, vLanded) shipped + FROM ( + SELECT t.id zoneFk, + TIME(IFNULL(e.`hour`, z.`hour`)) `hour`, + IFNULL(e.travelingDays, z.travelingDays) travelingDays, + IFNULL(e.price, z.price) price, + IFNULL(e.bonus, z.bonus) bonus + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN zoneEvent e ON e.zoneFk = t.id + WHERE ( + e.`type` = 'day' + AND e.dated = vLanded + ) OR ( + e.`type` != 'day' + AND e.weekDays & (1 << WEEKDAY(vLanded)) + AND (e.`started` IS NULL OR vLanded >= e.`started`) + AND (e.`ended` IS NULL OR vLanded <= e.`ended`) + ) + ORDER BY + zoneFk, + CASE + WHEN e.`type` = 'day' + THEN 1 + WHEN e.`type` = 'range' + THEN 2 + ELSE 3 + END + ) t + GROUP BY zoneFk; + + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + + IF NOT vShowExpiredZones THEN + DELETE FROM tmp.zoneOption + WHERE shipped < CURDATE() + OR (shipped = CURDATE() AND CURTIME() > `hour`); + END IF; +END$$ +DELIMITER ; + + +DROP PROCEDURE IF EXISTS `vn`.`zone_getOptionsForShipment`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getOptionsForShipment`(vShipped DATE, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Gets computed options for the passed zones and shipping date. + * + * @table tmp.zones(id) The zones ids + * @param vShipped The shipping date + * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options + */ + DECLARE vHour TIME DEFAULT TIME(NOW()); + + DROP TEMPORARY TABLE IF EXISTS tLandings; + CREATE TEMPORARY TABLE tLandings + (INDEX (eventFk)) + ENGINE = MEMORY + SELECT e.id eventFk, + @travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays, + TIMESTAMPADD(DAY, @travelingDays, vShipped) landed + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN zoneEvent e ON e.zoneFk = t.id; + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + CREATE TEMPORARY TABLE tmp.zoneOption + ENGINE = MEMORY + SELECT * + FROM ( + SELECT t.id zoneFk, + TIME(IFNULL(e.`hour`, z.`hour`)) `hour`, + l.travelingDays, + IFNULL(e.price, z.price) price, + IFNULL(e.bonus, z.bonus) bonus, + l.landed, + vShipped shipped + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN zoneEvent e ON e.zoneFk = t.id + JOIN tLandings l ON l.eventFk = e.id + WHERE ( + e.`type` = 'day' + AND e.`dated` = l.landed + ) OR ( + e.`type` != 'day' + AND e.weekDays & (1 << WEEKDAY(l.landed)) + AND (e.`started` IS NULL OR l.landed >= e.`started`) + AND (e.`ended` IS NULL OR l.landed <= e.`ended`) + ) + ORDER BY + zoneFk, + CASE + WHEN e.`type` = 'day' + THEN 1 + WHEN e.`type` = 'range' + THEN 2 + ELSE 3 + END + ) t + GROUP BY zoneFk; + DROP TEMPORARY TABLE tLandings; + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + IF NOT vShowExpiredZones THEN + DELETE FROM tmp.zoneOption + WHERE vShipped < CURDATE() + OR (vShipped = CURDATE() AND CURTIME() > `hour`); + END IF; +END$$ +DELIMITER ; + + +DROP PROCEDURE IF EXISTS `vn`.`zone_getShipped`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getShipped`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Devuelve la mínima fecha de envío para cada warehouse + * Excluye aquellas zonas que ya tienen cajas preparadas en ese almacén + * + * @param vLanded La fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id de la agencia + * @return tmp.zoneGetShipped + */ + DECLARE vZoneGeo INT; + SELECT address_getGeo(vAddressFk) INTO vZoneGeo; + + CALL vn.zone_getFromGeo(vZoneGeo); + CALL vn.zone_getOptionsForLanding(vLanded, vShowExpiredZones); + CALL vn.zone_excludeFromGeo(vZoneGeo); + CALL vn.zone_getClosed(); + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; + CREATE TEMPORARY TABLE tmp.zoneGetShipped + ENGINE = MEMORY + SELECT * FROM ( + SELECT zo.zoneFk, + zo.shipped, + zo.`hour`, + zw.warehouseFk, + z.agencyModeFk, + zo.price, + zo.bonus + FROM tmp.zoneOption zo + JOIN vn.zoneWarehouse zw ON zw.zoneFk = zo.zoneFk + JOIN vn.`zone` z ON z.id = zo.zoneFk + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk + AND cz.zoneFk = zw.zoneFk + AND zo.shipped = CURDATE() + WHERE z.agencyModeFk = vAgencyModeFk + AND (ISNULL(cz.zoneFk) OR vShowExpiredZones) + ORDER BY shipped) t + GROUP BY warehouseFk; + DROP TEMPORARY TABLE + tmp.`zone`, + tmp.zoneOption, + tmp.closedZones; +END$$ +DELIMITER ; + + +DROP PROCEDURE IF EXISTS `vn`.`zone_upcomingDeliveries`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_upcomingDeliveries`() +BEGIN + DECLARE vForwardDays INT; + + SELECT forwardDays INTO vForwardDays FROM zoneConfig; + CALL util.time_createTable(CURDATE(), DATE_ADD(CURDATE(), INTERVAL vForwardDays DAY)); + DROP TEMPORARY TABLE IF EXISTS tLandings; + CREATE TEMPORARY TABLE tLandings + (INDEX (eventFk)) + ENGINE = MEMORY + SELECT e.id eventFk, + @travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays, + TIMESTAMPADD(DAY, @travelingDays, ti.dated) landed, + ti.dated shipped + FROM zone z + JOIN zoneEvent e ON e.zoneFk = z.id + JOIN tmp.time ti ON ti.dated BETWEEN curdate() AND TIMESTAMPADD(DAY, vForwardDays, curdate()); + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + CREATE TEMPORARY TABLE tmp.zoneOption + ENGINE = MEMORY + SELECT * + FROM ( + SELECT z.id zoneFk, + TIME(IFNULL(e.`hour`, z.`hour`)) `hour`, + l.travelingDays, + IFNULL(e.price, z.price) price, + IFNULL(e.bonus, z.bonus) bonus, + l.landed, + l.shipped + FROM zone z + JOIN zoneEvent e ON e.zoneFk = z.id + JOIN tLandings l ON l.eventFk = e.id + WHERE ( + e.`type` = 'day' + AND e.`dated` = l.landed + ) OR ( + e.`type` != 'day' + AND e.weekDays & (1 << WEEKDAY(l.landed)) + AND (e.`started` IS NULL OR l.landed >= e.`started`) + AND (e.`ended` IS NULL OR l.landed <= e.`ended`) + ) + ORDER BY + zoneFk, + CASE + WHEN e.`type` = 'day' + THEN 1 + WHEN e.`type` = 'range' + THEN 2 + ELSE 3 + END + ) t + GROUP BY zoneFk, landed; + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + + SELECT MAX(zo.`hour`) `hour`, zg.`name`, zo.shipped, zo.zoneFk + FROM tmp.zoneOption zo + JOIN `zone` z ON z.id = zo.zoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN zoneIncluded zi ON zi.zoneFk = z.id + JOIN zoneGeo zg ON zg.id = zi.geoFk AND zg.type = 'province' + WHERE dm.code = 'DELIVERY' + GROUP BY shipped, zg.`name` + ORDER BY shipped, zg.`name`; + + DROP TEMPORARY TABLE tmp.time, tLandings; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/modules/zone/back/model-config.json b/modules/zone/back/model-config.json index ee555f3f4..261a89902 100644 --- a/modules/zone/back/model-config.json +++ b/modules/zone/back/model-config.json @@ -23,6 +23,9 @@ "ZoneExclusion": { "dataSource": "vn" }, + "ZoneExclusionGeo": { + "dataSource": "vn" + }, "ZoneGeo": { "dataSource": "vn" }, diff --git a/modules/zone/back/models/zone-exclusion-geo.json b/modules/zone/back/models/zone-exclusion-geo.json new file mode 100644 index 000000000..a578a07d0 --- /dev/null +++ b/modules/zone/back/models/zone-exclusion-geo.json @@ -0,0 +1,19 @@ +{ + "name": "ZoneExclusionGeo", + "base": "VnModel", + "options": { + "mysql": { + "table": "zoneExclusionGeo" + } + }, + "properties": { + "zoneExclusionFk": { + "type": "number", + "required": true + }, + "geoFk": { + "type": "date", + "required": true + } + } +} \ No newline at end of file diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index 7bcbba256..3a3eaf1b3 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -98,7 +98,7 @@ fixed-bottom-right> @@ -201,7 +201,7 @@ @@ -233,17 +235,17 @@ - + diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index c5843e362..ef0fad9e9 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -6,6 +6,8 @@ class Controller extends Section { super($element, $); this.vnWeekDays = vnWeekDays; this.editMode = 'exclude'; + this.exclusions; + this.days; } $onInit() { @@ -52,23 +54,18 @@ class Controller extends Section { if (this.editMode == 'include') { if (events.length) this.edit(events[0]); - else { + else this.create(type, days, weekday); - console.log(type); - } } else { - console.log(type); this.selected = { type: 'all', dated: days[0] }; + this.exclusions = exclusions; + this.days = days; + this.$.excludeDialog.show(); } - - // if (exclusions.length) - // this.exclusionDelete(exclusions); - // else - // this.exclusionCreate(days); } onEditClick(row, event) { @@ -80,7 +77,7 @@ class Controller extends Section { this.isNew = false; this.selected = angular.copy(row); this.selected.wdays = this.vnWeekDays.fromSet(row.weekDays); - this.$.dialog.show(); + this.$.includeDialog.show(); } create(type, days, weekday) { @@ -101,7 +98,7 @@ class Controller extends Section { }; } - this.$.dialog.show(); + this.$.includeDialog.show(); } onIncludeResponse(response) { @@ -141,6 +138,29 @@ class Controller extends Section { } } + onExcludeResponse(response) { + switch (response) { + case 'accept': { + let selected = this.selected; + let type = selected.type; + if (type == 'all') + this.exclusionCreate(this.days); + else { + const params = [{ + zoneExclusionFk: 1, + geoFk: 1 + }]; + this.$http.post(`ZoneExclusionGeos`, params).then(() => this.refresh()); + } + // inserta en zoneExclusionGeo el zoneGeo seleccionado + + return 1; + } + case 'delete': + return this.exclusionDelete(this.exclusions); + } + } + onDeleteClick(id, event) { if (event.defaultPrevented) return; event.preventDefault(); @@ -181,10 +201,12 @@ class Controller extends Section { } onSearch(params) { - this.$.model.applyFilter({}, params).then(() => { - const data = this.$.model.data; - this.$.treeview.data = data; - }); + if (this.selected.type == 'specificLocations') { + this.$.model.applyFilter({}, params).then(() => { + const data = this.$.model.data; + this.$.treeview.data = data; + }); + } } onFetch(item) { @@ -211,14 +233,6 @@ class Controller extends Section { return {name: {like: `%${value}%`}}; } } - - onSelection2(value, item) { - if (value == null) - value = undefined; - const params = {geoId: item.id, isIncluded: value}; - const path = `zones/${this.zone.id}/toggleIsIncluded`; - this.$http.post(path, params); - } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; From 06e9a22f405a824eca4a73e4bca1477f58f3b31d Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 May 2022 15:02:07 +0200 Subject: [PATCH 03/68] added search --- modules/zone/front/events/index.html | 49 +++++++++++++------------- modules/zone/front/events/index.js | 49 ++++++++++++++++++++++++-- modules/zone/front/location/index.js | 2 ++ modules/zone/front/location/style.scss | 30 ++++++++-------- modules/zone/front/routes.json | 7 ++-- 5 files changed, 93 insertions(+), 44 deletions(-) diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index 3a3eaf1b3..67657e665 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -198,7 +198,6 @@ message="This item will be deleted" question="Are you sure you want to continue?"> - - + @@ -228,27 +227,27 @@ url="Zones/{{$ctrl.$params.id}}/getLeaves" filter="$ctrl.filter"> - - - - - - - - - - +
+ + +
+ + + + +
+
diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index ef0fad9e9..d7d54498c 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -22,6 +22,17 @@ class Controller extends Section { return `Zones/${this.$params.id}/exclusions`; } + get checked() { + const geos = this.$.model.data || []; + const checkedLines = []; + for (let geo of geos) { + if (geo.checked) + checkedLines.push(geo); + } + + return checkedLines; + } + refresh() { this.$.data = null; this.$.$applyAsync(() => { @@ -200,8 +211,25 @@ class Controller extends Section { .then(() => this.refresh()); } - onSearch(params) { - if (this.selected.type == 'specificLocations') { + set excludeSearch(value) { + this._excludeSearch = value; + if (!value) this.onSearch(); + } + + get excludeSearch() { + return this._excludeSearch; + } + + onKeyDown(event) { + if (event.key == 'Enter') { + event.preventDefault(); + this.onSearch(); + } + } + + onSearch() { + const params = {search: this._excludeSearch}; + if (this.excludeType == 'specificLocations') { this.$.model.applyFilter({}, params).then(() => { const data = this.$.model.data; this.$.treeview.data = data; @@ -233,10 +261,25 @@ class Controller extends Section { return {name: {like: `%${value}%`}}; } } + + onSelection2(value, item) { + console.log(item, this.zone.id); + if (value == null) + value = undefined; + const params = {geoId: item.id, isIncluded: value}; + const path = `zones/${this.zone.id}/toggleIsIncluded`; + this.$http.post(path, params); + } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; ngModule.vnComponent('vnZoneEvents', { template: require('./index.html'), - controller: Controller + controller: Controller, + bindings: { + zone: '<' + }, + require: { + card: '^vnZoneCard' + } }); diff --git a/modules/zone/front/location/index.js b/modules/zone/front/location/index.js index 0f92f37de..8f3a24b65 100644 --- a/modules/zone/front/location/index.js +++ b/modules/zone/front/location/index.js @@ -36,6 +36,8 @@ class Controller extends Section { } onSelection(value, item) { + console.log(item, this.zone.id); + if (value == null) value = undefined; const params = {geoId: item.id, isIncluded: value}; diff --git a/modules/zone/front/location/style.scss b/modules/zone/front/location/style.scss index 2316a2622..24d685a51 100644 --- a/modules/zone/front/location/style.scss +++ b/modules/zone/front/location/style.scss @@ -1,19 +1,21 @@ @import "variables"; -vn-treeview-child { - .content > .vn-check:not(.indeterminate):not(.checked) { - color: $color-alert; +vn-zone-location { + vn-treeview-child { + .content > .vn-check:not(.indeterminate):not(.checked) { + color: $color-alert; - & > .btn { - border-color: $color-alert; + & > .btn { + border-color: $color-alert; + } + } + .content > .vn-check.checked { + color: $color-notice; + + & > .btn { + background-color: $color-notice; + border-color: $color-notice + } } } - .content > .vn-check.checked { - color: $color-notice; - - & > .btn { - background-color: $color-notice; - border-color: $color-notice - } - } -} \ No newline at end of file +} diff --git a/modules/zone/front/routes.json b/modules/zone/front/routes.json index e08f97314..7f67260da 100644 --- a/modules/zone/front/routes.json +++ b/modules/zone/front/routes.json @@ -85,10 +85,13 @@ "description": "Warehouses" }, { - "url": "/events", + "url": "/events?q", "state": "zone.card.events", "component": "vn-zone-events", - "description": "Calendar" + "description": "Calendar", + "params": { + "zone": "$ctrl.zone" + } }, { "url": "/location?q", From ab13c16948111fbc42bc2ccacc3ebf76d0be82d6 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 16 May 2022 07:17:29 +0200 Subject: [PATCH 04/68] feat: add dialog --- .../10460-mothersDay/00-zoneHoliday.sql | 5 +- .../zone/back/methods/zone/exclusionGeo.js | 48 +++++++++++++++++++ .../back/methods/zone/getEventsFiltered.js | 17 +++++-- .../zone/back/models/zone-exclusion-geo.json | 2 +- modules/zone/back/models/zone.js | 1 + modules/zone/front/calendar/index.js | 20 ++++++-- modules/zone/front/calendar/style.scss | 3 ++ modules/zone/front/events/index.html | 23 +++++---- modules/zone/front/events/index.js | 35 ++++++++------ modules/zone/front/events/style.scss | 11 +++++ modules/zone/front/location/index.js | 2 - 11 files changed, 133 insertions(+), 34 deletions(-) create mode 100644 modules/zone/back/methods/zone/exclusionGeo.js create mode 100644 modules/zone/front/events/style.scss diff --git a/db/changes/10460-mothersDay/00-zoneHoliday.sql b/db/changes/10460-mothersDay/00-zoneHoliday.sql index cacf5ba84..badae1c3e 100644 --- a/db/changes/10460-mothersDay/00-zoneHoliday.sql +++ b/db/changes/10460-mothersDay/00-zoneHoliday.sql @@ -81,11 +81,14 @@ BEGIN SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays FROM tZone t JOIN zoneEvent e ON e.zoneFk = t.id; + SELECT e.zoneFk, e.dated FROM tZone t JOIN zoneExclusion e ON e.zoneFk = t.id LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id - WHERE eg.zoneExclusionFk IS NULL; + JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vGeoFk + WHERE eg.zoneExclusionFk IS NULL OR zg2.`path` LIKE CONCAT(zg1.`path`,'%'); DROP TEMPORARY TABLE tZone; END$$ diff --git a/modules/zone/back/methods/zone/exclusionGeo.js b/modules/zone/back/methods/zone/exclusionGeo.js new file mode 100644 index 000000000..0bd6075b9 --- /dev/null +++ b/modules/zone/back/methods/zone/exclusionGeo.js @@ -0,0 +1,48 @@ + +module.exports = Self => { + Self.remoteMethod('exclusionGeo', { + description: 'Exclude a zoneGeo for a zone', + accepts: [ + { + arg: 'zoneFk', + type: 'number', + description: 'The zone id' + }, + { + arg: 'date', + type: 'date', + description: 'The date to exclude' + }, + { + arg: 'geoIds', + type: 'any', + description: 'The geos id' + } + + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/exclusionGeo`, + verb: 'POST' + } + }); + + Self.exclusionGeo = async(zoneFk, date, geoIds, options) => { + const models = Self.app.models; + + const newZoneExclusion = await models.ZoneExclusion.create({ + zoneFk: zoneFk, + dated: date + }); + + for (let geoId of geoIds) { + await models.ZoneExclusionGeo.create({ + zoneExclusionFk: newZoneExclusion.id, + geoFk: geoId.id + }); + } + }; +}; diff --git a/modules/zone/back/methods/zone/getEventsFiltered.js b/modules/zone/back/methods/zone/getEventsFiltered.js index 5e9cbae5a..b97e49b1c 100644 --- a/modules/zone/back/methods/zone/getEventsFiltered.js +++ b/modules/zone/back/methods/zone/getEventsFiltered.js @@ -53,11 +53,22 @@ module.exports = Self => { query = ` SELECT * - FROM vn.zoneExclusion + FROM vn.zoneExclusion e + LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id WHERE zoneFk = ? - AND dated BETWEEN ? AND ?;`; + AND dated BETWEEN ? AND ? + AND eg.zoneExclusionFk IS NULL;`; const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); - return {events, exclusions}; + query = ` + SELECT * + FROM vn.zoneExclusion e + LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE zoneFk = ? + AND dated BETWEEN ? AND ? + AND eg.zoneExclusionFk IS NOT NULL;`; + const geoExclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); + + return {events, exclusions, geoExclusions}; }; }; diff --git a/modules/zone/back/models/zone-exclusion-geo.json b/modules/zone/back/models/zone-exclusion-geo.json index a578a07d0..7c77c5458 100644 --- a/modules/zone/back/models/zone-exclusion-geo.json +++ b/modules/zone/back/models/zone-exclusion-geo.json @@ -12,7 +12,7 @@ "required": true }, "geoFk": { - "type": "date", + "type": "number", "required": true } } diff --git a/modules/zone/back/models/zone.js b/modules/zone/back/models/zone.js index ef1c8c5d9..c580a2f15 100644 --- a/modules/zone/back/models/zone.js +++ b/modules/zone/back/models/zone.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/zone/deleteZone')(Self); require('../methods/zone/includingExpired')(Self); require('../methods/zone/getZoneClosing')(Self); + require('../methods/zone/exclusionGeo')(Self); Self.validatesPresenceOf('agencyModeFk', { message: `Agency cannot be blank` diff --git a/modules/zone/front/calendar/index.js b/modules/zone/front/calendar/index.js index a24d10aef..bdec1b949 100644 --- a/modules/zone/front/calendar/index.js +++ b/modules/zone/front/calendar/index.js @@ -75,6 +75,17 @@ class Controller extends Component { } } + this.geoExclusions = {}; + let geoExclusions = value.geoExclusions; + + if (geoExclusions) { + for (let geoExclusion of geoExclusions) { + let stamp = toStamp(geoExclusion.dated); + if (!this.geoExclusions[stamp]) this.geoExclusions[stamp] = []; + this.geoExclusions[stamp].push(geoExclusion); + } + } + let events = value.events; if (events) { @@ -154,13 +165,16 @@ class Controller extends Component { hasEvents(day) { let stamp = day.getTime(); - return this.days[stamp] || this.exclusions[stamp]; + return this.days[stamp] || this.exclusions[stamp] || this.geoExclusions[stamp]; } getClass(day) { let stamp = day.getTime(); - return this.exclusions[stamp] && !this.days[stamp] - ? 'excluded' : ''; + if (this.geoExclusions[stamp] && !this.days[stamp]) + return 'geoExcluded'; + else if (this.exclusions[stamp] && !this.days[stamp]) + return 'excluded'; + else return ''; } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; diff --git a/modules/zone/front/calendar/style.scss b/modules/zone/front/calendar/style.scss index 25b6a87d1..d6853e33c 100644 --- a/modules/zone/front/calendar/style.scss +++ b/modules/zone/front/calendar/style.scss @@ -33,6 +33,9 @@ vn-zone-calendar { &.excluded .day-number { background-color: $color-alert; } + &.geoExcluded .day-number { + background-color: #33CAFF; + } } } } diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index 67657e665..45e2ec671 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -205,18 +205,18 @@ + ng-model="$ctrl.excludeSelected.dated"> - + @@ -227,20 +227,23 @@ url="Zones/{{$ctrl.$params.id}}/getLeaves" filter="$ctrl.filter"> -
+
+ + + -
+
@@ -254,13 +257,15 @@ + translate-attr="{value: 'Cancel'}" + tabindex="0"> + translate-attr="{value: 'Delete'}" + tabindex="0">