refs #6184 saveCmr #1788
|
@ -0,0 +1,82 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('saveCmr', {
|
||||
description: 'Save sign',
|
||||
accessType: 'WRITE',
|
||||
accepts:
|
||||
[
|
||||
{
|
||||
arg: 'tickets',
|
||||
type: ['number'],
|
||||
required: true,
|
||||
description: 'The tickets'
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/saveCmr`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.saveCmr = async(ctx, tickets, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
for (const ticketId of tickets) {
|
||||
const cmrFk = await models.Ticket.findOne(
|
||||
{where: {id: ticketId},
|
||||
guillermo marked this conversation as resolved
Outdated
|
||||
fields: ['cmrFk']
|
||||
}, myOptions);
|
||||
|
||||
if (cmrFk) {
|
||||
const dmsTypeCmr = await models.DmsType.findOne({
|
||||
where: {code: 'ticket'},
|
||||
fields: ['id']
|
||||
}, myOptions);
|
||||
|
||||
const hasDmsCmr = await models.TicketDms.findOne({
|
||||
where: { ticketFk: ticketId },
|
||||
fields: ['dmsFk'],
|
||||
include: {
|
||||
relation: 'dms',
|
||||
scope: {
|
||||
where: { dmsTypeFk: dmsTypeCmr }
|
||||
}
|
||||
}
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
const const
guillermo
commented
En eixe cas te que ser let, fijat baix. En eixe cas te que ser let, fijat baix.
Per a que siga const he tingut que juntar-ho.
|
||||
}, myOptions);
|
||||
|
||||
if (!hasDmsCmr) {
|
||||
const zip = await models.Route.downloadCmrsZip(ctx, cmr, myOptions);
|
||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||
const ctxUploadFile = Object.assign({}, zip);
|
||||
ctxUploadFile.args = {
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
si es dms, en reference posa ticket.cmrFk si es dms, en reference posa ticket.cmrFk
|
||||
warehouseId: ticket.warehouseFk,
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
al ser el tipo cmr, no es neceario poner cmr, pueden buscar por tipo al ser el tipo cmr, no es neceario poner cmr, pueden buscar por tipo
quitar texto en español.
Propuesta: poner cmr: cmrFk, ticket: ticketFk
|
||||
companyId: ticket.companyFk,
|
||||
dmsTypeId: dmsTypeCmr.id,
|
||||
reference: '',
|
||||
description: `Documento comprimido - CMR ${cmrFk}`,
|
||||
hasFile: false
|
||||
};
|
||||
await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tx) await tx.commit();
|
||||
return;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -91,7 +91,7 @@ module.exports = Self => {
|
|||
}
|
||||
]
|
||||
}, myOptions);
|
||||
const dmsType = await models.DmsType.findOne({where: {code: 'Ticket'}, fields: ['id']}, myOptions);
|
||||
const dmsType = await models.DmsType.findOne({where: {code: 'ticket'}, fields: ['id']}, myOptions);
|
||||
const ctxUploadFile = Object.assign({}, ctx);
|
||||
if (ticket.route() === null)
|
||||
throw new UserError('Ticket without route');
|
||||
|
@ -131,6 +131,7 @@ module.exports = Self => {
|
|||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions);
|
||||
await models.Ticket.saveCmr(ticketId, myOptions);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -41,6 +41,7 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/collectionLabel')(Self);
|
||||
require('../methods/ticket/expeditionPalletLabel')(Self);
|
||||
require('../methods/ticket/saveSign')(Self);
|
||||
require('../methods/ticket/saveCmr')(Self);
|
||||
require('../methods/ticket/invoiceTickets')(Self);
|
||||
require('../methods/ticket/docuwareDownload')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Este el cree cada vegada pero es el mateix id per a tots. Pujal fora del for
El nom jo posaría dmsTypeCmr