Merge branch 'test' into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
e2229b6762
|
@ -316,5 +316,6 @@
|
||||||
"The ticket doesn't exist.": "No existe el ticket.",
|
"The ticket doesn't exist.": "No existe el ticket.",
|
||||||
"Social name should be uppercase": "La razón social debe ir en mayúscula",
|
"Social name should be uppercase": "La razón social debe ir en mayúscula",
|
||||||
"Street should be uppercase": "La dirección fiscal debe ir en mayúscula",
|
"Street should be uppercase": "La dirección fiscal debe ir en mayúscula",
|
||||||
|
"The response is not a PDF": "La respuesta no es un PDF",
|
||||||
"Ticket without Route": "Ticket sin ruta"
|
"Ticket without Route": "Ticket sin ruta"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
const JSZip = require('jszip');
|
||||||
|
const axios = require('axios');
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('downloadCmrsZip', {
|
||||||
|
description: 'Download a zip file with multiple cmrs pdfs',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'ids',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The cmrs ids',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'string',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'string',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/downloadCmrsZip',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.downloadCmrsZip = async function(ctx, ids, options) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
const token = ctx.req.accessToken;
|
||||||
|
const zip = new JSZip();
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const zipConfig = await models.ZipConfig.findOne(null, myOptions);
|
||||||
|
let totalSize = 0;
|
||||||
|
ids = ids.split(',');
|
||||||
|
try {
|
||||||
|
for (let id of ids) {
|
||||||
|
if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
|
||||||
|
const response = await axios.get(
|
||||||
|
`${ctx.req.headers.referer}api/Routes/${id}/cmr?access_token=${token.id}`, {
|
||||||
|
...myOptions,
|
||||||
|
responseType: 'arraybuffer',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.headers['content-type'] !== 'application/pdf')
|
||||||
|
throw new UserError(`The response is not a PDF`);
|
||||||
|
|
||||||
|
zip.file(`${id}.pdf`, response.data, { binary: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const zipStream = zip.generateNodeStream({ streamFiles: true });
|
||||||
|
|
||||||
|
return [zipStream, 'application/zip', `filename="cmrs.zip"`];
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -22,6 +22,11 @@ module.exports = Self => {
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'The worker id',
|
description: 'The worker id',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'routeFk',
|
||||||
|
type: 'integer',
|
||||||
|
description: 'The route id',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'country',
|
arg: 'country',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -57,6 +62,7 @@ module.exports = Self => {
|
||||||
filter,
|
filter,
|
||||||
cmrFk,
|
cmrFk,
|
||||||
ticketFk,
|
ticketFk,
|
||||||
|
routeFk,
|
||||||
country,
|
country,
|
||||||
clientFk,
|
clientFk,
|
||||||
hasCmrDms,
|
hasCmrDms,
|
||||||
|
@ -66,6 +72,7 @@ module.exports = Self => {
|
||||||
const params = {
|
const params = {
|
||||||
cmrFk,
|
cmrFk,
|
||||||
ticketFk,
|
ticketFk,
|
||||||
|
routeFk,
|
||||||
country,
|
country,
|
||||||
clientFk,
|
clientFk,
|
||||||
hasCmrDms,
|
hasCmrDms,
|
||||||
|
@ -89,37 +96,38 @@ module.exports = Self => {
|
||||||
|
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
const stmt = new ParameterizedSQL(`
|
const stmt = new ParameterizedSQL(`
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM (
|
FROM (
|
||||||
SELECT t.cmrFk,
|
SELECT t.cmrFk,
|
||||||
t.id ticketFk,
|
t.id ticketFk,
|
||||||
co.country,
|
t.routeFk,
|
||||||
t.clientFk,
|
co.country,
|
||||||
IF(sub.id, TRUE, FALSE) hasCmrDms,
|
t.clientFk,
|
||||||
DATE(t.shipped) shipped
|
IF(sub.id, TRUE, FALSE) hasCmrDms,
|
||||||
FROM ticket t
|
DATE(t.shipped) shipped
|
||||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
FROM ticket t
|
||||||
JOIN state s ON s.id = ts.stateFk
|
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
JOIN alertLevel al ON al.id = s.alertLevel
|
JOIN state s ON s.id = ts.stateFk
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN alertLevel al ON al.id = s.alertLevel
|
||||||
JOIN address a ON a.id = t.addressFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
JOIN province p ON p.id = a.provinceFk
|
JOIN address a ON a.id = t.addressFk
|
||||||
JOIN country co ON co.id = p.countryFk
|
JOIN province p ON p.id = a.provinceFk
|
||||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
JOIN country co ON co.id = p.countryFk
|
||||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
JOIN warehouse w ON w.id = t.warehouseFk
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
LEFT JOIN (
|
JOIN warehouse w ON w.id = t.warehouseFk
|
||||||
SELECT td.ticketFk, d.id
|
LEFT JOIN (
|
||||||
FROM ticketDms td
|
SELECT td.ticketFk, d.id
|
||||||
JOIN dms d ON d.id = td.dmsFk
|
FROM ticketDms td
|
||||||
JOIN dmsType dt ON dt.id = d.dmsTypeFk
|
JOIN dms d ON d.id = td.dmsFk
|
||||||
WHERE dt.name = 'cmr'
|
JOIN dmsType dt ON dt.id = d.dmsTypeFk
|
||||||
) sub ON sub.ticketFk = t.id
|
WHERE dt.name = 'cmr'
|
||||||
WHERE co.code <> 'ES'
|
) sub ON sub.ticketFk = t.id
|
||||||
AND am.name <> 'ABONO'
|
WHERE co.code <> 'ES'
|
||||||
AND w.code = 'ALG'
|
AND am.name <> 'ABONO'
|
||||||
AND dm.code = 'DELIVERY'
|
AND w.code = 'ALG'
|
||||||
AND t.cmrFk
|
AND dm.code = 'DELIVERY'
|
||||||
|
AND t.cmrFk
|
||||||
) sub
|
) sub
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ module.exports = Self => {
|
||||||
require('../methods/route/downloadZip')(Self);
|
require('../methods/route/downloadZip')(Self);
|
||||||
require('../methods/route/cmr')(Self);
|
require('../methods/route/cmr')(Self);
|
||||||
require('../methods/route/getExternalCmrs')(Self);
|
require('../methods/route/getExternalCmrs')(Self);
|
||||||
|
require('../methods/route/downloadCmrsZip')(Self);
|
||||||
|
|
||||||
Self.validate('kmStart', validateDistance, {
|
Self.validate('kmStart', validateDistance, {
|
||||||
message: 'Distance must be lesser than 1000'
|
message: 'Distance must be lesser than 1000'
|
||||||
|
|
Loading…
Reference in New Issue