diff --git a/db/changes/10451-april/00-aclExpeditionState.sql b/db/changes/10451-april/00-aclExpeditionState.sql new file mode 100644 index 000000000..d26117bbf --- /dev/null +++ b/db/changes/10451-april/00-aclExpeditionState.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES('ExpeditionState', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 2a8921926..576a0d913 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -854,18 +854,35 @@ INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPack ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, CURDATE(), 15, 90.00), ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, CURDATE(), 16, 0.00); -INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`) +INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) VALUES - (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94), - (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94), - (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94), - (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94), - (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94), - (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94), - (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, NOW(), NULL, 1, 1, 18, NULL, 94); + (1, 'En reparto', 'ON DELIVERY'), + (2, 'Entregada', 'DELIVERED'), + (3, 'Perdida', 'LOST'); + + +INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`) + VALUES + (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94, 1), + (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94, 1), + (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94, 2), + (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94, 2), + (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 3), + (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94, 3), + (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94, NULL), + (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94, 1), + (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 2), + (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94, 3); + + +INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) + VALUES + (1, CURDATE(), 1, 1, 1), + (2, CURDATE(), 2, 1, 1), + (3, CURDATE(), 3, 1, 1), + (4, CURDATE(), 3, 2, 1106), + (5, CURDATE(), 5, 1, 1106), + (6, CURDATE(), 5, 3, 1106); INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) VALUES diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js new file mode 100644 index 000000000..1483780f7 --- /dev/null +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -0,0 +1,41 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; + +module.exports = Self => { + Self.remoteMethod('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'}, + }, + ], + returns: { + type: ['object'], + root: true, + }, + http: { + path: `/filter`, + verb: 'GET', + }, + }); + + Self.filter = async(filter, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const stmt = new ParameterizedSQL( + `SELECT es.created, u.name, u.id workerFk, est.description state + FROM vn.expeditionState es + JOIN vn.expeditionStateType est ON est.id = es.typeFk + JOIN account.user u ON u.id = es.userFk + `); + stmt.merge(Self.buildSuffix(filter, 'es')); + + return Self.rawStmt(stmt, myOptions); + }; +}; diff --git a/modules/ticket/back/methods/expedition-state/specs/filter.spec.js b/modules/ticket/back/methods/expedition-state/specs/filter.spec.js new file mode 100644 index 000000000..f144606eb --- /dev/null +++ b/modules/ticket/back/methods/expedition-state/specs/filter.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('expeditionState filter()', () => { + it('should return the expedition states matching the filter', async() => { + const tx = await models.ExpeditionState.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const filter = {where: {expeditionFk: 5}}; + const response = await models.ExpeditionState.filter(filter, options); + + expect(response.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/expedition/filter.js b/modules/ticket/back/methods/expedition/filter.js index 5eb7510b7..538e19938 100644 --- a/modules/ticket/back/methods/expedition/filter.js +++ b/modules/ticket/back/methods/expedition/filter.js @@ -47,9 +47,10 @@ module.exports = Self => { e.packagingFk, es.workerFk expeditionScanWorkerFk, su.name scannerUserName, - es.scanned - FROM - vn.expedition e + es.scanned, + est.description state + FROM vn.expedition e + LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk LEFT JOIN vn.item i2 ON i2.id = e.itemFk INNER JOIN vn.item i1 ON i1.id = e.isBox LEFT JOIN vn.packaging p ON p.id = e.packagingFk diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 5d5f08694..41885ee33 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -14,6 +14,9 @@ "Expedition": { "dataSource": "vn" }, + "ExpeditionState": { + "dataSource": "vn" + }, "Packaging": { "dataSource": "vn" }, diff --git a/modules/ticket/back/models/expedition-state.js b/modules/ticket/back/models/expedition-state.js new file mode 100644 index 000000000..af76af718 --- /dev/null +++ b/modules/ticket/back/models/expedition-state.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/expedition-state/filter')(Self); +}; diff --git a/modules/ticket/back/models/expedition-state.json b/modules/ticket/back/models/expedition-state.json new file mode 100644 index 000000000..262eb2e38 --- /dev/null +++ b/modules/ticket/back/models/expedition-state.json @@ -0,0 +1,28 @@ +{ + "name": "ExpeditionState", + "base": "VnModel", + "options": { + "mysql": { + "table": "expeditionState" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "created": { + "type": "date" + }, + "expeditionFk": { + "type": "number" + }, + "typeFk": { + "type": "number" + }, + "userFk": { + "type": "number" + } + } +} diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index bdbb2c3e8..a41d368f6 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -19,10 +19,9 @@ Package type Counter externalId - Packager Created - Palletizer - Scanned + State + @@ -33,7 +32,7 @@ vn-tooltip="Delete expedition"> - {{expedition.id | zeroFill:6}} + {{expedition.id | zeroFill:6}} {{::expedition.freightItemName}} {{::expedition.counter}} {{::expedition.externalId}} - - - {{::expedition.userName | dashIfEmpty}} - - {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} + {{::expedition.state}} - - {{::expedition.scannerUserName | dashIfEmpty}} - + + - {{::expedition.scanned | date:'dd/MM/yyyy HH:mm'}} @@ -77,4 +71,44 @@ on-accept="$ctrl.onDialogAccept($data)" question="Delete expedition" message="Are you sure you want to delete this expedition?"> - \ No newline at end of file + + + + + + + + + + + State + Worker + Created + + + + + {{::expeditionState.state}} + + + {{::expeditionState.name || 'System' | translate}} + + + {{::expeditionState.created | date:'dd/MM/yyyy HH:mm'}} + + + + + + + + \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 0c395e6ce..120d89bb2 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -6,6 +6,11 @@ class Controller extends Section { return this.$http.delete(`Expeditions/${id}`) .then(() => this.$.model.refresh()); } + + showLog(expedition) { + this.expedition = expedition; + this.$.statusLog.show(); + } } ngModule.vnComponent('vnTicketExpedition', { diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 425539aef..586ef2109 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -5,10 +5,12 @@ describe('Ticket', () => { let controller; let $scope; let $httpBackend; + let $window; beforeEach(ngModule('ticket')); - beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$window_) => { + $window = _$window_; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = { @@ -30,5 +32,23 @@ describe('Ticket', () => { expect($scope.model.refresh).toHaveBeenCalledWith(); }); }); + + describe('showLog()', () => { + it('should show the popover status log', () => { + controller.$.statusLog = {show: () => {}}; + jest.spyOn(controller.$.statusLog, 'show'); + + const expedition = {id: 1}; + + const event = new MouseEvent('click', { + view: $window, + bubbles: true, + cancelable: true + }); + controller.showLog(event, expedition); + + expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + }); + }); }); }); diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml new file mode 100644 index 000000000..d23cf25af --- /dev/null +++ b/modules/ticket/front/expedition/locale/es.yml @@ -0,0 +1 @@ +Status log: Hitorial de estados \ No newline at end of file