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

View File

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