diff --git a/db/changes/10490-august/00-ACL.sql b/db/changes/10490-august/00-ACL.sql index b32a87a5a..55852a38d 100644 --- a/db/changes/10490-august/00-ACL.sql +++ b/db/changes/10490-august/00-ACL.sql @@ -3,6 +3,8 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp ('ClientConsumptionQueue', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('Ticket', 'deliveryNotePdf', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Ticket', 'deliveryNoteEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), + ('Ticket', 'deliveryNoteCsvPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Ticket', 'deliveryNoteCsvEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('Client', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Client', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('Client', 'clientWelcomeHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), @@ -24,6 +26,8 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp ('InvoiceOut', 'invoiceEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('InvoiceOut', 'exportationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), ('InvoiceOut', 'sendQueued', 'WRITE', 'ALLOW', 'ROLE', 'system'), + ('Ticket', 'invoiceCsvPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Ticket', 'invoiceCsvEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('Supplier', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Supplier', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('Travel', 'extraCommunityPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), @@ -32,7 +36,8 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp ('OsTicket', 'osTicketReportEmail', 'WRITE', 'ALLOW', 'ROLE', 'system'), ('Item', 'buyerWasteEmail', 'WRITE', 'ALLOW', 'ROLE', 'system'), ('Claim', 'claimPickupPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Claim', 'claimPickupEmail', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'); + ('Claim', 'claimPickupEmail', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), + ('Item', 'labelPdf', 'READ', 'ALLOW', 'ROLE', 'employee'); INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) VALUES ('Sector','*','READ','ALLOW','ROLE','employee'); diff --git a/modules/item/back/methods/item/labelPdf.js b/modules/item/back/methods/item/labelPdf.js new file mode 100644 index 000000000..747869b37 --- /dev/null +++ b/modules/item/back/methods/item/labelPdf.js @@ -0,0 +1,72 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('labelPdf', { + description: 'Returns the item label pdf', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The item id', + http: {source: 'path'} + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id', + required: false + }, + { + arg: 'warehouseId', + type: 'number', + description: 'The warehouse id', + required: true + }, + { + arg: 'labelNumber', + type: 'number', + required: false + }, + { + arg: 'totalLabels', + type: 'number', + required: false + } + ], + 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/label-pdf', + verb: 'GET' + } + }); + + Self.labelPdf = 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('item-label', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="item-${id}.pdf"`]; + }; +}; diff --git a/modules/item/back/models/item.js b/modules/item/back/models/item.js index 381033a1e..b8baa97ea 100644 --- a/modules/item/back/models/item.js +++ b/modules/item/back/models/item.js @@ -16,6 +16,7 @@ module.exports = Self => { require('../methods/item/createIntrastat')(Self); require('../methods/item/activeBuyers')(Self); require('../methods/item/buyerWasteEmail')(Self); + require('../methods/item/labelPdf')(Self); Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'}); diff --git a/print/templates/reports/item-label/item-label.js b/print/templates/reports/item-label/item-label.js index 09bc38abc..d03d03cfa 100755 --- a/print/templates/reports/item-label/item-label.js +++ b/print/templates/reports/item-label/item-label.js @@ -40,7 +40,9 @@ module.exports = { }); }, getBarcodeBase64(id) { - return qrcode.toDataURL(id, {margin: 0}); + const data = String(id); + + return qrcode.toDataURL(data, {margin: 0}); }, packing() { const stems = this.item.stems ? this.item.stems : 1; @@ -53,17 +55,19 @@ module.exports = { }, props: { id: { + type: Number, required: true, description: 'The item id' }, warehouseId: { + type: Number, required: true }, labelNumber: { - type: String + type: Number }, totalLabels: { - type: String + type: Number } } };