Tarea #354 seccion ticket.line menu de mover lineas
This commit is contained in:
parent
accd66f63a
commit
4bc391e083
|
@ -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];
|
||||
};
|
||||
};
|
|
@ -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;
|
||||
};
|
||||
};
|
|
@ -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});
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
|
@ -1,3 +1,5 @@
|
|||
module.exports = Self => {
|
||||
Self.defineScope({where: {isManaged: {neq: 0}}});
|
||||
//require('../methods/agency/sendsThatDay')(Self);
|
||||
require('../methods/agency/getFirstShipped')(Self);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue