Change landed on shipped change #458

This commit is contained in:
Joan Sanchez 2018-08-16 13:12:18 +02:00
parent b4321816be
commit 1786602187
8 changed files with 155 additions and 12 deletions

View File

@ -33,7 +33,7 @@
<vn-horizontal>
<vn-date-picker vn-one
label="Shipped"
model="$ctrl.ticket.shipped"
model="$ctrl.shipped"
ini-options="{enableTime: true, dateFormat: 'd-m-Y h:i'}">
</vn-date-picker>
<vn-date-picker vn-one

View File

@ -37,6 +37,16 @@ class Controller {
return this.ticket.clientFk;
}
set shipped(value) {
this.ticket.shipped = value;
this.onChangeShipped(value);
}
get shipped() {
if (this.ticket)
return this.ticket.shipped;
}
set landed(value) {
this.ticket.landed = value;
this.onChangeLanded(value);
@ -47,6 +57,21 @@ class Controller {
return this.ticket.landed;
}
onChangeShipped(value) {
let data = {
shipped: toJsonDate(value),
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
};
let query = `/api/Tickets/getLanded`;
this.$http.post(query, data).then(res => {
if (res.data && res.data.landed)
this.ticket.landed = res.data.landed;
});
}
onChangeLanded(value) {
let data = {
landed: value,

View File

@ -1,4 +1,5 @@
import './index.js';
import {toJsonDate} from 'core/src/lib/date';
describe('Ticket', () => {
describe('Component vnTicketDataStepOne', () => {
@ -38,6 +39,16 @@ describe('Ticket', () => {
});
});
describe('shipped() setter', () => {
it('should set shipped property and call onChangeShipped() method ', () => {
spyOn(controller, 'onChangeShipped');
controller.ticket = {id: 1};
controller.shipped = new Date();
expect(controller.onChangeShipped).toHaveBeenCalledWith(new Date());
});
});
describe('landed() setter', () => {
it('should set landed property and call onChangeLanded() method ', () => {
spyOn(controller, 'onChangeLanded');
@ -48,8 +59,31 @@ describe('Ticket', () => {
});
});
describe('onChangeShipped()', () => {
it('should return an available landing date', async () => {
controller._ticket = {
id: 1,
shipped: new Date(),
addressFk: 121,
agencyModeFk: 2,
warehouseFk: 1
};
let data = {
shipped: toJsonDate(new Date()),
addressFk: 121,
agencyModeFk: 2,
warehouseFk: 1
};
$httpBackend.whenPOST(`/api/Tickets/getLanded`, data).respond(200);
$httpBackend.expectPOST(`/api/Tickets/getLanded`, data);
controller.onChangeShipped(new Date());
$httpBackend.flush();
});
});
describe('onChangeLanded()', () => {
it('should call onChangeLanded method and return an available shipment date', async () => {
it('should 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};

View File

@ -0,0 +1,46 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('getLanded', {
description: 'Returns ticket available landed date',
accessType: 'READ',
accepts: [{
arg: 'data',
type: 'Object',
required: true,
description: 'shipped, addressFk, agencyModeFk, warehouseFk',
http: {source: 'body'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getLanded`,
verb: 'POST'
}
});
Self.getLanded = async data => {
let stmts = [];
let agencyMode = await Self.app.models.AgencyMode.findById(data.agencyModeFk);
stmts.push(new ParameterizedSQL(
`CALL vn.agencyHourGetLanded(?, ?, ?, ?)`, [
data.shipped,
data.addressFk,
agencyMode.agencyFk,
data.warehouseFk
]
));
let rsIndex = stmts.push(
`SELECT * FROM tmp.agencyHourGetLanded`) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);
return landed[rsIndex][0];
};
};

View File

@ -23,14 +23,23 @@ module.exports = Self => {
});
Self.getShipped = async data => {
let stmts = [];
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');
stmts.push(new ParameterizedSQL(
`CALL vn.agencyHourGetShipped(?, ?, ?)`, [
data.landed,
data.addressFk,
agencyMode.agencyFk
]
));
let rows = await Self.rawStmt(stmt);
let rsIndex = stmts.push(`
SELECT * FROM tmp.agencyHourGetShipped`) - 1;
return rows[1][0];
let sql = ParameterizedSQL.join(stmts, ';');
let shipped = await Self.rawStmt(sql);
return shipped[rsIndex][0];
};
};

View File

@ -0,0 +1,15 @@
const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket getLanded()', () => {
it('should return a landing date', async() => {
let data = {
shipped: new Date(),
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 1
};
let result = await app.models.Ticket.getLanded(data);
expect(result.landed).toBeDefined();
});
});

View File

@ -1,15 +1,28 @@
const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket getShipped()', () => {
it('should call the getShipped method', async() => {
it('should return a shipment date', async() => {
let data = {
landed: new Date(),
addressFk: 121,
agencyModeFk: 7
};
await app.models.Ticket.getShipped(data)
.then(response => {
expect(response.warehouseFk).toEqual(1);
});
let result = await app.models.Ticket.getShipped(data);
expect(result.shipped).toBeDefined();
});
it('should not return a shipment date', async() => {
let newDate = new Date();
newDate.setMonth(newDate.getMonth() - 1);
let data = {
landed: newDate,
addressFk: 121,
agencyModeFk: 7
};
let result = await app.models.Ticket.getShipped(data);
expect(result).toBeUndefined();
});
});

View File

@ -15,5 +15,6 @@ module.exports = Self => {
require('../methods/ticket/getSales')(Self);
require('../methods/ticket/getSalesPersonMana')(Self);
require('../methods/ticket/getShipped')(Self);
require('../methods/ticket/getLanded')(Self);
require('../methods/ticket/filter')(Self);
};