diff --git a/client/ticket/src/data/step-one/index.html b/client/ticket/src/data/step-one/index.html index d0c56ec12..102bf6888 100644 --- a/client/ticket/src/data/step-one/index.html +++ b/client/ticket/src/data/step-one/index.html @@ -38,7 +38,7 @@ + model="$ctrl.landed"> { + if (res.data && res.data.shipped) + this.ticket.shipped = res.data.shipped; + }); + } + + onChangeAddress(value) { let filter = { include: [ { diff --git a/client/ticket/src/data/step-one/step-one.spec.js b/client/ticket/src/data/step-one/step-one.spec.js index 83c94e7de..b47494a6b 100644 --- a/client/ticket/src/data/step-one/step-one.spec.js +++ b/client/ticket/src/data/step-one/step-one.spec.js @@ -20,21 +20,43 @@ describe('ticket', () => { })); describe('ticket() setter', () => { - it('should set ticket property and call onChange() method ', () => { - spyOn(controller, 'onChange'); + it('should set ticket property and call onChangeAddress() method ', () => { + spyOn(controller, 'onChangeAddress'); controller.ticket = {id: 1, clientFk: 101}; - expect(controller.onChange).toHaveBeenCalledWith(101); + expect(controller.onChangeAddress).toHaveBeenCalledWith(101); }); }); describe('clientFk() setter', () => { - it('should set clientFk property and call onChange() method ', () => { - spyOn(controller, 'onChange'); + it('should set clientFk property and call onChangeAddress() method ', () => { + spyOn(controller, 'onChangeAddress'); controller.ticket = {id: 1, clientFk: 101}; controller.clientFk = 102; - expect(controller.onChange).toHaveBeenCalledWith(102); + expect(controller.onChangeAddress).toHaveBeenCalledWith(102); + }); + }); + + describe('landed() setter', () => { + it('should set landed property and call onChangeLanded() method ', () => { + spyOn(controller, 'onChangeLanded'); + controller.ticket = {id: 1}; + controller.landed = new Date(); + + expect(controller.onChangeLanded).toHaveBeenCalledWith(new Date()); + }); + }); + + describe('onChangeLanded()', () => { + it('should call onChangeLanded method and return an available shipment date', async () => { + controller._ticket = {id: 1, landed: new Date(), addressFk: 121, agencyModeFk: 2}; + let data = {landed: new Date(), addressFk: 121, agencyModeFk: 2}; + + $httpBackend.whenPOST(`/api/Tickets/getShipped`, data).respond(200); + $httpBackend.expectPOST(`/api/Tickets/getShipped`, data); + controller.onChangeLanded(new Date()); + $httpBackend.flush(); }); }); diff --git a/services/loopback/common/methods/sale/priceDifference.js b/services/loopback/common/methods/sale/priceDifference.js index b6f4855dd..e2731958d 100644 --- a/services/loopback/common/methods/sale/priceDifference.js +++ b/services/loopback/common/methods/sale/priceDifference.js @@ -59,10 +59,10 @@ module.exports = Self => { let query = `CALL vn.ticketComponentPriceDifference(?, ?, ?, ?, ?)`; let [differences] = await Self.rawSql(query, [ - ticketFk, - data.landed, - data.addressFk, - data.agencyModeFk, + ticketFk, + data.landed, + data.addressFk, + data.agencyModeFk, data.warehouseFk ]); diff --git a/services/loopback/common/methods/ticket/getShipped.js b/services/loopback/common/methods/ticket/getShipped.js new file mode 100644 index 000000000..a7650f5d5 --- /dev/null +++ b/services/loopback/common/methods/ticket/getShipped.js @@ -0,0 +1,36 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; + +module.exports = Self => { + Self.remoteMethod('getShipped', { + description: 'Returns ticket available shipment date', + accessType: 'READ', + accepts: [{ + arg: 'data', + type: 'Object', + required: true, + description: 'landed, addressFk, agencyModeFk', + http: {source: 'body'} + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getShipped`, + verb: 'POST' + } + }); + + Self.getShipped = async data => { + let agencyMode = await Self.app.models.AgencyMode.findById(data.agencyModeFk); + let params = [data.landed, data.addressFk, agencyMode.agencyFk]; + + let stmt = new ParameterizedSQL(`CALL vn.agencyHourGetShipped(?, ?, ?);`, params); + stmt.merge('SELECT * FROM tmp.agencyHourGetShipped'); + + let rows = await Self.rawStmt(stmt); + + return rows[1][0]; + }; +}; diff --git a/services/loopback/common/methods/ticket/specs/get-shipped.spec.js b/services/loopback/common/methods/ticket/specs/get-shipped.spec.js new file mode 100644 index 000000000..699337df5 --- /dev/null +++ b/services/loopback/common/methods/ticket/specs/get-shipped.spec.js @@ -0,0 +1,16 @@ +const app = require(`${servicesDir}/ticket/server/server`); + +describe('ticket getShipped()', () => { + it('should call the getShipped method', done => { + let data = { + landed: new Date(), + addressFk: 121, + agencyModeFk: 2 + }; + app.models.Ticket.getShipped(data) + .then(response => { + expect(response.warehouseFk).toEqual(1); + done(); + }); + }); +}); diff --git a/services/loopback/common/models/ticket.js b/services/loopback/common/models/ticket.js index 1eaadb5ce..a29590c2f 100644 --- a/services/loopback/common/models/ticket.js +++ b/services/loopback/common/models/ticket.js @@ -14,4 +14,5 @@ module.exports = Self => { require('../methods/ticket/getVAT')(Self); require('../methods/ticket/getSales')(Self); require('../methods/ticket/getSalesPersonMana')(Self); + require('../methods/ticket/getShipped')(Self); };