salix/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-10-17 13:13:27 +00:00
const {Report} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('invoiceInPdf', {
description: 'Returns the delivery note pdf',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The ticket id',
http: {source: 'path'}
}
],
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: '/:id/invoiceInPdf',
verb: 'GET'
}
});
Self.invoiceInPdf = async(ctx, id) => {
2022-10-18 12:58:38 +00:00
console.log(id);
2022-10-17 13:13:27 +00:00
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
delete args.ctx;
2022-10-18 12:58:38 +00:00
console.log(args);
2022-10-17 13:13:27 +00:00
for (const param in args)
params[param] = args[param];
const report = new Report('invoiceIn', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};