diff --git a/back/methods/collection/previaLabelPdf.js b/back/methods/collection/previaLabelPdf.js new file mode 100644 index 000000000..8141d3e88 --- /dev/null +++ b/back/methods/collection/previaLabelPdf.js @@ -0,0 +1,49 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('previaLabelPdf', { + description: 'Returns the previa label pdf', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The item 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/previa-label-pdf', + verb: 'GET' + } + }); + + Self.previaLabelPdf = 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('previa-label', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="previa-${id}.pdf"`]; + }; +}; diff --git a/back/models/collection.js b/back/models/collection.js index 436414f62..1c6c9594c 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -3,4 +3,5 @@ module.exports = Self => { require('../methods/collection/newCollection')(Self); require('../methods/collection/getSectors')(Self); require('../methods/collection/setSaleQuantity')(Self); + require('../methods/collection/previaLabelPdf')(Self); }; diff --git a/print/templates/reports/previa-label/assets/css/import.js b/print/templates/reports/previa-label/assets/css/import.js new file mode 100644 index 000000000..37a98dfdd --- /dev/null +++ b/print/templates/reports/previa-label/assets/css/import.js @@ -0,0 +1,12 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, + `${__dirname}/style.css`]) + .mergeStyles(); diff --git a/print/templates/reports/previa-label/assets/css/style.css b/print/templates/reports/previa-label/assets/css/style.css new file mode 100644 index 000000000..1101604b9 --- /dev/null +++ b/print/templates/reports/previa-label/assets/css/style.css @@ -0,0 +1,88 @@ +* { + box-sizing: border-box; +} +.label { + font-size: 1.2em; +} + +.barcode { + float: left; + width: 40%; +} + +.barcode h1 { + text-align: center; + font-size: 1.8em; + margin: 0 0 10px 0 +} + +.barcode .image { + text-align: center +} + +.barcode .image img { + width: 170px +} + +.data { + float: left; + width: 60%; +} + +.data .header { + background-color: #000; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + margin-bottom: 25px; + text-align: right; + font-size: 1.2em; + padding: 0.2em; + color: #FFF +} + +.data .color, +.data .producer { + text-transform: uppercase; + text-align: right; + font-size: 1.5em; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} + +.data .producer { + text-justify: inter-character; +} + +.data .details { + border-top: 4px solid #000; + padding-top: 2px; +} + +.data .details .package { + padding-right: 5px; + float: left; + width: 50%; +} + +.package .packing, +.package .dated, +.package .labelNumber { + text-align: right +} + +.package .packing { + font-size: 1.8em; + font-weight: 400 +} + +.data .details .size { + background-color: #000; + text-align: center; + font-size: 3em; + padding: 0.2em 0; + float: left; + width: 50%; + color: #FFF +} \ No newline at end of file diff --git a/print/templates/reports/previa-label/locale/es.yml b/print/templates/reports/previa-label/locale/es.yml new file mode 100644 index 000000000..278946f3e --- /dev/null +++ b/print/templates/reports/previa-label/locale/es.yml @@ -0,0 +1 @@ +reportName: Etiqueta \ No newline at end of file diff --git a/print/templates/reports/previa-label/options.json b/print/templates/reports/previa-label/options.json new file mode 100644 index 000000000..98c5788b1 --- /dev/null +++ b/print/templates/reports/previa-label/options.json @@ -0,0 +1,11 @@ +{ + "width": "10.4cm", + "height": "4.8cm", + "margin": { + "top": "0cm", + "right": "0cm", + "bottom": "0cm", + "left": "0cm" + }, + "printBackground": true +} \ No newline at end of file diff --git a/print/templates/reports/previa-label/previa-label.html b/print/templates/reports/previa-label/previa-label.html new file mode 100644 index 000000000..46ca0239c --- /dev/null +++ b/print/templates/reports/previa-label/previa-label.html @@ -0,0 +1,28 @@ + + +
+
+

{{previa.saleGroupFk}}

+
+ +
+
+
+
PREVIA
+
{{sector.description}}
+
Ticket #{{previa.ticketFk}}
+
+
+
{{previa.itemPackingTypeFk}}
+
{{previa.shippingHour}}:{{previa.shippingMinute}}
+
+
{{previa.items}}
+
+
+
+ +
diff --git a/print/templates/reports/previa-label/previa-label.js b/print/templates/reports/previa-label/previa-label.js new file mode 100755 index 000000000..a598e0179 --- /dev/null +++ b/print/templates/reports/previa-label/previa-label.js @@ -0,0 +1,46 @@ +const Component = require(`vn-print/core/component`); +const reportBody = new Component('report-body'); +const qrcode = require('qrcode'); + +module.exports = { + name: 'previa-label', + async serverPrefetch() { + this.previa = await this.fetchPrevia(this.id); + this.sector = await this.fetchSector(this.id); + this.previa = this.previa[0]; + this.barcode = await this.getBarcodeBase64(this.id); + + if (!this.previa) + throw new Error('Something went wrong'); + + if (!this.sector) + throw new Error('Something went wrong'); + }, + + computed: { + + }, + methods: { + fetchPrevia(id) { + return this.findOneFromDef('previa', [id]); + }, + getBarcodeBase64(id) { + const data = String(id); + + return qrcode.toDataURL(data, {margin: 0}); + }, + fetchSector(id) { + return this.findOneFromDef('sector', [id]); + } + }, + components: { + 'report-body': reportBody.build() + }, + props: { + id: { + type: Number, + required: true, + description: 'The saleGroupFk id' + }, + } +}; diff --git a/print/templates/reports/previa-label/sql/previa.sql b/print/templates/reports/previa-label/sql/previa.sql new file mode 100644 index 000000000..f73166f74 --- /dev/null +++ b/print/templates/reports/previa-label/sql/previa.sql @@ -0,0 +1 @@ +CALL vn.previousSticker_get(?) \ No newline at end of file diff --git a/print/templates/reports/previa-label/sql/sector.sql b/print/templates/reports/previa-label/sql/sector.sql new file mode 100644 index 000000000..d10a9a630 --- /dev/null +++ b/print/templates/reports/previa-label/sql/sector.sql @@ -0,0 +1,9 @@ +select + s.description +from + vn.collection c +join + vn.sector s +on + s.id = c.sectorFk +where c.id = ? \ No newline at end of file