Change shipment date on landed data selection. #410

This commit is contained in:
Joan Sanchez 2018-07-24 12:14:35 +02:00
parent dc60156277
commit bea6378f6a
7 changed files with 113 additions and 14 deletions

View File

@ -38,7 +38,7 @@
</vn-date-picker>
<vn-date-picker vn-one
label="Landed"
model="$ctrl.ticket.landed">
model="$ctrl.landed">
</vn-date-picker>
<vn-autocomplete vn-one
url="/api/Companies"

View File

@ -18,7 +18,7 @@ class Controller {
if (!value || !value.id) return;
this.onChange(value.clientFk);
this.onChangeAddress(value.clientFk);
}
get ticket() {
@ -29,7 +29,7 @@ class Controller {
this.ticket.clientFk = value;
this.ticket.addressFk = null;
this.onChange(value);
this.onChangeAddress(value);
}
get clientFk() {
@ -37,7 +37,31 @@ class Controller {
return this.ticket.clientFk;
}
onChange(value) {
set landed(value) {
this.ticket.landed = value;
this.onChangeLanded(value);
}
get landed() {
if (this.ticket)
return this.ticket.landed;
}
onChangeLanded(value) {
let data = {
landed: value,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
};
let query = `/api/Tickets/getShipped`;
this.$http.post(query, data).then(res => {
if (res.data && res.data.shipped)
this.ticket.shipped = res.data.shipped;
});
}
onChangeAddress(value) {
let filter = {
include: [
{

View File

@ -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();
});
});

View File

@ -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
]);

View File

@ -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];
};
};

View File

@ -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();
});
});
});

View File

@ -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);
};