From caff537f2e5e832f67bd2bc5739a430a662c18ef Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 11 Jan 2023 12:29:03 +0100 Subject: [PATCH] feat: imprime las facturas --- db/dump/fixtures.sql | 8 +-- .../back/methods/invoiceOut/invoiceClient.js | 12 +++++ .../back/methods/invoiceOut/invoicePdf.js | 50 +++++++++++++++++++ modules/invoiceOut/back/models/invoice-out.js | 1 + 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 modules/invoiceOut/back/methods/invoiceOut/invoicePdf.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 1ea4fa114..3280f079f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -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 diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js index 017acf8b5..29ecd9dd9 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js @@ -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; }; diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoicePdf.js b/modules/invoiceOut/back/methods/invoiceOut/invoicePdf.js new file mode 100644 index 000000000..3194d2c79 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/invoicePdf.js @@ -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"`]; + }; +}; diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index 88adae2ef..de647254f 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -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); };