This commit is contained in:
parent
25fa154f60
commit
567e480e3b
|
@ -72,7 +72,7 @@
|
||||||
"The secret can't be blank": "La contraseña no puede estar en blanco",
|
"The secret can't be blank": "La contraseña no puede estar en blanco",
|
||||||
"We weren't able to send this SMS": "No hemos podido enviar el SMS",
|
"We weren't able to send this SMS": "No hemos podido enviar el SMS",
|
||||||
"This client can't be invoiced": "Este cliente no puede ser facturado",
|
"This client can't be invoiced": "Este cliente no puede ser facturado",
|
||||||
"You must provide the correction information to generate a corrective invoice": "Debes informar la información de corrección para generar una factura rectificativa",
|
"You must provide the correction information to generate a corrective invoice": "Debes informar la información de corrección para generar una factura rectificativa",
|
||||||
"This ticket can't be invoiced": "Este ticket no puede ser facturado",
|
"This ticket can't be invoiced": "Este ticket no puede ser facturado",
|
||||||
"You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado",
|
"You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado",
|
||||||
"This ticket can not be modified": "Este ticket no puede ser modificado",
|
"This ticket can not be modified": "Este ticket no puede ser modificado",
|
||||||
|
@ -336,5 +336,7 @@
|
||||||
"Incorrect pin": "Pin incorrecto.",
|
"Incorrect pin": "Pin incorrecto.",
|
||||||
"You already have the mailAlias": "Ya tienes este alias de correo",
|
"You already have the mailAlias": "Ya tienes este alias de correo",
|
||||||
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
||||||
"No tickets to invoice": "No hay tickets para facturar"
|
"No tickets to invoice": "No hay tickets para facturar",
|
||||||
|
"This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado",
|
||||||
|
"Client does not have an email": "El cliente no tiene correo"
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
const {Readable} = require('stream');
|
const {Readable} = require('stream');
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('saveCmr', {
|
Self.remoteMethodCtx('saveCmr', {
|
||||||
|
@ -22,7 +23,6 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
let tx;
|
let tx;
|
||||||
let dms;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -33,11 +33,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const dmsTypeCmr = await models.DmsType.findOne({
|
|
||||||
where: {code: 'cmr'},
|
|
||||||
fields: ['id']
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
for (const ticketId of tickets) {
|
for (const ticketId of tickets) {
|
||||||
const ticket = await models.Ticket.findById(ticketId, myOptions);
|
const ticket = await models.Ticket.findById(ticketId, myOptions);
|
||||||
|
|
||||||
|
@ -48,31 +43,35 @@ module.exports = Self => {
|
||||||
relation: 'dms',
|
relation: 'dms',
|
||||||
fields: ['dmsFk'],
|
fields: ['dmsFk'],
|
||||||
scope: {
|
scope: {
|
||||||
where: {dmsTypeFk: dmsTypeCmr.id}
|
relation: 'dmsType',
|
||||||
|
scope: {
|
||||||
|
where: {code: 'cmr'}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (!hasDmsCmr?.dms()) {
|
if (hasDmsCmr?.dms())
|
||||||
ctx.args.id = ticket.cmrFk;
|
throw new UserError('This ticket already has a cmr saved');
|
||||||
const response = await models.Route.cmr(ctx, myOptions);
|
|
||||||
const pdfStream = Readable.from(Buffer.from(response[0]));
|
|
||||||
const data = {
|
|
||||||
workerFk: ctx.req.accessToken.userId,
|
|
||||||
dmsTypeFk: dmsTypeCmr.id,
|
|
||||||
companyFk: ticket.companyFk,
|
|
||||||
warehouseFk: ticket.warehouseFk,
|
|
||||||
reference: ticket.id,
|
|
||||||
contentType: 'application/pdf',
|
|
||||||
hasFile: true
|
|
||||||
};
|
|
||||||
|
|
||||||
dms = await models.Dms.createFromStream(data, 'pdf', pdfStream, myOptions);
|
ctx.args.id = ticket.cmrFk;
|
||||||
await models.TicketDms.create({
|
const response = await models.Route.cmr(ctx, myOptions);
|
||||||
ticketFk: ticketId,
|
const pdfStream = Readable.from(Buffer.from(response[0]));
|
||||||
dmsFk: dms.id
|
const data = {
|
||||||
}, myOptions);
|
workerFk: ctx.req.accessToken.userId,
|
||||||
}
|
dmsTypeFk: dmsTypeCmr.id,
|
||||||
|
companyFk: ticket.companyFk,
|
||||||
|
warehouseFk: ticket.warehouseFk,
|
||||||
|
reference: ticket.id,
|
||||||
|
contentType: 'application/pdf',
|
||||||
|
hasFile: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const dms = await models.Dms.createFromStream(data, 'pdf', pdfStream, myOptions);
|
||||||
|
await models.TicketDms.create({
|
||||||
|
ticketFk: ticketId,
|
||||||
|
dmsFk: dms.id
|
||||||
|
}, myOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -70,7 +70,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
if (ticketDms.dms()?.id) return true;
|
if (ticketDms?.dms()?.id) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createGestDoc(id) {
|
async function createGestDoc(id) {
|
||||||
|
|
Loading…
Reference in New Issue