From 46b59473a39bed651fce21d8436b7fe1d5837422 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 9 Sep 2021 16:06:44 +0200 Subject: [PATCH 1/5] refactor(lastbuyrefresh): moved last buy refresh calls to fixtures + some more fixtures --- db/dump/fixtures.sql | 20 ++++++++++--------- db/tests/cache/last_buy_refresh.spec.js | 14 +++++-------- .../back/methods/entry/latestBuysFilter.js | 1 - modules/item/back/methods/item/filter.js | 1 - 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8c1a3c8bc..fb71f091f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -125,14 +125,14 @@ INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) (1, 'Main Warehouse'), (2, 'Silla'); -INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasStowaway`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`) +INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasStowaway`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`, `hasProduction`) VALUES - (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 2, 1), - (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 0, 1, 2, 13), - (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1), - (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1), - (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1), - (13, 'Inventory', NULL, 1, 1, 1, 0, 0, 0, 0, 2, 1); + (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 2, 1, 1), + (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 0, 1, 2, 13, 1), + (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1, 1), + (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1, 1), + (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1, 1), + (13, 'Inventory', NULL, 1, 1, 1, 0, 0, 0, 0, 2, 1, 0); INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`, `pickingPlacement`, `path`) VALUES @@ -845,7 +845,7 @@ INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `create (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94), (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94), (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94), - (10, 7, 7, 71, CURDATE(), NULL, 1, 1, 18, NULL, 94); + (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94); INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) VALUES @@ -2408,4 +2408,6 @@ INSERT INTO `vn`.`expeditionScan` (`id`, `expeditionFk`, `scanned`, `palletFk`) (7, 7, CURDATE(), 1), (8, 8, CURDATE(), 1), (9, 9, CURDATE(), 1), - (10, 10, CURDATE(), 1); \ No newline at end of file + (10, 10, CURDATE(), 1); + +CALL `cache`.`last_buy_refresh`(FALSE); \ No newline at end of file diff --git a/db/tests/cache/last_buy_refresh.spec.js b/db/tests/cache/last_buy_refresh.spec.js index 0036e2762..71a9c3872 100644 --- a/db/tests/cache/last_buy_refresh.spec.js +++ b/db/tests/cache/last_buy_refresh.spec.js @@ -3,22 +3,18 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('last_buy_refresh()', () => { it(`should store some data on cache.last_buy`, async() => { - let stmts = []; - let stmt; + const stmts = []; stmts.push('START TRANSACTION'); - stmt = new ParameterizedSQL('CALL cache.last_buy_refresh(true)'); - stmts.push(stmt); - - let lastBuyTableIndex = stmts.push(`SELECT * FROM cache.last_buy ORDER BY item_id ASC`) - 1; + const lastBuyTableIndex = stmts.push(`SELECT * FROM cache.last_buy ORDER BY item_id ASC`) - 1; stmts.push('ROLLBACK'); - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await app.models.Ticket.rawStmt(sql); - let lastBuyTable = result[lastBuyTableIndex]; + const lastBuyTable = result[lastBuyTableIndex]; expect(lastBuyTable.length).toEqual(12); diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index d59e34e64..cbf9e3b6a 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -115,7 +115,6 @@ module.exports = Self => { const stmts = []; let stmt; - stmts.push('CALL cache.last_buy_refresh(FALSE)'); stmts.push('CALL cache.visible_refresh(@calc_id, FALSE, 1)'); stmt = new ParameterizedSQL(` diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 7063c386e..cff36a223 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -127,7 +127,6 @@ module.exports = Self => { filter = mergeFilters(filter, {where}); const stmts = []; - stmts.push('CALL cache.last_buy_refresh(FALSE)'); const stmt = new ParameterizedSQL( `SELECT i.id, From f7e2dd25e434676dafed7a495949fc6cb9db4570 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 9 Sep 2021 16:07:46 +0200 Subject: [PATCH 2/5] refactor(monitors): added column practicalHour to tickets monitor and renamed two columns --- modules/monitor/back/methods/sales-monitor/salesFilter.js | 6 ++++-- modules/monitor/front/index/locale/es.yml | 4 +++- modules/monitor/front/index/tickets/index.html | 6 ++++-- modules/monitor/front/index/tickets/index.js | 4 ---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 1546aee0e..6483a906a 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -223,7 +223,8 @@ module.exports = Self => { MINUTE(z.hour) AS zoneMinute, z.name AS zoneName, z.id AS zoneFk, - CAST(z.hour AS CHAR) AS hour + CAST(z.hour AS CHAR) AS hour, + TIME_FORMAT(zed.etc, '%H:%i') AS practicalHour FROM ticket t LEFT JOIN invoiceOut io ON t.refFk = io.ref LEFT JOIN zone z ON z.id = t.zoneFk @@ -235,7 +236,8 @@ module.exports = Self => { LEFT JOIN state st ON st.id = ts.stateFk LEFT JOIN client c ON c.id = t.clientFk LEFT JOIN worker wk ON wk.id = c.salesPersonFk - LEFT JOIN account.user u ON u.id = wk.userFk`); + LEFT JOIN account.user u ON u.id = wk.userFk + LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`); if (args.orderFk) { stmt.merge({ diff --git a/modules/monitor/front/index/locale/es.yml b/modules/monitor/front/index/locale/es.yml index 160392245..4eef3c93f 100644 --- a/modules/monitor/front/index/locale/es.yml +++ b/modules/monitor/front/index/locale/es.yml @@ -6,4 +6,6 @@ Delete selected elements: Eliminar los elementos seleccionados All the selected elements will be deleted. Are you sure you want to continue?: Todos los elementos seleccionados serán eliminados. ¿Seguro que quieres continuar? Component lack: Faltan componentes Minimize/Maximize: Minimizar/Maximizar -Problems: Problemas \ No newline at end of file +Problems: Problemas +Theoretical: Teórica +Practical: Práctica \ No newline at end of file diff --git a/modules/monitor/front/index/tickets/index.html b/modules/monitor/front/index/tickets/index.html index 2d2c5fa78..82adf2765 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -37,8 +37,9 @@ Client Salesperson Date - Hour - Closure + Prep. + Theoretical + Practical Province State Zone @@ -112,6 +113,7 @@ {{::ticket.shipped | date: 'HH:mm'}} {{::ticket.zoneLanding | date: 'HH:mm'}} + {{::ticket.practicalHour | date: 'HH:mm'}} {{::ticket.province}} Date: Fri, 10 Sep 2021 10:38:19 +0200 Subject: [PATCH 3/5] feat(closure): send to driver the route report on route closure --- db/dump/fixtures.sql | 7 ++++++- print/methods/closure.js | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8c1a3c8bc..6f667aa9b 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -6,6 +6,11 @@ ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`zoneGeo` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`ticket` AUTO_INCREMENT = 1; +INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`) + VALUES + ('TOTALLY_SECURE_TOKEN', '1209600', CURDATE(), 66); + + INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) VALUES ('1', '6'); @@ -208,7 +213,7 @@ UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10; -UPDATE `vn`.`agencyMode` SET `web` = 1; +UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com'; UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; diff --git a/print/methods/closure.js b/print/methods/closure.js index 4c6f91b58..daa2d5e7c 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -143,8 +143,24 @@ module.exports = app => { AND t.refFk IS NULL GROUP BY e.ticketFk`, [reqArgs.routeId]); const ticketIds = tickets.map(ticket => ticket.id); - await closeAll(ticketIds, reqArgs); + + // Send route report to the agency + const agencyMail = await db.findValue(` + SELECT am.reportMail + FROM route r + JOIN agencyMode am ON am.id = r.agencyModeFk + WHERE r.id = ?`, [reqArgs.routeId]); + + if (agencyMail) { + const args = Object.assign({ + routeId: reqArgs.routeId, + recipient: agencyMail + }, reqArgs); + + const email = new Email('driver-route', args); + await email.send(); + } } catch (error) { next(error); } From c442073eae6d17d607479e137874db6ce3cf64e7 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 14 Sep 2021 09:33:23 +0200 Subject: [PATCH 4/5] feat(upload-photo): added options to choose between upload from computer or external url Refs: 2627 --- .../salix/components/upload-photo/index.html | 28 +++++++++++++++-- front/salix/components/upload-photo/index.js | 30 ++++++++++++------- .../components/upload-photo/locale/es.yml | 4 ++- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/front/salix/components/upload-photo/index.html b/front/salix/components/upload-photo/index.html index 09b36d531..a9b674f42 100644 --- a/front/salix/components/upload-photo/index.html +++ b/front/salix/components/upload-photo/index.html @@ -4,7 +4,7 @@ message="Edit photo"> - + - + + + + + + + @@ -37,6 +51,14 @@ + + + + this.editor.bind({url: e.target.result}); - reader.readAsDataURL(value[0]); + if (this.uploadMethod == 'computer') { + const reader = new FileReader(); + reader.onload = e => this.editor.bind({url: e.target.result}); + reader.readAsDataURL(value); + } else if (this.uploadMethod == 'URL') + this.editor.bind({url: value}); } } diff --git a/front/salix/components/upload-photo/locale/es.yml b/front/salix/components/upload-photo/locale/es.yml index bba3a985a..fca0a4ac3 100644 --- a/front/salix/components/upload-photo/locale/es.yml +++ b/front/salix/components/upload-photo/locale/es.yml @@ -3,4 +3,6 @@ Select an image: Selecciona una imagen File name: Nombre del fichero Rotate left: Girar a la izquierda Rotate right: Girar a la derecha -Panoramic: Panorámico \ No newline at end of file +Panoramic: Panorámico +Select from computer: Seleccionar foto desde ordenador +Import from external URL: Importar desde URL externa \ No newline at end of file From 59efc240771e2d9848aecf0e4b9e976c177fe51a Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 14 Sep 2021 11:26:22 +0200 Subject: [PATCH 5/5] Updated unit test --- .../components/upload-photo/index.spec.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/front/salix/components/upload-photo/index.spec.js b/front/salix/components/upload-photo/index.spec.js index e8ac05fd4..f2aad6a5c 100644 --- a/front/salix/components/upload-photo/index.spec.js +++ b/front/salix/components/upload-photo/index.spec.js @@ -24,17 +24,30 @@ describe('Salix', () => { }); describe('viewportSelection()', () => { - it('should call to displayEditor() and updatePhotoPreview() methods', () => { - controller.displayEditor = jest.fn(); + it('should call to the updatePhotoPreview() method when uploadMethod property is set to "computer"', () => { controller.updatePhotoPreview = jest.fn(); const files = [{name: 'test.jpg'}]; controller.newPhoto.files = files; + controller.uploadMethod = 'computer'; controller.viewportSelection = {code: 'normal'}; - expect(controller.displayEditor).toHaveBeenCalledWith(); - expect(controller.updatePhotoPreview).toHaveBeenCalledWith(files); + const firstFile = files[0]; + + expect(controller.updatePhotoPreview).toHaveBeenCalledWith(firstFile); + }); + + it('should call to the updatePhotoPreview() method when uploadMethod property is set to "URL"', () => { + controller.updatePhotoPreview = jest.fn(); + + const url = 'http://gothamcity.com/batman.png'; + controller.newPhoto.url = url; + + controller.uploadMethod = 'URL'; + controller.viewportSelection = {code: 'normal'}; + + expect(controller.updatePhotoPreview).toHaveBeenCalledWith(url); }); });