feat: imprime las facturas
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-01-11 12:29:03 +01:00
parent 020068006c
commit caff537f2e
4 changed files with 67 additions and 4 deletions

View File

@ -2351,11 +2351,11 @@ INSERT INTO `vn`.`device` (`sn`, `model`, `userFk`)
VALUES
('aaa', 'android', '9');
INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
INSERT INTO `vn`.`queuePriority`(`id`, `priority`, `code`)
VALUES
(1, 'Alta'),
(2, 'Normal'),
(3, 'Baja');
(1, 'Alta', 'high'),
(2, 'Normal', 'normal'),
(3, 'Baja', 'low');
INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`, `weekMaxBreak`, `weekMaxScope`, `askInOut`)
VALUES

View File

@ -135,6 +135,18 @@ module.exports = Self => {
};
await models.InvoiceOut.invoiceEmail(ctx, invoiceOut.ref);
}
if (invoiceId && !invoiceOut.client().isToBeMailed) {
const query = `CALL vn.report_print(
'invoice',
?,
account.myUser_getId(),
JSON_OBJECT('reference', ?),
'normal'
);`;
await models.InvoiceOut.rawSql(query, [1 /* vPrinterFk */, invoiceOut.ref], myOptions);
}
return invoiceId;
};

View File

@ -0,0 +1,50 @@
const {Report} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('invoicePdf', {
description: 'Returns the invoice pdf',
accessType: 'READ',
accepts: [
{
arg: 'reference',
type: 'string',
required: true,
description: 'The invoice reference',
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: '/:reference/invoice',
verb: 'GET'
}
});
Self.invoicePdf = async(ctx, reference) => {
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('invoice', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${reference}.pdf"`];
};
};

View File

@ -15,4 +15,5 @@ module.exports = Self => {
require('../methods/invoiceOut/exportationPdf')(Self);
require('../methods/invoiceOut/invoiceCsv')(Self);
require('../methods/invoiceOut/invoiceCsvEmail')(Self);
require('../methods/invoiceOut/invoicePdf')(Self);
};