salix/modules/client/back/methods/receipt/balanceCompensationPdf.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-10-28 12:49:22 +00:00
const { Report } = require('vn-print');
module.exports = Self => {
2022-11-02 14:54:23 +00:00
Self.remoteMethodCtx('balanceCompensationPdf', {
2022-10-28 12:49:22 +00:00
description: 'Returns the the debit balances compensation pdf',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The receipt 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: {
2022-11-02 14:54:23 +00:00
path: '/:id/balance-compensation-pdf',
2022-10-28 12:49:22 +00:00
verb: 'GET'
}
});
2022-11-02 14:54:23 +00:00
Self.balanceCompensationPdf = async(ctx, id) => {
2022-10-28 12:49:22 +00:00
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
delete args.ctx;
for (const param in args)
params[param] = args[param];
2022-11-02 14:54:23 +00:00
const report = new Report('balance-compensation', params);
2022-10-28 12:49:22 +00:00
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};