diff --git a/client/client/src/locale/es.yml b/client/client/src/locale/es.yml index 2c3fe8fa37..2987c51a12 100644 --- a/client/client/src/locale/es.yml +++ b/client/client/src/locale/es.yml @@ -22,6 +22,7 @@ Worker: Trabajador Send: Enviar Sample: Plantilla Credit: Crédito +Are you sure you want to delete this expedition?: Está seguro de borrar esta expedición? # Sections Clients: Clientes diff --git a/client/ticket/src/expedition/index.html b/client/ticket/src/expedition/index.html index df159b9e06..d05c9bc77c 100644 --- a/client/ticket/src/expedition/index.html +++ b/client/ticket/src/expedition/index.html @@ -1,7 +1,6 @@ @@ -33,17 +32,17 @@ vn-tooltip="Delete expedition" ng-click="$ctrl.deleteExpedition(expedition)">delete - - {{("000000"+expedition.itemFk).slice(-6)}} + + {{expedition.itemFk}} - {{::expedition.item.name}} - {{::expedition.box.name}} + {{::expedition.namePackage}} + {{::expedition.nameBox}} {{::expedition.counter}} {{::expedition.checked}} - {{::expedition.worker.firstName}} {{::expedition.worker.name}} - {{::expedition.created | date:'dd/MM/yyyy'}} + {{::expedition.firstName}} {{::expedition.nameWorker}} + {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} @@ -58,3 +57,9 @@ + + \ No newline at end of file diff --git a/client/ticket/src/expedition/index.js b/client/ticket/src/expedition/index.js index 738083a386..edcd1ca08c 100644 --- a/client/ticket/src/expedition/index.js +++ b/client/ticket/src/expedition/index.js @@ -5,33 +5,23 @@ class Controller { this.$scope = $scope; this.$stateParams = $stateParams; this.$http = $http; - this.filter = { - include: [{ - relation: 'item', - scope: { - fields: ['name'] - } - }, - { - relation: 'box', - scope: { - fields: ['name'] - } - }, - { - relation: 'worker', - scope: {fields: ['firstName', 'name']} - }] - }; } deleteExpedition(expedition) { - this.$http.delete(`/ticket/api/Expeditions/${expedition.id}`, this.params).then( - () => this.$scope.model.refresh() - ); + this.expeditionId = expedition.id; + this.$scope.deleteExpedition.show(); + } + + returnDialog(response) { + if (response === 'ACCEPT') { + this.$http.delete(`/ticket/api/Expeditions/${this.expeditionId}`).then( + () => this.$scope.model.refresh() + ); + } } showDescriptor(event, itemFk) { + if (!itemFk) return; this.$scope.descriptor.itemFk = itemFk; this.$scope.descriptor.parent = event.target; this.$scope.descriptor.show(); diff --git a/client/ticket/src/expedition/index.spec.js b/client/ticket/src/expedition/index.spec.js index eb8608e9fe..6f16228527 100644 --- a/client/ticket/src/expedition/index.spec.js +++ b/client/ticket/src/expedition/index.spec.js @@ -24,15 +24,16 @@ describe('Ticket', () => { controller = $componentController('vnTicketExpedition', {$state: $state}, {$scope: $scope}); })); - describe('deleteExpedition()', () => { + describe('returnDialog()', () => { it('should perform a DELETE query', () => { spyOn($scope.model, 'refresh'); - let expedition = {id: 1}; + let response = 'ACCEPT'; + controller.expeditionId = 1; $httpBackend.when('DELETE', `/ticket/api/Expeditions/1`).respond(200); $httpBackend.expect('DELETE', `/ticket/api/Expeditions/1`); - controller.deleteExpedition(expedition); + controller.returnDialog(response); $httpBackend.flush(); expect($scope.model.refresh).toHaveBeenCalledWith(); diff --git a/services/ticket/common/methods/expedition/filter.js b/services/ticket/common/methods/expedition/filter.js new file mode 100644 index 0000000000..fa359bf257 --- /dev/null +++ b/services/ticket/common/methods/expedition/filter.js @@ -0,0 +1,48 @@ +const ParameterizedSQL = require('vn-loopback/node_modules/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 => { + let stmt = new ParameterizedSQL( + `SELECT + e.ticketFk, + e.isBox, + i1.name namePackage, + e.counter, + e.checked, + i2.name nameBox, + e.itemFk, + w.name nameWorker, + w.firstName, + e.created + FROM + vn.expedition e + LEFT JOIN vn.item i2 ON i2.id = e.itemFk + INNER JOIN vn.item i1 ON i1.id = e.isBox + LEFT JOIN vn.worker w ON w.id = e.workerFk + `); + stmt.merge(Self.buildSuffix(filter, 'e')); + + return await Self.rawStmt(stmt); + }; +}; diff --git a/services/ticket/common/models/expedition.js b/services/ticket/common/models/expedition.js new file mode 100644 index 0000000000..9d65643737 --- /dev/null +++ b/services/ticket/common/models/expedition.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/expedition/filter')(Self); +};