refs #6184 saveCmr #1788

Merged
guillermo merged 58 commits from 6184-saveCmr into dev 2024-02-13 06:47:06 +00:00
4 changed files with 87 additions and 19 deletions
Showing only changes of commit 3e70cb07e0 - Show all commits

View File

@ -49,8 +49,12 @@ module.exports = Self => {
try {
for (let id of ids) {
if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
const baseUrl = (ctx.req.headers.origin)
? `${ctx.req.headers.origin}/api`
: `${ctx.req.headers.referer}api`
const response = await axios.get(
`${ctx.req.headers.referer}api/Routes/${id}/cmr?access_token=${token.id}`, {
`${baseUrl}/Routes/${id}/cmr?access_token=${token.id}`, {
...myOptions,
responseType: 'arraybuffer',
});

View File

@ -0,0 +1,58 @@
{
"name": "Cmr",
"base": "VnModel",
"options": {
"mysql": {
"table": "cmr"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"truckPlate": {
"type": "number"
},
"observations": {
"type": "string"
},
"senderInstrucctions": {
"type": "string"
},
"paymentInstruccions": {
"type": "string"
},
"specialAgreements": {
"type": "string"
},
"created": {
"type": "date"
},
"companyFk": {
"type": "number"
},
"addressToFk": {
"type": "number"
},
"addressFromFk": {
"type": "number"
},
"supplierFk": {
"type": "number"
},
"packagesList": {
"type": "string"
},
"merchandiseDetail": {
"type": "string"
},
"landed": {
"type": "date"
},
"ead": {
"type": "date"
}
}
}

View File

@ -20,7 +20,7 @@ module.exports = Self => {
Self.saveCmr = async(ctx, tickets, options) => {
const models = Self.app.models;
const myOptions = {userId: ctx.req.accessToken.userId};
let tx, dms;
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -32,42 +32,43 @@ module.exports = Self => {
try {
for (const ticketId of tickets) {
const cmrFk = await models.Ticket.findOne({
where: {id: ticketId},
fields: ['cmrFk']
}, myOptions);
const ticket = await models.Ticket.findById(ticketId, myOptions);
if (cmrFk) {
const dmsTypeCmr = await models.DmsType.findOne({
where: {code: 'ticket'},
if (ticket.cmrFk) {
const dmsType = await models.DmsType.findOne({
where: {code: 'cmr'},
fields: ['id']
}, myOptions);
const hasDmsCmr = await models.TicketDms.findOne({
where: { ticketFk: ticketId },
fields: ['dmsFk'],
include: {
relation: 'dms',
fields: ['dmsFk'],
scope: {
where: { dmsTypeFk: dmsTypeCmr }
where: { dmsTypeFk: dmsType.id }
}
}
}, 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);
if (!hasDmsCmr.dms()) {
const zip = await models.Route.downloadCmrsZip(ctx, ticket.cmrFk.toString(), myOptions);
let ctxUploadFile;
ctx.req.file = Object.assign({}, zip);
ctxUploadFile = Object.assign({}, ctx);
ctxUploadFile.args = {
warehouseId: ticket.warehouseFk,
companyId: ticket.companyFk,
dmsTypeId: dmsTypeCmr.id,
dmsTypeId: dmsType.id,
reference: '',
description: `Documento comprimido - CMR ${cmrFk}`,
description: `Documento comprimido - CMR ${ticket.cmrFk}`,
hasFile: false
};
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
await models.TicketDms.create({
ticketFk: ticketId,
dmsFk: dms[0].id
}, myOptions);
}
}
}

View File

@ -139,6 +139,11 @@
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
},
"cmrFk": {
"type": "belongsTo",
"model": "Cmr",
"foreignKey": "cmrFk"
}
}
}