refs #6184 saveCmr #1788
|
@ -31,38 +31,39 @@ 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);
|
||||||
|
|
||||||
if (ticket.cmrFk) {
|
if (ticket.cmrFk) {
|
||||||
const dmsType = await models.DmsType.findOne({
|
|
||||||
where: {code: 'cmr'},
|
|
||||||
fields: ['id']
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const hasDmsCmr = await models.TicketDms.findOne({
|
const hasDmsCmr = await models.TicketDms.findOne({
|
||||||
where: { ticketFk: ticketId },
|
where: { ticketFk: ticketId },
|
||||||
include: {
|
include: {
|
||||||
relation: 'dms',
|
relation: 'dms',
|
||||||
fields: ['dmsFk'],
|
fields: ['dmsFk'],
|
||||||
scope: {
|
scope: {
|
||||||
where: { dmsTypeFk: dmsType.id }
|
where: { dmsTypeFk: dmsTypeCmr.id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (!hasDmsCmr.dms()) {
|
if (!hasDmsCmr.dms()) {
|
||||||
const zip = await models.Route.downloadCmrsZip(ctx, ticket.cmrFk.toString(), myOptions);
|
const zip = await models.Route.downloadCmrsZip(ctx, ticket.cmrFk.toString(), myOptions);
|
||||||
let ctxUploadFile;
|
|
||||||
ctx.req.file = Object.assign({}, zip);
|
ctx.req.file = Object.assign({}, zip);
|
||||||
ctxUploadFile = Object.assign({}, ctx);
|
const ctxUploadFile = {
|
||||||
ctxUploadFile.args = {
|
...ctx,
|
||||||
warehouseId: ticket.warehouseFk,
|
args: {
|
||||||
companyId: ticket.companyFk,
|
warehouseId: ticket.warehouseFk,
|
||||||
dmsTypeId: dmsType.id,
|
companyId: ticket.companyFk,
|
||||||
reference: '',
|
dmsTypeId: dmsTypeCmr.id,
|
||||||
description: `${ticket.cmrFk} - ${ticket.id}`,
|
reference: ticket.id,
|
||||||
hasFile: false
|
description: `${ticket.cmrFk} - ${ticket.id}`,
|
||||||
|
hasFile: false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||||
await models.TicketDms.create({
|
await models.TicketDms.create({
|
||||||
|
|
Loading…
Reference in New Issue