51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
const {Report} = require('vn-print');
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('invoiceInPdf', {
|
|
description: 'Returns the invoiceIn pdf',
|
|
accessType: 'READ',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'The invoiceIn 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/invoice-in-pdf',
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.invoiceInPdf = async(ctx, id) => {
|
|
const args = Object.assign({}, ctx.args);
|
|
const params = {lang: ctx.req.getLocale()};
|
|
delete args.ctx;
|
|
|
|
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"`];
|
|
};
|
|
};
|