From 6b44686ff4a0419703a8a556c9fa979d51b820fe Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 4 Oct 2019 09:28:09 +0200 Subject: [PATCH 1/9] update zone and shipped on #1746 --- .../front/basic-data/step-one/index.html | 3 +- .../ticket/front/basic-data/step-one/index.js | 56 +++---- .../front/basic-data/step-one/index.spec.js | 157 +++++++++++++++++- 3 files changed, 179 insertions(+), 37 deletions(-) diff --git a/modules/ticket/front/basic-data/step-one/index.html b/modules/ticket/front/basic-data/step-one/index.html index 3d79b9b68..4e3cf361a 100644 --- a/modules/ticket/front/basic-data/step-one/index.html +++ b/modules/ticket/front/basic-data/step-one/index.html @@ -14,6 +14,7 @@ label="Client" show-field="name" value-field="id" + search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}" field="$ctrl.clientId" initial-data="$ctrl.clientId" order="id"> @@ -23,7 +24,7 @@ label="Address" show-field="nickname" value-field="id" - field="$ctrl.ticket.addressFk" + field="$ctrl.addressId" order="isActive DESC"> {{::isActive ? '' : 'INACTIVE'}} {{::nickname}} diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index 862a7a315..09632ba5a 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -26,10 +26,7 @@ class Controller { } get clientId() { - if (this.ticket) - return this.ticket.clientFk; - - return null; + return this.ticket && this.ticket.clientFk; } set clientId(value) { @@ -39,11 +36,24 @@ class Controller { this.onChangeClient(value); } - get warehouseId() { - if (this.ticket) - return this.ticket.warehouseFk; + get addressId() { + return this.ticket && this.ticket.addressFk; + } - return null; + set addressId(value) { + if (value != this.ticket.addressFk) { + this.ticket.addressFk = value; + this.getShipped({ + landed: this.ticket.landed, + addressFk: value, + agencyModeFk: this.ticket.agencyModeFk, + warehouseFk: this.ticket.warehouseFk + }); + } + } + + get warehouseId() { + return this.ticket && this.ticket.warehouseFk; } set warehouseId(value) { @@ -60,10 +70,7 @@ class Controller { get shipped() { - if (this.ticket) - return this.ticket.shipped; - - return null; + return this.ticket && this.ticket.shipped; } set shipped(value) { @@ -77,10 +84,7 @@ class Controller { } get landed() { - if (this.ticket) - return this.ticket.landed; - - return null; + return this.ticket && this.ticket.landed; } set landed(value) { @@ -94,17 +98,14 @@ class Controller { } get agencyModeId() { - if (this.ticket) - return this.ticket.agencyModeFk; - - return null; + return this.ticket && this.ticket.agencyModeFk; } set agencyModeId(value) { if (value != this.ticket.agencyModeFk) { this.ticket.agencyModeFk = value; - this.getShipped({ - landed: this.ticket.landed, + this.getLanded({ + shipped: this.ticket.shipped, addressFk: this.ticket.addressFk, agencyModeFk: value, warehouseFk: this.ticket.warehouseFk @@ -113,10 +114,7 @@ class Controller { } get zoneId() { - if (this.ticket) - return this.ticket.zoneFk; - - return null; + return this.ticket && this.ticket.zoneFk; } set zoneId(value) { @@ -206,9 +204,10 @@ class Controller { this.$http.get(query, {params}).then(res => { if (res.data) { this.ticket.zoneFk = res.data.zoneFk; - this.ticket.landed = res.data.landed; this.ticket.agencyModeFk = res.data.agencyModeFk; this.ticket.warehouseFk = res.data.warehouseFk; + this.ticket.landed = res.data.landed; + this.ticket.shipped = params.shipped; } else { return this.vnApp.showError( this.$translate.instant(`No delivery zone available for this landing date`) @@ -226,9 +225,10 @@ class Controller { this.$http.get(query, {params}).then(res => { if (res.data) { this.ticket.zoneFk = res.data.zoneFk; - this.ticket.shipped = res.data.shipped; this.ticket.agencyModeFk = res.data.agencyModeFk; this.ticket.warehouseFk = res.data.warehouseFk; + this.ticket.landed = params.landed; + this.ticket.shipped = res.data.shipped; } else { return this.vnApp.showError( this.$translate.instant(`No delivery zone available for this landing date`) diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js index c743ca911..89ca7f171 100644 --- a/modules/ticket/front/basic-data/step-one/index.spec.js +++ b/modules/ticket/front/basic-data/step-one/index.spec.js @@ -5,14 +5,16 @@ describe('Ticket', () => { let $state; let controller; let $httpBackend; + let $httpParamSerializer; beforeEach(angular.mock.module('ticket', $translateProvider => { $translateProvider.translations('en', {}); })); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => { $state = _$state_; $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; controller = $componentController('vnTicketBasicDataStepOne', {$state}); controller.ticket = { addressFk: 121, @@ -37,6 +39,14 @@ describe('Ticket', () => { }); }); + describe('clientId() getter', () => { + it('should return the clientFk property', () => { + controller.ticket = {id: 1, clientFk: 102}; + + expect(controller.clientId).toEqual(102); + }); + }); + describe('clientId() setter', () => { it('should set clientId property and call onChangeClient() method ', () => { spyOn(controller, 'onChangeClient'); @@ -47,6 +57,69 @@ describe('Ticket', () => { }); }); + describe('adressId() getter', () => { + it('should return the addressFk property', () => { + controller.ticket = {id: 1, addressFk: 99}; + + expect(controller.addressId).toEqual(99); + }); + }); + + describe('addressId() setter', () => { + it('should set addressId property and call getShipped() method ', () => { + spyOn(controller, 'getShipped'); + controller.ticket.addressFk = 99; + controller.addressId = 100; + const landed = new Date(); + const spectedResult = { + landed: landed, + addressFk: 100, + agencyModeFk: 7, + warehouseFk: 1 + }; + controller.landed = landed; + + expect(controller.getShipped).toHaveBeenCalledWith(spectedResult); + expect(controller.ticket.addressFk).toEqual(100); + }); + }); + + describe('warehouseId() getter', () => { + it('should return the warehouseId property', () => { + controller.ticket.warehouseFk = 2; + + expect(controller.warehouseId).toEqual(2); + }); + }); + + describe('warehouseId() setter', () => { + it('should set warehouseId property and call getShipped() method ', () => { + spyOn(controller, 'getShipped'); + controller.ticket.warehouseId = 1; + controller.warehouseId = 2; + const landed = new Date(); + const spectedResult = { + landed: landed, + addressFk: 121, + agencyModeFk: 7, + warehouseFk: 2 + }; + controller.landed = landed; + + expect(controller.getShipped).toHaveBeenCalledWith(spectedResult); + expect(controller.ticket.warehouseFk).toEqual(2); + }); + }); + + describe('shipped() getter', () => { + it('should return the shipped property', () => { + const shipped = new Date(); + controller.ticket.shipped = shipped; + + expect(controller.shipped).toEqual(shipped); + }); + }); + describe('shipped() setter', () => { it('should set shipped property and call getLanded() method ', () => { spyOn(controller, 'getLanded'); @@ -59,11 +132,19 @@ describe('Ticket', () => { }; controller.shipped = shipped; - expect(controller.getLanded).toHaveBeenCalledWith(spectedResult); }); }); + describe('landed() getter', () => { + it('should return the landed property', () => { + const landed = new Date(); + controller.ticket.landed = landed; + + expect(controller.landed).toEqual(landed); + }); + }); + describe('landed() setter', () => { it('should set shipped property and call getShipped() method ', () => { spyOn(controller, 'getShipped'); @@ -81,21 +162,29 @@ describe('Ticket', () => { }); }); + describe('agencyModeId() getter', () => { + it('should return the agencyModeFk property', () => { + controller.ticket.agencyModeFk = 66; + + expect(controller.agencyModeId).toEqual(66); + }); + }); + describe('agencyModeId() setter', () => { - it('should set agencyModeId property and call onChangeAgencyMode() method', () => { - spyOn(controller, 'getShipped'); - const landed = new Date(); + it('should set agencyModeId property and call getLanded() method', () => { + spyOn(controller, 'getLanded'); + const shipped = new Date(); const agencyModeId = 8; const spectedResult = { - landed: landed, + shipped: shipped, addressFk: 121, agencyModeFk: agencyModeId, warehouseFk: 1 }; - controller.ticket.landed = landed; + controller.ticket.shipped = shipped; controller.agencyModeId = 8; - expect(controller.getShipped).toHaveBeenCalledWith(spectedResult); + expect(controller.getLanded).toHaveBeenCalledWith(spectedResult); }); it('should do nothing if attempting to set the same agencyMode id', () => { @@ -115,6 +204,14 @@ describe('Ticket', () => { }); }); + describe('zoneId() getter', () => { + it('should return the zoneFk property', () => { + controller.ticket.zoneFk = 10; + + expect(controller.zoneId).toEqual(10); + }); + }); + describe('zoneId() setter', () => { it('should set zoneId property and call onChangeZone() method ', () => { const zoneId = 5; @@ -223,5 +320,49 @@ describe('Ticket', () => { $httpBackend.flush(); }); }); + + describe('getLanded()', () => { + it('should return an available landed date', async() => { + const shipped = new Date(); + const expectedResult = {landed: new Date()}; + const params = { + shipped: shipped, + addressFk: 121, + agencyModeFk: 7, + warehouseFk: 1 + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `/api/Agencies/getLanded?${serializedParams}`).respond(200, expectedResult); + $httpBackend.expect('GET', `/api/Agencies/getLanded?${serializedParams}`); + controller.getLanded(params); + $httpBackend.flush(); + + expect(controller.shipped).toEqual(shipped); + expect(controller.landed).toEqual(expectedResult.landed); + }); + }); + + describe('getShipped()', () => { + it('should return an available shipped date', async() => { + const landed = new Date(); + const expectedResult = {shipped: new Date()}; + const params = { + landed: landed, + addressFk: 121, + agencyModeFk: 7, + warehouseFk: 1 + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200, expectedResult); + $httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`); + controller.getShipped(params); + $httpBackend.flush(); + + expect(controller.shipped).toEqual(expectedResult.shipped); + expect(controller.landed).toEqual(landed); + }); + }); }); }); -- 2.40.1 From 9c3e7f50ec4e7063605a1369271a1186c0a8c8ad Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 4 Oct 2019 11:18:07 +0200 Subject: [PATCH 2/9] disabled autoload on stowaway model #1747 --- modules/ticket/front/descriptor/addStowaway.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/descriptor/addStowaway.html b/modules/ticket/front/descriptor/addStowaway.html index 74554d2be..3efaedc8d 100644 --- a/modules/ticket/front/descriptor/addStowaway.html +++ b/modules/ticket/front/descriptor/addStowaway.html @@ -12,7 +12,7 @@
Stowaways to add
- + Ticket id -- 2.40.1 From 05aa9151eb661966baccc3438c1dd15fe6e2e191 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 8 Oct 2019 11:41:17 +0200 Subject: [PATCH 3/9] fixed stowaway list --- modules/ticket/front/descriptor/addStowaway.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/descriptor/addStowaway.html b/modules/ticket/front/descriptor/addStowaway.html index 3efaedc8d..ee587dae0 100644 --- a/modules/ticket/front/descriptor/addStowaway.html +++ b/modules/ticket/front/descriptor/addStowaway.html @@ -6,7 +6,7 @@ + on-open="model.refresh()">
Stowaways to add
-- 2.40.1 From cc71f51f45271e834d381304812ed68969d06df8 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 8 Oct 2019 13:51:16 +0200 Subject: [PATCH 4/9] added invoiceOut alias --- modules/invoiceOut/back/methods/invoiceOut/filter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/filter.js b/modules/invoiceOut/back/methods/invoiceOut/filter.js index 001fe077d..092d298d0 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/filter.js +++ b/modules/invoiceOut/back/methods/invoiceOut/filter.js @@ -86,8 +86,9 @@ module.exports = Self => { return {'i.hasPdf': value}; case 'created': return {'i.created': value}; - case 'amount': case 'clientFk': + return {'i.clientFk': value}; + case 'amount': case 'companyFk': case 'issued': case 'dued': -- 2.40.1 From 6422d25ad616ebf7ff19924e203167210c1abef9 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 8 Oct 2019 14:36:02 +0200 Subject: [PATCH 5/9] stowaway changed to correct field name --- modules/ticket/back/methods/ticket/getPossibleStowaways.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/getPossibleStowaways.js b/modules/ticket/back/methods/ticket/getPossibleStowaways.js index f692c9f23..3565d64ab 100644 --- a/modules/ticket/back/methods/ticket/getPossibleStowaways.js +++ b/modules/ticket/back/methods/ticket/getPossibleStowaways.js @@ -45,7 +45,7 @@ module.exports = Self => { clientFk: ship.clientFk, addressFk: ship.addressFk, agencyModeFk: ship.agencyModeFk, - warehouse: {neq: ship.warehouseFk}, + warehouseFk: {neq: ship.warehouseFk}, shipped: { between: [lowestDate.toJSON(), highestDate.toJSON()] } -- 2.40.1 From d2329d989f21bf084b62f512c4cd4d654798cf16 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 08:33:22 +0200 Subject: [PATCH 6/9] added transaction options to findOne() --- back/methods/dms/uploadFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index b50aaf824..41d551f2b 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -94,7 +94,7 @@ module.exports = Self => { const models = Self.app.models; const storageConnector = Self.app.dataSources.storage.connector; const myUserId = ctx.req.accessToken.userId; - const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}); + const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}, myOptions); const args = ctx.args; const newDms = await Self.create({ -- 2.40.1 From f34742c18c5826250d929a4a6c9608018534725f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 09:58:34 +0200 Subject: [PATCH 7/9] changed warehouse from ticket id 17 --- db/dump/fixtures.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f701c4121..f00a98759 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -471,7 +471,7 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (14, 1, 2, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()), (15, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, CURDATE()), (16, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), - (17, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), + (17, 1, 7, 2, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), (18, 1, 4, 4, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, CURDATE()), (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, CURDATE()), (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), -- 2.40.1 From 144f13c40048e697295428a077286febdb43d70a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 09:59:28 +0200 Subject: [PATCH 8/9] changed state to stowaway ticket --- modules/ticket/back/models/stowaway.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/models/stowaway.js b/modules/ticket/back/models/stowaway.js index aa21e8680..780b6b31c 100644 --- a/modules/ticket/back/models/stowaway.js +++ b/modules/ticket/back/models/stowaway.js @@ -14,7 +14,7 @@ module.exports = function(Self) { code: 'BOARDING' }; let state = await models.State.findOne({where}); - let params = {ticketFk: ctx.instance.id, stateFk: state.id}; + let params = {ticketFk: ctx.instance.shipFk, stateFk: state.id}; const loopBackContext = LoopBackContext.getCurrentContext(); let httpCtx = {req: loopBackContext.active}; -- 2.40.1 From 8af7f13ac68057abf745cc0de0c6201542c7b0ec Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 14:11:23 +0200 Subject: [PATCH 9/9] #1763 insert from procedure --- modules/worker/back/methods/worker-time-control/addTime.js | 7 ++----- modules/worker/front/time-control/index.js | 4 +--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/addTime.js b/modules/worker/back/methods/worker-time-control/addTime.js index cb639f9af..9864142bf 100644 --- a/modules/worker/back/methods/worker-time-control/addTime.js +++ b/modules/worker/back/methods/worker-time-control/addTime.js @@ -33,10 +33,7 @@ module.exports = Self => { const subordinate = await Worker.findById(data.workerFk); - return Self.create({ - userFk: subordinate.userFk, - timed: data.timed, - manual: 1 - }); + return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ + subordinate.userFk, null, data.timed, true]); }; }; diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index a82fdc63d..feadfc8b3 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -238,9 +238,7 @@ class Controller { if (response === 'ACCEPT') { let data = {workerFk: this.worker.id, timed: this.newTime}; let query = `/api/WorkerTimeControls/addTime`; - this.$http.post(query, data).then(() => { - this.refresh(); - }); + this.$http.post(query, data).then(() => this.refresh()); } } } -- 2.40.1