diff --git a/back/nodemonConfig.json b/back/nodemonConfig.json index a1c9ca84fc..5138bc30ed 100644 --- a/back/nodemonConfig.json +++ b/back/nodemonConfig.json @@ -18,6 +18,7 @@ "modules/supplier/front/**/*", "modules/ticket/front/**/*", "modules/travel/front/**/*", + "modules/shelving/front/**/*", "modules/worker/front/**/*", "modules/zone/front/**/*" ] diff --git a/db/changes/10480-june/00-aclShelvingLog.sql b/db/changes/10480-june/00-aclShelvingLog.sql new file mode 100644 index 0000000000..dc75142d12 --- /dev/null +++ b/db/changes/10480-june/00-aclShelvingLog.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) + VALUES + ('ShelvingLog','*','READ','ALLOW','ROLE','employee'); \ No newline at end of file diff --git a/db/changes/10480-june/00-aclZoneExclusionGeos.sql b/db/changes/10480-june/00-aclZoneExclusionGeos.sql new file mode 100644 index 0000000000..4c0f6c9916 --- /dev/null +++ b/db/changes/10480-june/00-aclZoneExclusionGeos.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ZoneExclusionGeo', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('ZoneExclusionGeo', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss'); \ No newline at end of file diff --git a/db/changes/10480-june/00-route.sql b/db/changes/10480-june/00-route.sql new file mode 100644 index 0000000000..beb7d5e414 --- /dev/null +++ b/db/changes/10480-june/00-route.sql @@ -0,0 +1,10 @@ +UPDATE `vn`.`route` r + JOIN(SELECT r.id, wl.workcenterFk + FROM `vn`.`route` r + JOIN `vn`.`routeLog` rl ON rl.originFk = r.id + JOIN `vn`.`workerLabour` wl ON wl.workerFk = rl.userFk + AND r.created BETWEEN wl.started AND IFNULL(wl.ended, r.created) + WHERE r.created BETWEEN '2021-12-01' AND CURDATE() + AND rl.action = 'insert' + )sub ON sub.id = r.id + SET r.commissionWorkCenterFk = sub.workcenterFk; \ No newline at end of file diff --git a/db/changes/10480-june/00-shelving.sql b/db/changes/10480-june/00-shelving.sql new file mode 100644 index 0000000000..c66d164c4f --- /dev/null +++ b/db/changes/10480-june/00-shelving.sql @@ -0,0 +1,18 @@ +ALTER TABLE `vn`.`itemShelving` DROP FOREIGN KEY itemShelving_fk2; +ALTER TABLE `vn`.`shelvingLog` DROP FOREIGN KEY shelvingLog_FK_ibfk_1; +ALTER TABLE `vn`.`smartTag` DROP FOREIGN KEY smartTag_shelving_fk; +ALTER TABLE `vn`.`workerShelving` DROP FOREIGN KEY workerShelving_shelving_fk; + +ALTER TABLE `vn`.`shelving` DROP PRIMARY KEY; +ALTER TABLE `vn`.`shelving` ADD id INT auto_increment PRIMARY KEY NULL; +ALTER TABLE `vn`.`shelving` CHANGE id id int(11) auto_increment NOT NULL FIRST; +ALTER TABLE `vn`.`shelving` ADD CONSTRAINT shelving_UN UNIQUE KEY (code); + +ALTER TABLE `vn`.`itemShelving` ADD CONSTRAINT itemShelving_fk2 FOREIGN KEY (shelvingFk) REFERENCES `vn`.`shelving`(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `vn`.`shelvingLog` ADD CONSTRAINT shelvingLog_FK_ibfk_1 FOREIGN KEY (originFk) REFERENCES `vn`.`shelving`(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `vn`.`smartTag` ADD CONSTRAINT smartTag_FK FOREIGN KEY (shelvingFk) REFERENCES `vn`.`shelving`(code) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `vn`.`workerShelving` ADD CONSTRAINT workerShelving_FK_1 FOREIGN KEY (shelvingFk) REFERENCES `vn`.`shelving`(code) ON DELETE RESTRICT ON UPDATE CASCADE; + +ALTER TABLE vn.shelvingLog DROP FOREIGN KEY shelvingLog_FK_ibfk_1; +ALTER TABLE vn.shelvingLog MODIFY COLUMN originFk INT NOT NULL; +ALTER TABLE vn.shelvingLog ADD CONSTRAINT shelvingLog_FK FOREIGN KEY (originFk) REFERENCES vn.shelving(id) ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/changes/10480-june/04-aclParking.sql b/db/changes/10480-june/04-aclParking.sql new file mode 100644 index 0000000000..05acd68b1c --- /dev/null +++ b/db/changes/10480-june/04-aclParking.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) + VALUES ('Parking','*','*','ALLOW','ROLE','employee') \ No newline at end of file diff --git a/db/changes/10480-june/04-aclShelving.sql b/db/changes/10480-june/04-aclShelving.sql new file mode 100644 index 0000000000..b237dfe0da --- /dev/null +++ b/db/changes/10480-june/04-aclShelving.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) + VALUES ('Shelving','*','*','ALLOW','ROLE','employee') \ No newline at end of file diff --git a/db/changes/10490-august/delete.keep b/db/changes/10490-august/delete.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f67db0b200..640f3fde08 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -155,14 +155,29 @@ INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPrepare INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`) VALUES - ('1', '700', '01', '1', '700-01', '70001'), - ('2', '700', '02', '2', '700-02', '70002'); + ('1', 700, '01', 1, '700-01', 70001), + ('2', 700, '02', 2, '700-02', 70002), + ('3', 100, '01', 1, '100-01', 1), + (32397, 100, '02', 1, 'A-47-1', 1165), + (34831, 200, '01', 1, 'K-26-2', 20220), + (34965, 200, '02', 2, 'L-08-4', 21800), + (39096, 200, '03', 2, 'LR-02-3', 99999); -INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `parked`, `userFk`) +INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `userFk`, `isRecyclable`) VALUES - ('GVC', 1, 0, 1, 0, 1106), - ('HEJ', 2, 0, 1, 0, 1106), - ('UXN', 1, 0, 1, 0, 1106); + ('AA6', 34965, 1, 0, NULL, 0), + ('AA7', 34965, 1, 0, NULL, 0), + ('AA8', 34965, 1, 0, NULL, 0), + ('AA9', NULL, 1, 0, NULL, 0), + ('AAA', NULL, 0, 0, 1109, 1), + ('AAB', NULL, 0, 0, 1109, 1), + ('AAC', NULL, 1, 99, 1109, 1), + ('AAD', NULL, 0, 0, 1109, 1), + ('AAE', 39096, 1, 0, 1109, 1), + ('AAF', 34831, 1, 0, 1109, 1), + ('GVC', 1, 0, 1, 1106, 1), + ('HEJ', 2, 0, 1, 1106, 1), + ('UXN', 1, 0, 1, 1106, 1); INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`, `maxAmount`, `daysInFuture`) VALUES @@ -1137,6 +1152,9 @@ INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) (3, 2, NULL), (23, 1, NULL); +INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `level`) + VALUES + (1, 1, 1); INSERT INTO `vn`.`parking` (`column`, `row`, `sectorFk`, `code`, `pickingOrder`) VALUES ('100', '01', 1, '100-01', 1); @@ -1340,7 +1358,7 @@ INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) (4, 4), (5, 6); -INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`) +INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`) VALUES (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1), (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2), @@ -2582,6 +2600,15 @@ INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed` (1106, 2, util.VN_CURDATE(), NULL), (1106, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)); +INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`) +VALUES + (1, 1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=7, 7, 14) - DAYOFWEEK(CURDATE())) DAY), CURDATE(), 100), + (2, 1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=8, 8, 15) - DAYOFWEEK(CURDATE())) DAY), CURDATE(), 100); + +INSERT INTO `vn`.`zoneExclusionGeo` (`zoneExclusionFk`, `geoFk`) + VALUES + (2, 1); + INSERT INTO `vn`.`mdbBranch` (`name`) VALUES ('test'), @@ -2620,3 +2647,6 @@ INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`) VALUES (1, 'h1', 1, 'VbiUcajdaT'); +INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) + VALUES + (1, 9); diff --git a/db/dump/structure.sql b/db/dump/structure.sql index bb58c1955f..d6197c052b 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -34349,6 +34349,7 @@ CREATE TABLE `route` ( `priority` int(11) NOT NULL DEFAULT '0', `invoiceInFk` mediumint(8) unsigned DEFAULT NULL, `beachFk` int(11) DEFAULT NULL, + `commissionWorkCenterFk` int(11) DEFAULT NULL COMMENT 'WorkerCenter que gestiona la ruta', PRIMARY KEY (`id`), KEY `Id_Agencia` (`agencyModeFk`), KEY `Fecha` (`created`), @@ -34357,7 +34358,9 @@ CREATE TABLE `route` ( KEY `fk_route_1_idx` (`zoneFk`), KEY `asdfasdf_idx` (`invoiceInFk`), KEY `route_idxIsOk` (`isOk`), + KEY `route_WorkCenterFk_idx` (`commissionWorkCenterFk`), CONSTRAINT `fk_route_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `route_WorkCenterFk` FOREIGN KEY (`commissionWorkCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE, CONSTRAINT `route_fk5` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `route_ibfk_1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `route_ibfk_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, @@ -34514,6 +34517,7 @@ CREATE TABLE `routeConfig` ( `plusCategory1Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `plusCategory2Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `defaultCompanyFk` smallint(5) unsigned DEFAULT '442', + `defaultWorkCenterFk` int(11) DEFAULT 9 COMMENT 'Para el cálculo de las comisiones, en caso de el creador de la ruta no tenga workCenter', PRIMARY KEY (`id`), KEY `routeConfig_FK` (`defaultCompanyFk`), CONSTRAINT `routeConfig_FK` FOREIGN KEY (`defaultCompanyFk`) REFERENCES `company` (`id`) @@ -38644,26 +38648,29 @@ CREATE TABLE `travel` ( `warehouseInFk` smallint(6) unsigned DEFAULT NULL, `warehouseOutFk` smallint(6) unsigned DEFAULT NULL, `agencyFk` int(11) DEFAULT NULL, - `ref` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `isDelivered` tinyint(1) NOT NULL DEFAULT '0', - `isReceived` tinyint(1) NOT NULL DEFAULT '0', + `agencyModeFk` int(11) DEFAULT NULL, + `ref` varchar(20) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `isDelivered` tinyint(1) NOT NULL DEFAULT 0, + `isReceived` tinyint(1) NOT NULL DEFAULT 0, `m3` decimal(10,2) unsigned DEFAULT NULL, `kg` decimal(10,0) unsigned DEFAULT NULL, `cargoSupplierFk` int(11) DEFAULT NULL, - `totalEntries` tinyint(4) unsigned DEFAULT '0', + `totalEntries` tinyint(4) unsigned DEFAULT 0, `appointment` datetime DEFAULT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `shipment_2` (`shipped`,`landed`,`warehouseInFk`,`warehouseOutFk`,`agencyFk`,`ref`), + UNIQUE KEY `shipment_1` (`shipped`,`landed`,`warehouseInFk`,`warehouseOutFk`,`agencyFk`,`agencyModeFk`,`ref`), KEY `agency_id` (`agencyFk`), KEY `shipment` (`shipped`), KEY `landing` (`landed`), KEY `warehouse_landing` (`warehouseInFk`,`landed`), KEY `warehouse_out_shipment` (`warehouseOutFk`,`shipped`), KEY `travel_ibfk_4_idx` (`cargoSupplierFk`), + KEY `travel_FK` (`agencyModeFk`), + CONSTRAINT `travel_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_1` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouseOutFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agencyFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=195614 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -38679,6 +38686,15 @@ DELIMITER ;; FOR EACH ROW BEGIN CALL travel_checkDates(NEW.shipped, NEW.landed); + + -- Actualizar agencyFk y agencyModeFk + IF NEW.agencyFk THEN + SET NEW.agencyModeFk = NEW.agencyFk; + END IF; + + IF NEW.agencyModeFk THEN + SET NEW.agencyFk = NEW.agencyModeFk; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -38702,6 +38718,15 @@ BEGIN OR !(NEW.shipped <=> OLD.shipped) THEN CALL travel_checkDates(NEW.shipped, NEW.landed); END IF; + + -- Actualizar agencyFk y agencyModeFk + IF !(NEW.agencyFk <=> OLD.agencyFk)THEN + SET NEW.agencyModeFk = NEW.agencyFk; + END IF; + + IF !(NEW.agencyModeFk <=> OLD.agencyModeFk) THEN + SET NEW.agencyFk = NEW.agencyModeFk; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -39331,38 +39356,39 @@ DROP TABLE IF EXISTS `worker`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `worker` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `code` varchar(3) COLLATE utf8_unicode_ci NOT NULL, - `firstName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `lastName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `password__` varchar(50) CHARACTER SET utf8 DEFAULT NULL, - `email__` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `extension__` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, + `code` varchar(3) COLLATE utf8mb3_unicode_ci NOT NULL, + `firstName` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `lastName` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `password__` varchar(50) CHARACTER SET utf8mb3 DEFAULT NULL, + `email__` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `extension__` varchar(10) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `sub` int(11) unsigned DEFAULT NULL, - `user__` varchar(20) CHARACTER SET utf8 DEFAULT NULL, - `typeBussines__` varchar(30) CHARACTER SET utf8 DEFAULT 'no dejar vacio' COMMENT 'campo obsoleto, actualmente se rellena en laboral', - `laborCategory__` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `user__` varchar(20) CHARACTER SET utf8mb3 DEFAULT NULL, + `typeBussines__` varchar(30) CHARACTER SET utf8mb3 DEFAULT 'no dejar vacio' COMMENT 'campo obsoleto, actualmente se rellena en laboral', + `laborCategory__` varchar(45) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `started__` datetime DEFAULT NULL, `ended__` datetime DEFAULT NULL, - `notes__` varchar(254) COLLATE utf8_unicode_ci DEFAULT NULL, - `photo` blob, - `fi__` varchar(9) COLLATE utf8_unicode_ci DEFAULT NULL, - `address__` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + `notes__` varchar(254) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `photo` blob DEFAULT NULL, + `fi__` varchar(9) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `address__` varchar(50) COLLATE utf8mb3_unicode_ci NOT NULL, `birthed__` date NOT NULL, - `phone` varchar(9) COLLATE utf8_unicode_ci NOT NULL, + `phone` varchar(9) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `mobileExtension` int(4) DEFAULT NULL, `clientFk__` int(11) DEFAULT NULL, `userFk` int(10) unsigned DEFAULT NULL, - `bossFk` int(11) NOT NULL DEFAULT '103', + `bossFk` int(11) NOT NULL DEFAULT 103, `fiDueDate` datetime DEFAULT NULL, - `hasMachineryAuthorized` tinyint(2) DEFAULT '0', + `hasMachineryAuthorized` tinyint(2) DEFAULT 0, `seniority` date DEFAULT NULL, - `isTodayRelative` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para el F11. Calcula los problemas de visiblidad en funcion del dia actual', - `isF11Allowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Usuario autorizado para abrir el F11', + `isTodayRelative` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Para el F11. Calcula los problemas de visiblidad en funcion del dia actual', + `isF11Allowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Usuario autorizado para abrir el F11', `sectorFk` int(11) DEFAULT NULL COMMENT 'Sector que tiene asociado el trabajador.', - `maritalStatus` enum('S','M') COLLATE utf8_unicode_ci NOT NULL, + `maritalStatus` enum('S','M') COLLATE utf8mb3_unicode_ci NOT NULL, `labelerFk` tinyint(3) unsigned DEFAULT NULL, `originCountryFk` mediumint(8) unsigned DEFAULT NULL COMMENT 'País de origen', `educationLevelFk` smallint(6) DEFAULT NULL, - `SSN` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, + `SSN` varchar(15) COLLATE utf8mb3_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `CodigoTrabajador_UNIQUE` (`code`), UNIQUE KEY `user` (`user__`), @@ -39378,7 +39404,7 @@ CREATE TABLE `worker` ( CONSTRAINT `worker_FK_1` FOREIGN KEY (`originCountryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, CONSTRAINT `worker_FK_2` FOREIGN KEY (`educationLevelFk`) REFERENCES `educationLevel` (`id`) ON UPDATE CASCADE, CONSTRAINT `worker_ibfk_1` FOREIGN KEY (`id`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=22748 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46798,7 +46824,7 @@ BEGIN JOIN entry e ON e.id = b.entryFk JOIN itemType it ON it.id = i.typeFk JOIN travel tr ON tr.id = e.travelFk - JOIN agencyMode am ON am.id = tr.agencyFk + JOIN agencyMode am ON am.id = tr.agencyModeFk JOIN tmp.rate r SET b.freightValue = @PF:= ROUND(IFNULL(((am.m3 * @cm3:= item_getVolume(b.itemFk, b.packageFk)) / 1000000) / b.packing,0),3), @@ -72287,7 +72313,7 @@ BEGIN END; START TRANSACTION; - INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyFk, `ref`, isDelivered, isReceived, m3, kg) + INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, kg) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3, kg FROM travel WHERE id = vTravelFk; diff --git a/e2e/paths/12-entry/02_descriptor.spec.js b/e2e/paths/12-entry/02_descriptor.spec.js index 699d005170..997a6065cd 100644 --- a/e2e/paths/12-entry/02_descriptor.spec.js +++ b/e2e/paths/12-entry/02_descriptor.spec.js @@ -29,7 +29,7 @@ describe('Entry descriptor path', () => { it('should click the travels button to be redirected to the travels index filtered by the current agency', async() => { await page.waitToClick(selectors.entryDescriptor.travelsQuicklink); await page.expectURL('/travel/index'); - await page.expectURL('agencyFk'); + await page.expectURL('agencyModeFk'); }); it('should go back to the entry summary', async() => { diff --git a/front/module-import.js b/front/module-import.js index ab1eb73d69..bc547deeb1 100755 --- a/front/module-import.js +++ b/front/module-import.js @@ -21,6 +21,7 @@ export default function moduleImport(moduleName) { case 'entry' : return import('entry/front'); case 'account' : return import('account/front'); case 'supplier' : return import('supplier/front'); + case 'shelving' : return import('shelving/front'); case 'monitor' : return import('monitor/front'); } } diff --git a/jest-front.js b/jest-front.js index 7a692f57cb..6d75322602 100644 --- a/jest-front.js +++ b/jest-front.js @@ -13,6 +13,7 @@ import './modules/route/front/module.js'; import './modules/ticket/front/module.js'; import './modules/travel/front/module.js'; import './modules/worker/front/module.js'; +import './modules/shelving/front/module.js'; core.run(vnInterceptor => { vnInterceptor.setApiPath(null); diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index b395b102ad..c7462e46c1 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -37,7 +37,7 @@ {"state": "client.card.unpaid", "icon": "icon-defaulter"} ] } - ] + ] }, "keybindings": [ {"key": "c", "state": "client.index"} diff --git a/modules/entry/back/methods/entry/getEntry.js b/modules/entry/back/methods/entry/getEntry.js index 66238d0dc4..cac3c65f86 100644 --- a/modules/entry/back/methods/entry/getEntry.js +++ b/modules/entry/back/methods/entry/getEntry.js @@ -43,7 +43,7 @@ module.exports = Self => { 'name', 'shipped', 'landed', - 'agencyFk', + 'agencyModeFk', 'warehouseOutFk', 'warehouseInFk', 'isReceived', diff --git a/modules/entry/front/basic-data/index.html b/modules/entry/front/basic-data/index.html index 8787853a51..423e9d70d2 100644 --- a/modules/entry/front/basic-data/index.html +++ b/modules/entry/front/basic-data/index.html @@ -137,7 +137,7 @@ diff --git a/modules/entry/front/basic-data/index.js b/modules/entry/front/basic-data/index.js index 80870c3f37..564a3df5ce 100644 --- a/modules/entry/front/basic-data/index.js +++ b/modules/entry/front/basic-data/index.js @@ -46,7 +46,7 @@ class Controller extends Section { if (!value) continue; switch (key) { - case 'agencyFk': + case 'agencyModeFk': case 'warehouseInFk': case 'warehouseOutFk': case 'shipped': diff --git a/modules/entry/front/card/index.js b/modules/entry/front/card/index.js index eafed171bb..96f4702e29 100644 --- a/modules/entry/front/card/index.js +++ b/modules/entry/front/card/index.js @@ -14,7 +14,7 @@ class Controller extends ModuleCard { { relation: 'travel', scope: { - fields: ['id', 'landed', 'agencyFk', 'warehouseOutFk'], + fields: ['id', 'landed', 'agencyModeFk', 'warehouseOutFk'], include: [ { relation: 'agency', diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index fed3787d49..34aa162f98 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -14,9 +14,9 @@ class Controller extends Descriptor { let travelFilter; const entryTravel = this.entry && this.entry.travel; - if (entryTravel && entryTravel.agencyFk) { + if (entryTravel && entryTravel.agencyModeFk) { travelFilter = this.entry && JSON.stringify({ - agencyFk: entryTravel.agencyFk + agencyModeFk: entryTravel.agencyModeFk }); } return travelFilter; @@ -49,7 +49,7 @@ class Controller extends Descriptor { { relation: 'travel', scope: { - fields: ['id', 'landed', 'agencyFk', 'warehouseOutFk'], + fields: ['id', 'landed', 'agencyModeFk', 'warehouseOutFk'], include: [ { relation: 'agency', diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js new file mode 100644 index 0000000000..5328dc2404 --- /dev/null +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -0,0 +1,51 @@ +const models = require('vn-loopback/server/server').models; + +describe('route updateWorkCenter()', () => { + const routeId = 1; + + it('should set the commission work center if the worker has workCenter', async() => { + const tx = await models.Route.beginTransaction({}); + try { + const developerId = 9; + const ctx = { + req: { + accessToken: {userId: developerId} + } + }; + const options = {transaction: tx}; + + const expectedResult = 1; + const updatedRoute = await models.Route.updateWorkCenter(ctx, routeId, options); + + expect(updatedRoute.commissionWorkCenterFk).toEqual(expectedResult); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`shoul set the default commision work center if that worker didn't have one yet`, async() => { + const tx = await models.Route.beginTransaction({}); + try { + const userWithoutWorkCenter = 2; + const ctx = { + req: { + accessToken: {userId: userWithoutWorkCenter} + } + }; + const options = {transaction: tx}; + + const expectedResult = 9; + const updatedRoute = await models.Route.updateWorkCenter(ctx, routeId, options); + + expect(updatedRoute.commissionWorkCenterFk).toEqual(expectedResult); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/route/back/methods/route/updateWorkCenter.js b/modules/route/back/methods/route/updateWorkCenter.js new file mode 100644 index 0000000000..7796fba412 --- /dev/null +++ b/modules/route/back/methods/route/updateWorkCenter.js @@ -0,0 +1,54 @@ +module.exports = Self => { + Self.remoteMethodCtx('updateWorkCenter', { + description: 'Update the commission work center through user salix connected', + accessType: 'WRITE', + accepts: { + arg: 'id', + type: 'number', + description: 'Route Id', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/updateWorkCenter`, + verb: 'POST' + } + }); + + Self.updateWorkCenter = async(ctx, id, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + const userId = ctx.req.accessToken.userId; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const [result] = await Self.rawSql(` + SELECT IFNULL(wl.workCenterFk, r.defaultWorkCenterFk) AS commissionWorkCenter + FROM vn.routeConfig r + LEFT JOIN vn.workerLabour wl ON wl.workerFk = ? + AND CURDATE() BETWEEN wl.started AND IFNULL(wl.ended, CURDATE()); + `, [userId], myOptions); + + const route = await models.Route.findById(id, null, myOptions); + await route.updateAttribute('commissionWorkCenterFk', result.commissionWorkCenter, myOptions); + + if (tx) await tx.commit(); + + return route; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index c82d1722e9..4050e62fe0 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -9,6 +9,7 @@ module.exports = Self => { require('../methods/route/clone')(Self); require('../methods/route/getSuggestedTickets')(Self); require('../methods/route/unlink')(Self); + require('../methods/route/updateWorkCenter')(Self); Self.validate('kmStart', validateDistance, { message: 'Distance must be lesser than 1000' diff --git a/modules/route/back/models/route.json b/modules/route/back/models/route.json index 46fb6b76f7..3b33cc0280 100644 --- a/modules/route/back/models/route.json +++ b/modules/route/back/models/route.json @@ -47,6 +47,9 @@ }, "description": { "type": "string" + }, + "commissionWorkCenterFk": { + "type": "number" } }, "relations": { diff --git a/modules/route/front/create/index.js b/modules/route/front/create/index.js index 56c8cc25ac..c81394c10c 100644 --- a/modules/route/front/create/index.js +++ b/modules/route/front/create/index.js @@ -4,7 +4,12 @@ import Section from 'salix/components/section'; export default class Controller extends Section { onSubmit() { this.$.watcher.submit().then( - res => this.$state.go('route.card.summary', {id: res.data.id}) + res => { + this.$http.post(`Routes/${res.data.id}/updateWorkCenter`, null) + .then(() => { + this.$state.go('route.card.summary', {id: res.data.id}); + }); + } ); } } diff --git a/modules/shelving/back/methods/shelving/getSummary.js b/modules/shelving/back/methods/shelving/getSummary.js new file mode 100644 index 0000000000..da357c7bf3 --- /dev/null +++ b/modules/shelving/back/methods/shelving/getSummary.js @@ -0,0 +1,52 @@ +module.exports = Self => { + Self.remoteMethod('getSummary', { + description: 'Returns the shelving summary', + accessType: 'READ', + accepts: { + arg: 'code', + type: 'string', + required: true, + description: 'The shelving code', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/:code/getSummary`, + verb: 'GET' + } + }); + Self.getSummary = async code => { + let filter = { + where: {code: code}, + fields: [ + 'code', + 'parkingFk', + 'priority', + 'userFk', + 'isRecyclable' + ], + include: [ + { + relation: 'parking' + }, + { + relation: 'worker', + scope: { + fields: ['id', 'userFk'], + include: { + relation: 'user', + scope: { + fields: ['id', 'nickname'] + } + } + } + } + ] + }; + + return Self.app.models.Shelving.findOne(filter); + }; +}; diff --git a/modules/shelving/back/model-config.json b/modules/shelving/back/model-config.json new file mode 100644 index 0000000000..b5619d8c5b --- /dev/null +++ b/modules/shelving/back/model-config.json @@ -0,0 +1,11 @@ +{ + "Parking": { + "dataSource": "vn" + }, + "Shelving": { + "dataSource": "vn" + }, + "ShelvingLog": { + "dataSource": "vn" + } +} diff --git a/modules/shelving/back/models/parking.json b/modules/shelving/back/models/parking.json new file mode 100644 index 0000000000..7efcf72d32 --- /dev/null +++ b/modules/shelving/back/models/parking.json @@ -0,0 +1,33 @@ +{ + "name": "Parking", + "base": "VnModel", + "options": { + "mysql": { + "table": "parking" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "column": { + "type": "string", + "required": true + }, + "row": { + "type": "string", + "required": true + }, + "sectorFk": { + "type": "number" + }, + "code": { + "type": "string" + }, + "pickingOrder": { + "type": "number" + } + } +} diff --git a/modules/shelving/back/models/shelving-log.json b/modules/shelving/back/models/shelving-log.json new file mode 100644 index 0000000000..a2267394e9 --- /dev/null +++ b/modules/shelving/back/models/shelving-log.json @@ -0,0 +1,58 @@ +{ + "name": "ShelvingLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "shelvingLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "forceId": false + }, + "originFk": { + "type": "number", + "required": true + }, + "userFk": { + "type": "number" + }, + "action": { + "type": "string", + "required": true + }, + "changedModel": { + "type": "string" + }, + "oldInstance": { + "type": "object" + }, + "newInstance": { + "type": "object" + }, + "creationDate": { + "type": "date" + }, + "changedModelId": { + "type": "number" + }, + "changedModelValue": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/shelving/back/models/shelving.js b/modules/shelving/back/models/shelving.js new file mode 100644 index 0000000000..3e27f5863c --- /dev/null +++ b/modules/shelving/back/models/shelving.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/shelving/getSummary')(Self); +}; diff --git a/modules/shelving/back/models/shelving.json b/modules/shelving/back/models/shelving.json new file mode 100644 index 0000000000..508ac428f0 --- /dev/null +++ b/modules/shelving/back/models/shelving.json @@ -0,0 +1,51 @@ +{ + "name": "Shelving", + "base": "Loggable", + "log": { + "model": "ShelvingLog", + "showField": "id" + }, + "options": { + "mysql": { + "table": "shelving" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "code": { + "type": "string", + "required": true + }, + "parkingFk": { + "type": "number" + }, + "isPrinted": { + "type": "boolean" + }, + "priority": { + "type": "number" + }, + "userFk": { + "type": "number" + }, + "isRecyclable": { + "type": "boolean" + } + }, + "relations": { + "parking": { + "type": "belongsTo", + "model": "Parking", + "foreignKey": "parkingFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "userFk" + } + } +} diff --git a/modules/shelving/front/basic-data/index.html b/modules/shelving/front/basic-data/index.html new file mode 100644 index 0000000000..68d61e169a --- /dev/null +++ b/modules/shelving/front/basic-data/index.html @@ -0,0 +1,52 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/shelving/front/basic-data/index.js b/modules/shelving/front/basic-data/index.js new file mode 100644 index 0000000000..e17c9feeed --- /dev/null +++ b/modules/shelving/front/basic-data/index.js @@ -0,0 +1,10 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +ngModule.vnComponent('vnShelvingBasicData', { + template: require('./index.html'), + controller: Section, + bindings: { + shelving: '<' + } +}); diff --git a/modules/shelving/front/card/index.html b/modules/shelving/front/card/index.html new file mode 100644 index 0000000000..c83afc2881 --- /dev/null +++ b/modules/shelving/front/card/index.html @@ -0,0 +1,8 @@ + + + + + + diff --git a/modules/shelving/front/card/index.js b/modules/shelving/front/card/index.js new file mode 100644 index 0000000000..5e2ea9b129 --- /dev/null +++ b/modules/shelving/front/card/index.js @@ -0,0 +1,29 @@ +import ngModule from '../module'; +import ModuleCard from 'salix/components/module-card'; + +class Controller extends ModuleCard { + reload() { + const filter = { + include: [ + {relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + } + }}, + {relation: 'parking'} + ] + }; + this.$http.get(`Shelvings/${this.$params.id}`, {filter}) + .then(res => this.shelving = res.data); + } +} + +ngModule.vnComponent('vnShelvingCard', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/shelving/front/card/index.spec.js b/modules/shelving/front/card/index.spec.js new file mode 100644 index 0000000000..85b1bd2696 --- /dev/null +++ b/modules/shelving/front/card/index.spec.js @@ -0,0 +1,26 @@ +import './index'; + +describe('component vnShelvingCard', () => { + let controller; + let $httpBackend; + const data = {id: 1, code: 'AAA'}; + + beforeEach(ngModule('shelving')); + + beforeEach(inject(($componentController, _$httpBackend_, $stateParams) => { + $httpBackend = _$httpBackend_; + + let $element = angular.element('
'); + controller = $componentController('vnShelvingCard', {$element}); + + $stateParams.id = data.id; + $httpBackend.whenRoute('GET', 'Shelvings/:id').respond(data); + })); + + it('should reload the controller data', () => { + controller.reload(); + $httpBackend.flush(); + + expect(controller.shelving).toEqual(data); + }); +}); diff --git a/modules/shelving/front/create/index.html b/modules/shelving/front/create/index.html new file mode 100644 index 0000000000..edb3a7d3ba --- /dev/null +++ b/modules/shelving/front/create/index.html @@ -0,0 +1,51 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/shelving/front/create/index.js b/modules/shelving/front/create/index.js new file mode 100644 index 0000000000..bb0e441ebe --- /dev/null +++ b/modules/shelving/front/create/index.js @@ -0,0 +1,15 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + onSubmit() { + return this.$.watcher.submit().then(res => + this.$state.go('shelving.card.basicData', {id: res.data.id}) + ); + } +} + +ngModule.vnComponent('vnShelvingCreate', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/shelving/front/create/index.spec.js b/modules/shelving/front/create/index.spec.js new file mode 100644 index 0000000000..0bdde91458 --- /dev/null +++ b/modules/shelving/front/create/index.spec.js @@ -0,0 +1,38 @@ +import './index'; + +describe('Shelving', () => { + describe('Component vnShelvingCreate', () => { + let $scope; + let $state; + let controller; + + beforeEach(ngModule('shelving')); + + beforeEach(inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $state = _$state_; + $scope.watcher = { + submit: () => { + return { + then: callback => { + callback({data: {id: 1}}); + } + }; + } + }; + const $element = angular.element(''); + controller = $componentController('vnShelvingCreate', {$element, $scope}); + controller.$params = {}; + })); + + describe('onSubmit()', () => { + it(`should redirect to basic data by calling the $state.go function`, () => { + jest.spyOn(controller.$state, 'go'); + + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('shelving.card.basicData', {id: 1}); + }); + }); + }); +}); diff --git a/modules/shelving/front/descriptor/index.html b/modules/shelving/front/descriptor/index.html new file mode 100644 index 0000000000..1344bb52ad --- /dev/null +++ b/modules/shelving/front/descriptor/index.html @@ -0,0 +1,45 @@ + + + + Delete + + + +
+ + + + + + + {{::$ctrl.shelving.worker.user.nickname}} + + +
+
+
+ + + + + + + \ No newline at end of file diff --git a/modules/shelving/front/descriptor/index.js b/modules/shelving/front/descriptor/index.js new file mode 100644 index 0000000000..931dbb6dc0 --- /dev/null +++ b/modules/shelving/front/descriptor/index.js @@ -0,0 +1,26 @@ +import ngModule from '../module'; +import Descriptor from 'salix/components/descriptor'; + +class Controller extends Descriptor { + get shelving() { + return this.entity; + } + + set shelving(value) { + this.entity = value; + } + + onDelete() { + return this.$http.delete(`Shelvings/${this.shelving.id}`) + .then(() => this.$state.go('shelving.index')) + .then(() => this.vnApp.showSuccess(this.$t('Shelving removed'))); + } +} + +ngModule.vnComponent('vnShelvingDescriptor', { + template: require('./index.html'), + controller: Controller, + bindings: { + shelving: '<' + } +}); diff --git a/modules/shelving/front/descriptor/index.spec.js b/modules/shelving/front/descriptor/index.spec.js new file mode 100644 index 0000000000..3ee33580bd --- /dev/null +++ b/modules/shelving/front/descriptor/index.spec.js @@ -0,0 +1,29 @@ +import './index.js'; + +describe('component vnShelvingDescriptor', () => { + let $httpBackend; + let controller; + + const shelving = {id: 1, code: 'AA6'}; + + beforeEach(ngModule('shelving')); + + beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnShelvingDescriptor', {$element: null}, {shelving}); + jest.spyOn(controller.vnApp, 'showSuccess'); + })); + + describe('onDelete()', () => { + it('should delete entity and go to index', () => { + controller.$state.go = jest.fn(); + + $httpBackend.expectDELETE('Shelvings/1').respond(); + controller.onDelete(); + $httpBackend.flush(); + + expect(controller.$state.go).toHaveBeenCalledWith('shelving.index'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + }); + }); +}); diff --git a/modules/shelving/front/index.js b/modules/shelving/front/index.js new file mode 100644 index 0000000000..2ad9bc1b99 --- /dev/null +++ b/modules/shelving/front/index.js @@ -0,0 +1,11 @@ +export * from './module'; + +import './basic-data'; +import './card'; +import './create'; +import './descriptor'; +import './index/'; +import './main'; +import './search-panel'; +import './summary'; +import './log'; diff --git a/modules/shelving/front/index/index.html b/modules/shelving/front/index/index.html new file mode 100644 index 0000000000..1532abd429 --- /dev/null +++ b/modules/shelving/front/index/index.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/shelving/front/index/index.js b/modules/shelving/front/index/index.js new file mode 100644 index 0000000000..04d8ea9cd5 --- /dev/null +++ b/modules/shelving/front/index/index.js @@ -0,0 +1,14 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + preview(shelving) { + this.selectedShelving = shelving; + this.$.summary.show(); + } +} + +ngModule.vnComponent('vnShelvingIndex', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/shelving/front/index/index.spec.js b/modules/shelving/front/index/index.spec.js new file mode 100644 index 0000000000..aad79fb0e8 --- /dev/null +++ b/modules/shelving/front/index/index.spec.js @@ -0,0 +1,39 @@ +import './index.js'; +describe('Component vnShelvingIndex', () => { + let controller; + let $window; + let shelvings = [{ + id: 1, + code: 'AAA' + }, { + id: 2, + code: 'AA1' + }, { + id: 3, + code: 'AA2' + }]; + + beforeEach(ngModule('shelving')); + + beforeEach(inject(($componentController, _$window_) => { + $window = _$window_; + const $element = angular.element(''); + controller = $componentController('vnShelvingIndex', {$element}); + })); + + describe('preview()', () => { + it('should show the dialog summary', () => { + controller.$.summary = {show: () => {}}; + jest.spyOn(controller.$.summary, 'show'); + + let event = new MouseEvent('click', { + view: $window, + bubbles: true, + cancelable: true + }); + controller.preview(event, shelvings[0]); + + expect(controller.$.summary.show).toHaveBeenCalledWith(); + }); + }); +}); diff --git a/modules/shelving/front/index/locale/es.yml b/modules/shelving/front/index/locale/es.yml new file mode 100644 index 0000000000..4d30f4cee1 --- /dev/null +++ b/modules/shelving/front/index/locale/es.yml @@ -0,0 +1,2 @@ +Parking: Parking +Priority: Prioridad \ No newline at end of file diff --git a/modules/shelving/front/log/index.html b/modules/shelving/front/log/index.html new file mode 100644 index 0000000000..8f0e6851cb --- /dev/null +++ b/modules/shelving/front/log/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/shelving/front/log/index.js b/modules/shelving/front/log/index.js new file mode 100644 index 0000000000..588e0995af --- /dev/null +++ b/modules/shelving/front/log/index.js @@ -0,0 +1,7 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +ngModule.vnComponent('vnShelvingLog', { + template: require('./index.html'), + controller: Section, +}); diff --git a/modules/shelving/front/log/locale/es.yml b/modules/shelving/front/log/locale/es.yml new file mode 100644 index 0000000000..c572b78d18 --- /dev/null +++ b/modules/shelving/front/log/locale/es.yml @@ -0,0 +1 @@ +Changed by: Cambiado por \ No newline at end of file diff --git a/modules/shelving/front/main/index.html b/modules/shelving/front/main/index.html new file mode 100644 index 0000000000..3f3cc718b5 --- /dev/null +++ b/modules/shelving/front/main/index.html @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/modules/shelving/front/main/index.js b/modules/shelving/front/main/index.js new file mode 100644 index 0000000000..96689fbd98 --- /dev/null +++ b/modules/shelving/front/main/index.js @@ -0,0 +1,29 @@ +import ngModule from '../module'; +import ModuleMain from 'salix/components/module-main'; + +export default class Shelving extends ModuleMain { + constructor($element, $) { + super($element, $); + this.filter = { + include: [ + {relation: 'parking'} + ], + }; + } + + exprBuilder(param, value) { + switch (param) { + case 'search': + return {code: {like: `%${value}%`}}; + case 'parkingFk': + case 'userFk': + case 'isRecyclable': + return {[param]: value}; + } + } +} + +ngModule.vnComponent('vnShelving', { + controller: Shelving, + template: require('./index.html') +}); diff --git a/modules/shelving/front/main/index.spec.js b/modules/shelving/front/main/index.spec.js new file mode 100644 index 0000000000..dcfa912bcb --- /dev/null +++ b/modules/shelving/front/main/index.spec.js @@ -0,0 +1,19 @@ +import './index'; + +describe('component vnShelving', () => { + let controller; + + beforeEach(ngModule('shelving')); + + beforeEach(inject($componentController => { + controller = $componentController('vnShelving', {$element: null}); + })); + + describe('exprBuilder()', () => { + it('should search by code', () => { + let expr = controller.exprBuilder('search', 'UXN'); + + expect(expr).toEqual({code: {like: '%UXN%'}},); + }); + }); +}); diff --git a/modules/shelving/front/main/locale/es.yml b/modules/shelving/front/main/locale/es.yml new file mode 100644 index 0000000000..4c39469cee --- /dev/null +++ b/modules/shelving/front/main/locale/es.yml @@ -0,0 +1 @@ +Search shelving by code, parking or worker: Busca carros por código, parking o trabajador \ No newline at end of file diff --git a/modules/shelving/front/module.js b/modules/shelving/front/module.js new file mode 100644 index 0000000000..8ba261ead9 --- /dev/null +++ b/modules/shelving/front/module.js @@ -0,0 +1,3 @@ +import {ng} from 'core/vendor'; + +export default ng.module('shelving', ['salix']); diff --git a/modules/shelving/front/routes.json b/modules/shelving/front/routes.json new file mode 100644 index 0000000000..b99ca4caca --- /dev/null +++ b/modules/shelving/front/routes.json @@ -0,0 +1,70 @@ +{ + "module": "shelving", + "name": "Shelvings", + "icon" : "contact_support", + "dependencies": ["worker"], + "validations" : true, + "menus": { + "main": [ + {"state": "shelving.index", "icon": "contact_support"} + ], + "card": [ + {"state": "shelving.card.basicData", "icon": "settings"}, + {"state": "shelving.card.log", "icon": "history"} + ] + }, + "keybindings": [ + {"key": "s", "state": "shelving.index"} + ], + "routes": [ + { + "url": "/shelving", + "state": "shelving", + "abstract": true, + "component": "vn-shelving", + "description": "Shelvings" + }, + { + "url": "/index?q", + "state": "shelving.index", + "component": "vn-shelving-index", + "description": "Shelvings" + }, + { + "url": "/create", + "state": "shelving.create", + "component": "vn-shelving-create", + "description": "New shelving" + }, + { + "url": "/:id", + "state": "shelving.card", + "abstract": true, + "component": "vn-shelving-card" + }, + { + "url": "/summary", + "state": "shelving.card.summary", + "component": "vn-shelving-summary", + "description": "Summary", + "params": { + "shelving": "$ctrl.shelving" + } + }, + { + "url": "/basic-data", + "state": "shelving.card.basicData", + "component": "vn-shelving-basic-data", + "description": "Basic data", + "params": { + "shelving": "$ctrl.shelving" + } + }, + { + "url" : "/log", + "state": "shelving.card.log", + "component": "vn-shelving-log", + "description": "Log" + } + ] +} \ No newline at end of file diff --git a/modules/shelving/front/search-panel/index.html b/modules/shelving/front/search-panel/index.html new file mode 100644 index 0000000000..b7ca068a5b --- /dev/null +++ b/modules/shelving/front/search-panel/index.html @@ -0,0 +1,43 @@ +
+
+ + + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/modules/shelving/front/search-panel/index.js b/modules/shelving/front/search-panel/index.js new file mode 100644 index 0000000000..51b81538b7 --- /dev/null +++ b/modules/shelving/front/search-panel/index.js @@ -0,0 +1,7 @@ +import ngModule from '../module'; +import SearchPanel from 'core/components/searchbar/search-panel'; + +ngModule.vnComponent('vnShelvingSearchPanel', { + template: require('./index.html'), + controller: SearchPanel +}); diff --git a/modules/shelving/front/search-panel/locale/es.yml b/modules/shelving/front/search-panel/locale/es.yml new file mode 100644 index 0000000000..bd19b1b337 --- /dev/null +++ b/modules/shelving/front/search-panel/locale/es.yml @@ -0,0 +1 @@ +Search shelvings by code: Busca carros por código \ No newline at end of file diff --git a/modules/shelving/front/summary/index.html b/modules/shelving/front/summary/index.html new file mode 100644 index 0000000000..61e44d278d --- /dev/null +++ b/modules/shelving/front/summary/index.html @@ -0,0 +1,51 @@ + +
+ + + + {{::$ctrl.summary.code}} +
+ + +

+ + Basic data + +

+ + + + + + + + + + {{$ctrl.summary.worker.user.nickname}} + + + + + +
+
+
+ + \ No newline at end of file diff --git a/modules/shelving/front/summary/index.js b/modules/shelving/front/summary/index.js new file mode 100644 index 0000000000..10a905f1d3 --- /dev/null +++ b/modules/shelving/front/summary/index.js @@ -0,0 +1,41 @@ +import ngModule from '../module'; +import Summary from 'salix/components/summary'; +import './style.scss'; + +class Controller extends Summary { + set shelving(value) { + this._shelving = value; + this.summary = null; + if (!value) return; + + const filter = { + include: [ + {relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + } + }}, + {relation: 'parking'} + ] + }; + this.$http.get(`Shelvings/${value.id}`, {filter}) + .then(res => this.summary = res.data); + } + + get shelving() { + return this._shelving; + } +} + +ngModule.vnComponent('vnShelvingSummary', { + template: require('./index.html'), + controller: Controller, + bindings: { + shelving: '<' + } +}); diff --git a/modules/shelving/front/summary/locale/es.yml b/modules/shelving/front/summary/locale/es.yml new file mode 100644 index 0000000000..d5d14d52aa --- /dev/null +++ b/modules/shelving/front/summary/locale/es.yml @@ -0,0 +1,5 @@ +Code: Código +Parking: Parking +Priority: Prioridad +Worker: Trabajador +Recyclable: Reciclable \ No newline at end of file diff --git a/modules/shelving/front/summary/style.scss b/modules/shelving/front/summary/style.scss new file mode 100644 index 0000000000..1eb6b23239 --- /dev/null +++ b/modules/shelving/front/summary/style.scss @@ -0,0 +1,7 @@ +@import "variables"; + +vn-client-summary { + .alert span { + color: $color-alert + } +} \ No newline at end of file diff --git a/modules/ticket/back/methods/boxing/getVideoList.js b/modules/ticket/back/methods/boxing/getVideoList.js new file mode 100644 index 0000000000..cdc3555a74 --- /dev/null +++ b/modules/ticket/back/methods/boxing/getVideoList.js @@ -0,0 +1,80 @@ +const axios = require('axios'); +const https = require('https'); +const models = require('vn-loopback/server/server').models; + +module.exports = Self => { + Self.remoteMethod('getVideoList', { + description: 'Get video list of expedition id', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'Expedition id' + }, { + arg: 'from', + type: 'number', + required: false, + }, { + arg: 'to', + type: 'number', + required: false, + } + ], returns: { + type: ['Object'], + root: true + }, + http: { + path: `/getVideoList`, + verb: 'GET', + }, + }); + + Self.getVideoList = async(id, from, to, options) => { + const myOptions = {}; + console.log(id); + if (typeof options == 'object') + Object.assign(myOptions, options); + + const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions); + + const query = ` + SELECT + e.id, + ps.monitorId, + e.created + FROM expedition e + JOIN host h ON Convert(h.code USING utf8mb3) COLLATE utf8mb3_unicode_ci = e.hostFk + JOIN packingSite ps ON ps.hostFk = h.id + WHERE e.id = ?;`; + const [expedition] = await models.PackingSiteConfig.rawSql(query, [id]); + + const monitorId = '6Ou0D1bhBw'; + console.log(id, expedition); + if (!from && !expedition) return []; + let start = new Date(expedition.created); + let end = new Date(start.getTime() + (packingSiteConfig.avgBoxingTime * 1000)); + + if (from && to) { + start.setHours(from, 0, 0); + end.setHours(to, 0, 0); + } + const offset = start.getTimezoneOffset(); + start = new Date(start.getTime() - (offset * 60 * 1000)); + end = new Date(end.getTime() - (offset * 60 * 1000)); + console.log(start, end); + const videoUrl = `/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}`; + const timeUrl = `?start=${start.toISOString().split('.')[0]}&end=${end.toISOString().split('.')[0]}`; + const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}`; + console.log(url); + + console.log('try get'); + const response = await axios(url).then(res => { + return res; + }); + console.log('finish get'); + + console.log(response); + }; +}; diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index 393194f060..611f4e429b 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -35,7 +35,7 @@ module.exports = Self => { 'landed', 'warehouseInFk', 'warehouseOutFk', - 'agencyFk', + 'agencyModeFk', 'ref' ] }); @@ -56,7 +56,7 @@ module.exports = Self => { travel.warehouseOutFk, travel.warehouseInFk, travel.ref, - travel.agencyFk + travel.agencyModeFk ] ); stmts.push(stmt); @@ -76,7 +76,7 @@ module.exports = Self => { 'landed', 'warehouseInFk', 'warehouseOutFk', - 'agencyFk', + 'agencyModeFk', 'ref' ] }); diff --git a/modules/travel/back/methods/travel/extraCommunityFilter.js b/modules/travel/back/methods/travel/extraCommunityFilter.js index af6e1ec0a5..7769b7f21e 100644 --- a/modules/travel/back/methods/travel/extraCommunityFilter.js +++ b/modules/travel/back/methods/travel/extraCommunityFilter.js @@ -34,7 +34,7 @@ module.exports = Self => { description: 'The landed to date filter' }, { - arg: 'agencyFk', + arg: 'agencyModeFk', type: 'number', description: 'The agencyModeFk id' }, @@ -96,7 +96,7 @@ module.exports = Self => { case 'continent': return {'cnt.code': value}; case 'id': - case 'agencyFk': + case 'agencyModeFk': case 'warehouseOutFk': case 'warehouseInFk': case 'totalEntries': @@ -143,7 +143,7 @@ module.exports = Self => { JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN country c ON c.id = wo.countryFk LEFT JOIN continent cnt ON cnt.id = c.continentFk - JOIN agencyMode am ON am.id = t.agencyFk` + JOIN agencyMode am ON am.id = t.agencyModeFk` ); stmt.merge(conn.makeWhere(filter.where)); diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index 586b4e5aad..3fa1d65f9c 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -44,7 +44,7 @@ module.exports = Self => { description: 'The landed to date filter', http: {source: 'query'} }, { - arg: 'agencyFk', + arg: 'agencyModeFk', type: 'number', description: 'The agencyModeFk id', http: {source: 'query'} @@ -102,7 +102,7 @@ module.exports = Self => { case 'landedTo': return {'t.landed': {lte: value}}; case 'id': - case 'agencyFk': + case 'agencyModeFk': case 'warehouseOutFk': case 'warehouseInFk': case 'totalEntries': @@ -124,7 +124,7 @@ module.exports = Self => { t.landed, t.warehouseInFk, t.warehouseOutFk, - t.agencyFk, + t.agencyModeFk, t.ref, t.isDelivered, t.isReceived, @@ -137,7 +137,7 @@ module.exports = Self => { wout.name warehouseOutName, cnt.code continent FROM vn.travel t - JOIN vn.agencyMode am ON am.id = t.agencyFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk JOIN vn.warehouse win ON win.id = t.warehouseInFk JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk JOIN warehouse wo ON wo.id = t.warehouseOutFk diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index 9a9649d842..d888d80c1d 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -32,9 +32,9 @@ module.exports = Self => { t.warehouseOutFk, t.landed, t.shipped, - t.agencyFk + t.agencyModeFk FROM travel t - WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); + WHERE t.agencyModeFk = ? LIMIT 50)`, [agencyModeFk]); stmts.push(stmt); stmt = new ParameterizedSQL(` @@ -44,10 +44,10 @@ module.exports = Self => { t.warehouseOutFk, (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) FROM tmp.travel t - WHERE t.agencyFk + WHERE t.agencyModeFk ORDER BY id DESC LIMIT 50) AS dayDuration FROM tmp.travel t - WHERE t.agencyFk + WHERE t.agencyModeFk ORDER BY t.id DESC LIMIT 1`); const avgDaysIndex = stmts.push(stmt) - 1; diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index aa92fa3086..2e79ff193b 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -71,7 +71,7 @@ describe('Travel cloneWithEntries()', () => { expect(newTravel.ref).toEqual('fifth travel'); expect(newTravel.warehouseInFk).toEqual(warehouseThree); expect(newTravel.warehouseOutFk).toEqual(warehouseThree); - expect(newTravel.agencyFk).toEqual(agencyModeOne); + expect(newTravel.agencyModeFk).toEqual(agencyModeOne); expect(travelEntries.length).toBeGreaterThan(0); }); }); diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index b74160efe1..3693aae82a 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -70,10 +70,10 @@ describe('Travel extraCommunityFilter()', () => { expect(result.length).toEqual(3); }); - it('should return the travel matching "agencyFk"', async() => { + it('should return the travel matching "agencyModeFk"', async() => { const ctx = { args: { - agencyFk: 1 + agencyModeFk: 1 } }; diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index 95330e2636..c20b7b0bf1 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -44,17 +44,14 @@ "type": "number" }, "agencyModeFk": { - "type": "number", - "mysql": { - "columnName": "agencyFk" - } + "type": "number" } }, "relations": { "agency": { "type": "belongsTo", "model": "AgencyMode", - "foreignKey": "agencyFk" + "foreignKey": "agencyModeFk" }, "warehouseIn": { "type": "belongsTo", diff --git a/modules/travel/front/descriptor-menu/index.js b/modules/travel/front/descriptor-menu/index.js index 25922815e9..0630bb618e 100644 --- a/modules/travel/front/descriptor-menu/index.js +++ b/modules/travel/front/descriptor-menu/index.js @@ -25,7 +25,7 @@ class Controller extends Section { 'shipped', 'landed', 'totalEntries', - 'agencyFk', + 'agencyModeFk', 'warehouseInFk', 'warehouseOutFk', 'cargoSupplierFk' @@ -64,7 +64,7 @@ class Controller extends Section { onCloneAccept() { const params = JSON.stringify({ ref: this.travel.ref, - agencyModeFk: this.travel.agencyFk, + agencyModeFk: this.travel.agencyModeFk, shipped: this.travel.shipped, landed: this.travel.landed, warehouseInFk: this.travel.warehouseInFk, diff --git a/modules/travel/front/descriptor-menu/index.spec.js b/modules/travel/front/descriptor-menu/index.spec.js index 4ca93a6d61..40319e8e20 100644 --- a/modules/travel/front/descriptor-menu/index.spec.js +++ b/modules/travel/front/descriptor-menu/index.spec.js @@ -18,7 +18,7 @@ describe('Travel Component vnTravelDescriptorMenu', () => { controller.travel = { ref: 'the ref', - agencyFk: 'the agency', + agencyModeFk: 'the agency', shipped: 'the shipped date', landed: 'the landing date', warehouseInFk: 'the receiver warehouse', @@ -29,7 +29,7 @@ describe('Travel Component vnTravelDescriptorMenu', () => { const params = JSON.stringify({ ref: controller.travel.ref, - agencyModeFk: controller.travel.agencyFk, + agencyModeFk: controller.travel.agencyModeFk, shipped: controller.travel.shipped, landed: controller.travel.landed, warehouseInFk: controller.travel.warehouseInFk, diff --git a/modules/travel/front/descriptor/index.js b/modules/travel/front/descriptor/index.js index dc19f68af8..b1f2f53bed 100644 --- a/modules/travel/front/descriptor/index.js +++ b/modules/travel/front/descriptor/index.js @@ -14,9 +14,9 @@ class Controller extends Descriptor { let travelFilter; const travel = this.travel; - if (travel && travel.agencyFk) { + if (travel && travel.agencyModeFk) { travelFilter = this.travel && JSON.stringify({ - agencyFk: this.travel.agencyFk + agencyModeFk: this.travel.agencyModeFk }); } return travelFilter; diff --git a/modules/travel/front/extra-community-search-panel/index.html b/modules/travel/front/extra-community-search-panel/index.html index 8e51acc15a..ab1e88891b 100644 --- a/modules/travel/front/extra-community-search-panel/index.html +++ b/modules/travel/front/extra-community-search-panel/index.html @@ -29,7 +29,7 @@ diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 8510cf3282..27a7000833 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -11,7 +11,7 @@ Id Reference - Agency + Agency Warehouse Out Shipped Delivered diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 5cae6fa061..50036831ff 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -10,7 +10,7 @@ export default class Controller extends Section { onCloneAccept(travel) { const params = JSON.stringify({ ref: travel.ref, - agencyModeFk: travel.agencyFk, + agencyModeFk: travel.agencyModeFk, shipped: travel.shipped, landed: travel.landed, warehouseInFk: travel.warehouseInFk, @@ -44,7 +44,7 @@ export default class Controller extends Section { case 'landed': return {'t.landed': {between: this.dateRange(value)}}; case 'id': - case 'agencyFk': + case 'agencyModeFk': case 'warehouseOutFk': case 'warehouseInFk': case 'totalEntries': diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index 1b2ab0a879..9abe46a644 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -35,11 +35,11 @@ describe('Travel Component vnTravelIndex', () => { const travel = { ref: 1, - agencyFk: 1 + agencyModeFk: 1 }; const travelParams = { ref: travel.ref, - agencyModeFk: travel.agencyFk + agencyModeFk: travel.agencyModeFk }; const queryParams = JSON.stringify(travelParams); controller.onCloneAccept(travel); diff --git a/modules/travel/front/search-panel/index.html b/modules/travel/front/search-panel/index.html index 8d4edec1ac..2e9c796c32 100644 --- a/modules/travel/front/search-panel/index.html +++ b/modules/travel/front/search-panel/index.html @@ -29,7 +29,7 @@ diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index f7a3443585..3d41707ce7 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -49,6 +49,9 @@ }, "labelerFk": { "type" : "number" + }, + "mobileExtension": { + "type" : "number" } }, "relations": { diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index cbe6831852..5a3acdde59 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -25,10 +25,18 @@ + + + + - - + + - - + + - + + + +

User data

diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index 3cdb2c36f1..c2ad107d5e 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -34,7 +34,7 @@ class Controller extends Summary { }, { relation: 'client', - scope: {fields: ['fi']} + scope: {fields: ['fi', 'phone']} }, { relation: 'boss', diff --git a/modules/worker/front/summary/locale/es.yml b/modules/worker/front/summary/locale/es.yml new file mode 100644 index 0000000000..e9c8e55836 --- /dev/null +++ b/modules/worker/front/summary/locale/es.yml @@ -0,0 +1,3 @@ +Business phone: Teléfono de empresa +Personal phone: Teléfono personal +Mobile extension: Extensión móvil \ No newline at end of file diff --git a/modules/zone/back/methods/zone/exclusionGeo.js b/modules/zone/back/methods/zone/exclusionGeo.js new file mode 100644 index 0000000000..5026c58c55 --- /dev/null +++ b/modules/zone/back/methods/zone/exclusionGeo.js @@ -0,0 +1,64 @@ + +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('exclusionGeo', { + description: 'Exclude a geo from a zone', + accepts: [ + { + arg: 'zoneFk', + type: 'number', + description: 'The zone id' + }, + { + arg: 'date', + type: 'date', + description: 'The date to exclude' + }, + { + arg: 'geoIds', + type: ['number'], + 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 myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!geoIds[0]) throw new UserError(`You must select a location`); + + const newZoneExclusion = await models.ZoneExclusion.create({ + zoneFk: zoneFk, + dated: date + }, myOptions); + + const promises = []; + + for (const geoId of geoIds) { + const newZoneExclusionGeo = await models.ZoneExclusionGeo.create({ + zoneExclusionFk: newZoneExclusion.id, + geoFk: geoId + }, myOptions); + + promises.push(newZoneExclusionGeo); + } + + const newZoneExclusionGeos = await Promise.all(promises); + + return newZoneExclusionGeos; + }; +}; diff --git a/modules/zone/back/methods/zone/getEventsFiltered.js b/modules/zone/back/methods/zone/getEventsFiltered.js index 316652fa3b..b7875785df 100644 --- a/modules/zone/back/methods/zone/getEventsFiltered.js +++ b/modules/zone/back/methods/zone/getEventsFiltered.js @@ -56,12 +56,23 @@ module.exports = Self => { [zoneFk, started, ended, started, ended, started, ended, started, ended], myOptions); query = ` - SELECT * - FROM vn.zoneExclusion - WHERE zoneFk = ? - AND dated BETWEEN ? AND ?;`; + SELECT e.* + FROM vn.zoneExclusion e + LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE e.zoneFk = ? + AND e.dated BETWEEN ? AND ? + AND eg.zoneExclusionFk IS NULL;`; const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); - return {events, exclusions}; + query = ` + SELECT eg.*, e.zoneFk, e.dated, e.created, e.userFk + FROM vn.zoneExclusion e + LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE e.zoneFk = ? + AND e.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/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js new file mode 100644 index 0000000000..3a345f2ce5 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -0,0 +1,41 @@ +const models = require('vn-loopback/server/server').models; + +describe('zone exclusionGeo()', () => { + const zoneId = 1; + const today = new Date(); + + it(`should show an error when location isn't selected`, async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const geoIds = []; + + await models.Zone.exclusionGeo(zoneId, today, geoIds, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toContain(`You must select a location`); + }); + + it('should create two exclusion by geo', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const geoIds = [1, 2]; + const result = await models.Zone.exclusionGeo(zoneId, today, geoIds, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js new file mode 100644 index 0000000000..9db2e24be4 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js @@ -0,0 +1,40 @@ +const models = require('vn-loopback/server/server').models; + +describe('zone updateExclusionGeo()', () => { + it(`should show an error when location isn't selected`, async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const zoneId = 1; + const geoIds = []; + + await models.Zone.updateExclusionGeo(zoneId, geoIds, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toContain(`You must select a location`); + }); + + it('should delete all exclusion and then create two exclusion by geo for a zone', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const zoneId = 2; + const geoIds = [1, 2]; + const result = await models.Zone.updateExclusionGeo(zoneId, geoIds, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/zone/back/methods/zone/updateExclusionGeo.js b/modules/zone/back/methods/zone/updateExclusionGeo.js new file mode 100644 index 0000000000..237e336e08 --- /dev/null +++ b/modules/zone/back/methods/zone/updateExclusionGeo.js @@ -0,0 +1,55 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('updateExclusionGeo', { + description: 'Update the geos excluded from a zone', + accepts: [ + { + arg: 'zoneExclusionFk', + type: 'number', + description: 'The zoneExclusion id' + }, + { + arg: 'geoIds', + type: ['number'], + description: 'The geos id' + } + + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/updateExclusionGeo`, + verb: 'POST' + } + }); + + Self.updateExclusionGeo = async(zoneExclusionFk, geoIds, options) => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!geoIds[0]) throw new UserError(`You must select a location`); + + await models.ZoneExclusionGeo.destroyAll({ + zoneExclusionFk: zoneExclusionFk + }, myOptions); + + const promises = []; + + for (const geoId of geoIds) { + const params = { + zoneExclusionFk: zoneExclusionFk, + geoFk: geoId + }; + const deletedZoneExclusionGeos = models.ZoneExclusionGeo.create(params, myOptions); + promises.push(deletedZoneExclusionGeos); + } + + return Promise.all(promises); + }; +}; diff --git a/modules/zone/back/model-config.json b/modules/zone/back/model-config.json index ee555f3f4f..261a89902a 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 0000000000..816e4b650b --- /dev/null +++ b/modules/zone/back/models/zone-exclusion-geo.json @@ -0,0 +1,21 @@ +{ + "name": "ZoneExclusionGeo", + "base": "VnModel", + "options": { + "mysql": { + "table": "zoneExclusionGeo" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "zoneExclusionFk": { + "type": "number" + }, + "geoFk": { + "type": "number" + } + } +} \ No newline at end of file diff --git a/modules/zone/back/models/zone.js b/modules/zone/back/models/zone.js index ef1c8c5d95..6d5a6cdca9 100644 --- a/modules/zone/back/models/zone.js +++ b/modules/zone/back/models/zone.js @@ -8,6 +8,8 @@ module.exports = Self => { require('../methods/zone/deleteZone')(Self); require('../methods/zone/includingExpired')(Self); require('../methods/zone/getZoneClosing')(Self); + require('../methods/zone/exclusionGeo')(Self); + require('../methods/zone/updateExclusionGeo')(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 a24d10aef6..3bc7158ef5 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) { @@ -135,11 +146,13 @@ class Controller extends Component { onSelection($event, $days, $type, $weekday) { let $events = []; let $exclusions = []; + let $geoExclusions = []; for (let day of $days) { let stamp = day.getTime(); $events = $events.concat(this.days[stamp] || []); $exclusions = $exclusions.concat(this.exclusions[stamp] || []); + $geoExclusions = $geoExclusions.concat(this.geoExclusions[stamp] || []); } this.emit('selection', { @@ -148,19 +161,23 @@ class Controller extends Component { $type, $weekday, $events, - $exclusions + $exclusions, + $geoExclusions }); } 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]) + return 'geoExcluded'; + else if (this.exclusions[stamp]) + return 'excluded'; + else return ''; } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; diff --git a/modules/zone/front/calendar/index.spec.js b/modules/zone/front/calendar/index.spec.js index be002925e9..338f479178 100644 --- a/modules/zone/front/calendar/index.spec.js +++ b/modules/zone/front/calendar/index.spec.js @@ -15,6 +15,7 @@ describe('component vnZoneCalendar', () => { controller.zone = {id: 1}; controller.days = []; controller.exclusions = []; + controller.geoExclusions = []; })); describe('date() setter', () => { @@ -57,7 +58,7 @@ describe('component vnZoneCalendar', () => { }); describe('data() setter', () => { - it('should set the events and exclusions and then call the refreshEvents() method', () => { + it('should set the events, exclusions and geoExclusions and then call the refreshEvents() method', () => { jest.spyOn(controller, 'refreshEvents').mockReturnThis(); controller.data = { @@ -66,13 +67,17 @@ describe('component vnZoneCalendar', () => { }], events: [{ dated: new Date() - }] + }], + geoExclusions: [{ + dated: new Date() + }], }; expect(controller.refreshEvents).toHaveBeenCalledWith(); expect(controller.events).toBeDefined(); expect(controller.events.length).toEqual(1); expect(controller.exclusions).toBeDefined(); + expect(controller.geoExclusions).toBeDefined(); expect(Object.keys(controller.exclusions).length).toEqual(1); }); }); @@ -122,7 +127,8 @@ describe('component vnZoneCalendar', () => { $events: [], $exclusions: [], $type: 'day', - $weekday: 1 + $weekday: 1, + $geoExclusions: [], } ); }); @@ -151,5 +157,16 @@ describe('component vnZoneCalendar', () => { expect(result).toEqual('excluded'); }); + + it('should return the className "geoExcluded" for a date with geo excluded', () => { + const dated = new Date(); + + controller.geoExclusions = []; + controller.geoExclusions[dated.getTime()] = true; + + const result = controller.getClass(dated); + + expect(result).toEqual('geoExcluded'); + }); }); }); diff --git a/modules/zone/front/calendar/style.scss b/modules/zone/front/calendar/style.scss index 25b6a87d1a..38491af58e 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: $color-main; + } } } } diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index e71a1ae262..46ba87dea5 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -2,7 +2,7 @@ id="calendar" vn-id="calendar" data="data" - on-selection="$ctrl.onSelection($days, $type, $weekday, $events, $exclusions)" + on-selection="$ctrl.onSelection($days, $type, $weekday, $events, $exclusions, $geoExclusions)" on-step="$ctrl.refresh()" class="vn-w-md"> @@ -98,7 +98,7 @@ fixed-bottom-right> @@ -198,3 +198,80 @@ 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 0df16a42a2..b86330126f 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; +import './style.scss'; class Controller extends Section { constructor($element, $, vnWeekDays) { @@ -20,6 +21,16 @@ 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(() => { @@ -48,33 +59,56 @@ class Controller extends Section { : this.$t('Everyday'); } - onSelection(days, type, weekday, events, exclusions) { + onSelection(days, type, weekday, events, exclusions, exclusionGeos) { if (this.editMode == 'include') { if (events.length) - this.edit(events[0]); - else - this.create(type, days, weekday); - } else { - if (exclusions.length) - this.exclusionDelete(exclusions); - else - this.exclusionCreate(days); + return this.editInclusion(events[0]); + return this.createInclusion(type, days, weekday); + } else if (this.editMode == 'exclude') { + if (exclusions.length || exclusionGeos.length) + return this.editExclusion(exclusions[0] || {}, exclusionGeos); + return this.createExclusion(days); } } + editExclusion(exclusion, exclusionGeos) { + this.isNew = false; + this.excludeSelected = angular.copy(exclusion); + this.excludeSelected.type = exclusionGeos.length ? + 'specificLocations' : 'all'; + + this.exclusionGeos = new Set(); + if (exclusionGeos.length) { + this.excludeSelected.id = exclusionGeos[0].zoneExclusionFk; + exclusionGeos.forEach(x => this.exclusionGeos.add(x.geoFk)); + } + + this.$.excludeDialog.show(); + } + + createExclusion(days) { + this.isNew = true; + this.excludeSelected = { + type: 'all', + dated: days[0] + }; + this.exclusionGeos = new Set(); + this.$.excludeDialog.show(); + } + onEditClick(row, event) { if (event.defaultPrevented) return; - this.edit(row); + this.editInclusion(row); } - edit(row) { + editInclusion(row) { 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) { + createInclusion(type, days, weekday) { this.isNew = true; if (type == 'weekday') { @@ -92,7 +126,7 @@ class Controller extends Section { }; } - this.$.dialog.show(); + this.$.includeDialog.show(); } onIncludeResponse(response) { @@ -132,6 +166,19 @@ class Controller extends Section { } } + onExcludeResponse(response) { + const type = this.excludeSelected.type; + switch (response) { + case 'accept': { + if (type == 'all') + return this.exclusionCreate(); + return this.exclusionGeoCreate(); + } + case 'delete': + return this.exclusionDelete(this.excludeSelected); + } + } + onDeleteClick(id, event) { if (event.defaultPrevented) return; event.preventDefault(); @@ -149,31 +196,121 @@ class Controller extends Section { .then(() => this.refresh()); } - exclusionCreate(days) { - let exclusions = days.map(dated => { - return {dated}; - }); + exclusionCreate() { + const excludeSelected = this.excludeSelected; + const dated = excludeSelected.dated; + let req; - this.$http.post(this.exclusionsPath, exclusions) + if (this.isNew) + req = this.$http.post(this.exclusionsPath, [{dated}]); + if (!this.isNew) + req = this.$http.put(`${this.exclusionsPath}/${excludeSelected.id}`, {dated}); + + return req.then(() => { + this.refresh(); + }); + } + + exclusionGeoCreate() { + const excludeSelected = this.excludeSelected; + let req; + const geoIds = []; + this.exclusionGeos.forEach(id => geoIds.push(id)); + + if (this.isNew) { + const params = { + zoneFk: parseInt(this.$params.id), + date: excludeSelected.dated, + geoIds + }; + req = this.$http.post(`Zones/exclusionGeo`, params); + } else { + const params = { + zoneExclusionFk: this.excludeSelected.id, + geoIds + }; + req = this.$http.post(`Zones/updateExclusionGeo`, params); + } + return req.then(() => this.refresh()); + } + + exclusionDelete(exclusion) { + const path = `${this.exclusionsPath}/${exclusion.id}`; + return this.$http.delete(path) .then(() => this.refresh()); } - exclusionDelete(exclusions) { - let reqs = []; + set excludeSearch(value) { + this._excludeSearch = value; + if (!value) this.onSearch(); + } - for (let exclusion of exclusions) { - if (!exclusion.id) continue; - let path = `${this.exclusionsPath}/${exclusion.id}`; - reqs.push(this.$http.delete(path)); + get excludeSearch() { + return this._excludeSearch; + } + + onKeyDown(event) { + if (event.key == 'Enter') { + event.preventDefault(); + this.onSearch(); + } + } + + onSearch() { + const params = {search: this._excludeSearch}; + if (this.excludeSelected.type == 'specificLocations') { + this.$.model.applyFilter({}, params).then(() => { + const data = this.$.model.data; + this.getChecked(data); + this.$.treeview.data = data; + }); + } + } + + onFetch(item) { + const params = item ? {parentId: item.id} : null; + return this.$.model.applyFilter({}, params).then(() => { + const data = this.$.model.data; + this.getChecked(data); + return 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; } - this.$q.all(reqs) - .then(() => this.refresh()); + return a.name.localeCompare(b.name); + } + + getChecked(data) { + for (let geo of data) { + geo.checked = this.exclusionGeos.has(geo.id); + if (geo.childs) this.getChecked(geo.childs); + } + } + + onItemCheck(geoId, checked) { + if (checked) + this.exclusionGeos.add(geoId); + else + this.exclusionGeos.delete(geoId); } } 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/events/index.spec.js b/modules/zone/front/events/index.spec.js index ed2c91c31e..b4ff800d65 100644 --- a/modules/zone/front/events/index.spec.js +++ b/modules/zone/front/events/index.spec.js @@ -1,4 +1,5 @@ import './index'; +import crudModel from 'core/mocks/crud-model'; describe('component vnZoneEvents', () => { let $scope; @@ -34,7 +35,8 @@ describe('component vnZoneEvents', () => { const query = `Zones/getEventsFiltered?ended=${date}&started=${date}&zoneFk=${params.zoneFk}`; const response = { events: 'myEvents', - exclusions: 'myExclusions' + exclusions: 'myExclusions', + geoExclusions: 'myGeoExclusions', }; $httpBackend.whenGET(query).respond(response); controller.refresh(); @@ -48,71 +50,129 @@ describe('component vnZoneEvents', () => { }); describe('onSelection()', () => { - it('should call the edit() method', () => { - jest.spyOn(controller, 'edit').mockReturnThis(); + it('should call the editInclusion() method', () => { + jest.spyOn(controller, 'editInclusion').mockReturnThis(); const weekday = {}; const days = []; const type = 'EventType'; const events = [{name: 'Event'}]; const exclusions = []; + const exclusionsGeo = []; controller.editMode = 'include'; - controller.onSelection(days, type, weekday, events, exclusions); + controller.onSelection(days, type, weekday, events, exclusions, exclusionsGeo); - expect(controller.edit).toHaveBeenCalledWith({name: 'Event'}); + expect(controller.editInclusion).toHaveBeenCalledWith({name: 'Event'}); }); - it('should call the create() method', () => { - jest.spyOn(controller, 'create').mockReturnThis(); + it('should call the createInclusion() method', () => { + jest.spyOn(controller, 'createInclusion').mockReturnThis(); const weekday = {dated: new Date()}; const days = [weekday]; const type = 'EventType'; const events = []; const exclusions = []; + const exclusionsGeo = []; controller.editMode = 'include'; - controller.onSelection(days, type, weekday, events, exclusions); + controller.onSelection(days, type, weekday, events, exclusions, exclusionsGeo); - expect(controller.create).toHaveBeenCalledWith(type, days, weekday); + expect(controller.createInclusion).toHaveBeenCalledWith(type, days, weekday); }); - it('should call the exclusionDelete() method', () => { - jest.spyOn(controller, 'exclusionDelete').mockReturnThis(); + it('should call the editExclusion() method with exclusions', () => { + jest.spyOn(controller, 'editExclusion').mockReturnThis(); const weekday = {}; const days = []; const type = 'EventType'; const events = []; - const exclusions = [{id: 1}]; - controller.editMode = 'delete'; - controller.onSelection(days, type, weekday, events, exclusions); + const exclusions = [{name: 'Exclusion'}]; + const exclusionsGeo = []; + controller.editMode = 'exclude'; + controller.onSelection(days, type, weekday, events, exclusions, exclusionsGeo); - expect(controller.exclusionDelete).toHaveBeenCalledWith(exclusions); + expect(controller.editExclusion).toHaveBeenCalled(); }); - it('should call the exclusionCreate() method', () => { - jest.spyOn(controller, 'exclusionCreate').mockReturnThis(); + it('should call the editExclusion() method with exclusionsGeo', () => { + jest.spyOn(controller, 'editExclusion').mockReturnThis(); + + const weekday = {}; + const days = []; + const type = 'EventType'; + const events = []; + const exclusions = []; + const exclusionsGeo = [{name: 'GeoExclusion'}]; + controller.editMode = 'exclude'; + controller.onSelection(days, type, weekday, events, exclusions, exclusionsGeo); + + expect(controller.editExclusion).toHaveBeenCalled(); + }); + + it('should call the createExclusion() method', () => { + jest.spyOn(controller, 'createExclusion').mockReturnThis(); const weekday = {}; const days = [{dated: new Date()}]; const type = 'EventType'; const events = []; const exclusions = []; - controller.editMode = 'delete'; - controller.onSelection(days, type, weekday, events, exclusions); + const exclusionsGeo = []; + controller.editMode = 'exclude'; + controller.onSelection(days, type, weekday, events, exclusions, exclusionsGeo); - expect(controller.exclusionCreate).toHaveBeenCalledWith(days); + expect(controller.createExclusion).toHaveBeenCalledWith(days); }); }); - describe('create()', () => { - it('shoud set the selected property and then call the dialog show() method', () => { - controller.$.dialog = {show: jest.fn()}; + describe('editExclusion()', () => { + it('shoud set the excludeSelected.type = "specificLocations" and then call the excludeDialog show() method', () => { + controller.$.excludeDialog = {show: jest.fn()}; + + const exclusionGeos = [{id: 1}]; + const exclusions = []; + + controller.editExclusion(exclusions, exclusionGeos); + + expect(controller.excludeSelected.type).toEqual('specificLocations'); + expect(controller.$.excludeDialog.show).toHaveBeenCalledWith(); + }); + + it('shoud set the excludeSelected.type = "all" and then call the excludeDialog show() method', () => { + controller.$.excludeDialog = {show: jest.fn()}; + + const exclusionGeos = []; + const exclusions = [{id: 1}]; + + controller.editExclusion(exclusions, exclusionGeos); + + expect(controller.excludeSelected.type).toEqual('all'); + expect(controller.$.excludeDialog.show).toHaveBeenCalledWith(); + }); + }); + + describe('createExclusion()', () => { + it('shoud set the excludeSelected property and then call the excludeDialog show() method', () => { + controller.$.excludeDialog = {show: jest.fn()}; + + const days = [new Date()]; + controller.createExclusion(days); + + expect(controller.excludeSelected).toBeDefined(); + expect(controller.isNew).toBeTruthy(); + expect(controller.$.excludeDialog.show).toHaveBeenCalledWith(); + }); + }); + + describe('createInclusion()', () => { + it('shoud set the selected property and then call the includeDialog show() method', () => { + controller.$.includeDialog = {show: jest.fn()}; const type = 'weekday'; const days = [new Date()]; const weekday = 1; - controller.create(type, days, weekday); + controller.createInclusion(type, days, weekday); const selection = controller.selected; const firstWeekday = selection.wdays[weekday]; @@ -120,23 +180,23 @@ describe('component vnZoneEvents', () => { expect(selection.type).toEqual('indefinitely'); expect(firstWeekday).toBeTruthy(); expect(controller.isNew).toBeTruthy(); - expect(controller.$.dialog.show).toHaveBeenCalledWith(); + expect(controller.$.includeDialog.show).toHaveBeenCalledWith(); }); - it('shoud set the selected property with the first day and then call the dialog show() method', () => { - controller.$.dialog = {show: jest.fn()}; + it('shoud set the selected property with the first day and then call the includeDialog show() method', () => { + controller.$.includeDialog = {show: jest.fn()}; const type = 'nonListedType'; const days = [new Date()]; const weekday = 1; - controller.create(type, days, weekday); + controller.createInclusion(type, days, weekday); const selection = controller.selected; expect(selection.type).toEqual('day'); expect(selection.dated).toEqual(days[0]); expect(controller.isNew).toBeTruthy(); - expect(controller.$.dialog.show).toHaveBeenCalledWith(); + expect(controller.$.includeDialog.show).toHaveBeenCalledWith(); }); }); @@ -180,6 +240,35 @@ describe('component vnZoneEvents', () => { }); }); + describe('onExcludeResponse()', () => { + it('should call the exclusionCreate() method', () => { + jest.spyOn(controller, 'exclusionCreate').mockReturnThis(); + + controller.excludeSelected = {type: 'all'}; + controller.onExcludeResponse('accept'); + + expect(controller.exclusionCreate).toHaveBeenCalledWith(); + }); + + it('should call the exclusionGeoCreate() method', () => { + jest.spyOn(controller, 'exclusionGeoCreate').mockReturnThis(); + + controller.excludeSelected = {type: 'specificLocations'}; + controller.onExcludeResponse('accept'); + + expect(controller.exclusionGeoCreate).toHaveBeenCalledWith(); + }); + + it('should call the exclusionDelete() method', () => { + jest.spyOn(controller, 'exclusionDelete').mockReturnThis(); + + controller.excludeSelected = {id: 1, type: 'all'}; + controller.onExcludeResponse('delete'); + + expect(controller.exclusionDelete).toHaveBeenCalledWith(controller.excludeSelected); + }); + }); + describe('onDeleteResponse()', () => { it('shoud make an HTTP DELETE query and then call the refresh() method', () => { jest.spyOn(controller, 'refresh').mockReturnThis(); @@ -197,9 +286,10 @@ describe('component vnZoneEvents', () => { it('shoud make an HTTP POST query and then call the refresh() method', () => { jest.spyOn(controller, 'refresh').mockReturnThis(); - const dates = [new Date()]; + controller.excludeSelected = {}; + controller.isNew = true; $httpBackend.expect('POST', `Zones/1/exclusions`).respond({id: 1}); - controller.exclusionCreate(dates); + controller.exclusionCreate(); $httpBackend.flush(); expect(controller.refresh).toHaveBeenCalledWith(); @@ -210,25 +300,41 @@ describe('component vnZoneEvents', () => { it('shoud make an HTTP DELETE query once and then call the refresh() method', () => { jest.spyOn(controller, 'refresh').mockReturnThis(); - const exclusions = [{id: 1}]; + const exclusions = {id: 1}; const firstExclusionId = 1; - $httpBackend.when('DELETE', `Zones/1/exclusions/${firstExclusionId}`).respond(200); + $httpBackend.expectDELETE(`Zones/1/exclusions/${firstExclusionId}`).respond(200); controller.exclusionDelete(exclusions); $httpBackend.flush(); expect(controller.refresh).toHaveBeenCalledWith(); }); + }); - it('shoud make an HTTP DELETE query for every event and then call the refresh() method', () => { - jest.spyOn(controller, 'refresh').mockReturnThis(); - jest.spyOn(controller.$http, 'delete').mockReturnValue(200); + describe('onSearch()', () => { + it('should call the applyFilter() method and then set the data', () => { + jest.spyOn(controller, 'getChecked').mockReturnValue([1, 2, 3]); - const exclusions = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]; - controller.exclusionDelete(exclusions); - $scope.$apply(); + controller.$.treeview = {}; + controller.$.model = crudModel; + controller.excludeSelected = {type: 'specificLocations'}; + controller._excludeSearch = 'es'; - expect(controller.$http.delete).toHaveBeenCalledTimes(4); - expect(controller.refresh).toHaveBeenCalledWith(); + controller.onSearch(); + const treeviewData = controller.$.treeview.data; + + expect(treeviewData).toBeDefined(); + expect(treeviewData.length).toEqual(3); + }); + }); + + describe('onFetch()', () => { + it('should call the applyFilter() method and then return the model data', () => { + jest.spyOn(controller, 'getChecked').mockReturnValue([1, 2, 3]); + + controller.$.model = crudModel; + const result = controller.onFetch(); + + expect(result.length).toEqual(3); }); }); }); diff --git a/modules/zone/front/events/locale/es.yml b/modules/zone/front/events/locale/es.yml index eb581a7190..1fb114720a 100644 --- a/modules/zone/front/events/locale/es.yml +++ b/modules/zone/front/events/locale/es.yml @@ -4,3 +4,7 @@ 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 +You must select a location: Debes seleccionar una localización diff --git a/modules/zone/front/events/style.scss b/modules/zone/front/events/style.scss new file mode 100644 index 0000000000..49a6e87a6b --- /dev/null +++ b/modules/zone/front/events/style.scss @@ -0,0 +1,11 @@ +@import "variables"; + + .width{ + width: 600px + } + + .treeview{ + max-height: 300px; + overflow: auto; + } + diff --git a/modules/zone/front/location/style.scss b/modules/zone/front/location/style.scss index 2316a26225..24d685a513 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 e08f973147..7f67260da1 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", diff --git a/print/templates/reports/extra-community/extra-community.js b/print/templates/reports/extra-community/extra-community.js index 9843d6bb75..4dad5dfff6 100755 --- a/print/templates/reports/extra-community/extra-community.js +++ b/print/templates/reports/extra-community/extra-community.js @@ -12,7 +12,7 @@ module.exports = { shippedFrom: this.shippedStart, continent: this.continent, id: this.id, - agencyFk: this.agencyFk, + agencyModeFk: this.agencyModeFk, warehouseInFk: this.warehouseInFk, warehouseOutFk: this.warehouseOutFk, totalEntries: this.totalEntries, @@ -68,7 +68,7 @@ module.exports = { return {'t.ref': {like: `%${value}%`}}; case 'id': return `t.id = ${value}`; - case 'agencyFk': + case 'agencyModeFk': return `am.id = ${value}`; case 'warehouseOutFk': return `wo.id = ${value}`; @@ -101,7 +101,7 @@ module.exports = { 'continent', 'ref', 'id', - 'agencyFk', + 'agencyModeFk', 'warehouseOutFk', 'warehouseInFk', 'totalEntries', diff --git a/print/templates/reports/extra-community/sql/travels.sql b/print/templates/reports/extra-community/sql/travels.sql index 167c8b1f8b..f8a4e01423 100644 --- a/print/templates/reports/extra-community/sql/travels.sql +++ b/print/templates/reports/extra-community/sql/travels.sql @@ -19,4 +19,4 @@ FROM travel t JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN country c ON c.id = wo.countryFk LEFT JOIN continent cnt ON cnt.id = c.continentFk - JOIN agencyMode am ON am.id = t.agencyFk \ No newline at end of file + JOIN agencyMode am ON am.id = t.agencyModeFk \ No newline at end of file