Tarea #354 seccion ticket.line menu de mover lineas

This commit is contained in:
gerard 2018-06-28 15:24:27 +02:00
parent accd66f63a
commit 4bc391e083
6 changed files with 124 additions and 2 deletions

View File

@ -0,0 +1,27 @@
module.exports = Self => {
Self.remoteMethod('getFirstShipped', {
description: 'Returns the first shipped and landed possible for params',
accessType: '',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'agencyModeFk, addressFk, warehouseFk'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getFirstShipped`,
verb: 'get'
}
});
Self.getFirstShipped = async params => {
let query = `CALL vn.agencyHourGetFirstShipped(?, ?, ?)`;
let [result] = await Self.rawSql(query, [params.agencyModeFk, params.addressFk, params.warehouseFk]);
return result[0];
};
};

View File

@ -0,0 +1,52 @@
module.exports = Self => {
Self.remoteMethod('moveToNewTicket', {
description: 'Change the state of a ticket',
accessType: '',
accepts: [{
arg: 'ticketParams',
type: 'object',
required: true,
description: '[sales IDs], newTicketFk, actualTicketFk',
http: {source: 'body'}
}, {
arg: 'sales',
type: 'object',
required: true,
description: '[sales IDs]',
http: {source: 'body'}
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/moveToNewTicket`,
verb: 'post'
}
});
Self.moveToNewTicket = async params => {
let model = Self.app.models;
let thisTicketIsEditable = await model.Ticket.isEditable(params.ticket.oldTicketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
let travelDates = await model.Agency.getFirstShipped(params.ticket);
console.log(travelDates);
let newTicketParams = {
clientFk: params.ticket.clientFk,
addressFk: params.ticket.addressFk,
agencyModeFk: params.ticket.agencyModeFk,
warehouseFk: params.ticket.warehouseFk,
shipped: travelDates.vShipped,
landed: travelDates.vLanded
};
let newTicket = await model.Ticket.create(newTicketParams);
for (let i = 0; i < params.sales.length; i++) {
await model.Sale.update({id: params.sales[i].id}, {ticketFk: newTicket.id});
}
return newTicket;
};
};

View File

@ -26,7 +26,7 @@ module.exports = Self => {
let newTicketIsEditable = await Self.app.models.Ticket.isEditable(params.newTicketFk);
if (!newTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new Error(`The sales of that ticket can't be modified`);
for (let i = 0; i < params.sales.length; i++) {
await Self.app.models.Sale.update({id: params.sales[i].id}, {ticketFk: params.newTicketFk});

View File

@ -0,0 +1,40 @@
module.exports = Self => {
Self.remoteMethod('create', {
description: 'Create a newticket and returns the new ID',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed',
http: {source: 'body'}
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/create`,
verb: 'post'
}
});
Self.create = async params => {
let existsAddress = await Self.app.models.Address.findOne({where: {id: params.addressFk, clientFk: params.clientFk}});
if (!existsAddress)
throw new Error(`This address doesn't exist`);
let query = `CALL vn.ticketListCreate(?, ?, ?, ?, ?, ?, ?, ?);`;
let result = await Self.rawSql(query, [
params.clientFk,
params.shipped,
params.wharehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed
]);
return result;
};
};

View File

@ -1,3 +1,5 @@
module.exports = Self => {
Self.defineScope({where: {isManaged: {neq: 0}}});
//require('../methods/agency/sendsThatDay')(Self);
require('../methods/agency/getFirstShipped')(Self);
};

View File

@ -7,9 +7,10 @@ module.exports = Self => {
require('../methods/ticket/getTotal')(Self);
require('../methods/ticket/getTaxes')(Self);
require('../methods/ticket/componentUpdate')(Self);
// require('../methods/ticket/create')(Self);
require('../methods/ticket/create')(Self);
require('../methods/ticket/isEditable')(Self);
require('../methods/ticket/threeLastActive')(Self);
require('../methods/ticket/deleted')(Self);
require('../methods/ticket/getVAT')(Self);
require('../methods/ticket/getSalesPersonMana')(Self);
};