From d7a6350995bebf5e121848edeb957ca6bea08cfc Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Dec 2022 18:27:45 +0100 Subject: [PATCH] refs #4898 Created report expedition-pallet-label --- .../methods/ticket/expeditionPalletLabel.js | 55 ++++++++++++++++ modules/ticket/back/models/ticket-methods.js | 1 + .../assets/css/import.js | 12 ++++ .../assets/css/style.css | 62 +++++++++++++++++++ .../expedition-pallet-label.html | 38 ++++++++++++ .../expedition-pallet-label.js | 46 ++++++++++++++ .../expedition-pallet-label/locale/es.yml | 1 + .../expedition-pallet-label/options.json | 11 ++++ .../expedition-pallet-label/sql/labelData.sql | 19 ++++++ .../expedition-pallet-label/sql/username.sql | 3 + 10 files changed, 248 insertions(+) create mode 100644 modules/ticket/back/methods/ticket/expeditionPalletLabel.js create mode 100644 print/templates/reports/expedition-pallet-label/assets/css/import.js create mode 100644 print/templates/reports/expedition-pallet-label/assets/css/style.css create mode 100644 print/templates/reports/expedition-pallet-label/expedition-pallet-label.html create mode 100644 print/templates/reports/expedition-pallet-label/expedition-pallet-label.js create mode 100644 print/templates/reports/expedition-pallet-label/locale/es.yml create mode 100644 print/templates/reports/expedition-pallet-label/options.json create mode 100644 print/templates/reports/expedition-pallet-label/sql/labelData.sql create mode 100644 print/templates/reports/expedition-pallet-label/sql/username.sql diff --git a/modules/ticket/back/methods/ticket/expeditionPalletLabel.js b/modules/ticket/back/methods/ticket/expeditionPalletLabel.js new file mode 100644 index 000000000..2215263dd --- /dev/null +++ b/modules/ticket/back/methods/ticket/expeditionPalletLabel.js @@ -0,0 +1,55 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('expeditionPalletLabel', { + description: 'Returns the expedition pallet label', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The pallet id', + http: {source: 'path'} + }, { + arg: 'userFk', + type: 'number', + required: true, + description: 'The user id' + } + ], + 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/expedition-pallet-label', + verb: 'GET' + } + }); + + Self.expeditionPalletLabel = 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('expedition-pallet-label', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="doc-${id}.pdf"`]; + }; +}; diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 82a1ac862..8fd74d35c 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -37,4 +37,5 @@ module.exports = function(Self) { require('../methods/ticket/merge')(Self); require('../methods/ticket/isRoleAdvanced')(Self); require('../methods/ticket/collectionLabel')(Self); + require('../methods/ticket/expeditionPalletLabel')(Self); }; diff --git a/print/templates/reports/expedition-pallet-label/assets/css/import.js b/print/templates/reports/expedition-pallet-label/assets/css/import.js new file mode 100644 index 000000000..37a98dfdd --- /dev/null +++ b/print/templates/reports/expedition-pallet-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/expedition-pallet-label/assets/css/style.css b/print/templates/reports/expedition-pallet-label/assets/css/style.css new file mode 100644 index 000000000..68e91fb47 --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/assets/css/style.css @@ -0,0 +1,62 @@ +html { + font-family: Arial, Helvetica, sans-serif; +} +* { + box-sizing: border-box; + font-size: 25px; +} +#truck { + width: 100%; + max-width: 150px; + height: 90px; + background-color: black; + color: white; + font-size: 50px; + font-weight: bold; + text-align: center; +} +.mainTable { + width: 100%; + height: 100%; + border: 10px solid; + border-radius: 20px; + -moz-border-radius: 20px; + -webkit-border-radius: 10px; + border-collapse: separate; + border-spacing: 0px; +} +.zoneTable{ + width: 100%; + margin: 0 auto; + border-collapse: collapse; +} +#routeFk, #zone, #labels{ + font-size: 30px; +} +#routeFk{ + width: 120px; + padding-top: 5px; + padding-bottom: 5px; + max-width: 120px; + text-align: center; +} +#zone{ + width: 305px; + max-width: 305px; + text-align: center; +} +#labels{ + text-align: center; +} +#black { + background-color: rgb(102, 102, 102); + color: white; +} +#QR { + padding: 25px; + padding-left: 40px; + margin-top: 20px; +} +#additionalInfo { + padding-top: 20px; +} \ No newline at end of file diff --git a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.html b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.html new file mode 100644 index 000000000..45c6ab463 --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + +
{{labelData.truck || '---'}}
+ + + + + + + + + + + + + +
{{labelData.routeFk}}{{labelData.zone || '---'}}{{labelData.labels}}
{{labelData.routeFk}}{{labelData.zone || '---'}}{{labelData.labels || '--'}}
+
+
Pallet: {{id}}
+
User: {{username.name || '---'}}
+
Day: {{labelData.dayName.toUpperCase() || '---'}}
+
+ + \ No newline at end of file diff --git a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js new file mode 100644 index 000000000..d18a9a4ec --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js @@ -0,0 +1,46 @@ +const Component = require(`vn-print/core/component`); +const reportBody = new Component('report-body'); +const UserError = require('vn-loopback/util/user-error'); +const qrcode = require('qrcode'); + +module.exports = { + name: 'expedition-pallet-label', + props: { + id: { + type: Number, + required: true, + description: 'The pallet id' + }, + userFk: { + type: Number, + required: true, + description: 'The user id' + } + }, + async serverPrefetch() { + this.labelsData = await this.rawSqlFromDef('labelData', this.id); + this.username = await this.findOneFromDef('username', this.userFk); + this.labelData = this.labelsData[0]; + + let QRdata = JSON.stringify({ + company: 'vnl', + user: null, + created: new Date(), + table: 'expeditionPallet', + id: this.id + }); + + this.QR = await this.getQR(QRdata); + if (!this.labelsData.length) + throw new UserError('Empty data source'); + }, + methods: { + getQR(id) { + const data = String(id); + return qrcode.toDataURL(data, {margin: 0}); + }, + }, + components: { + 'report-body': reportBody.build() + }, +}; diff --git a/print/templates/reports/expedition-pallet-label/locale/es.yml b/print/templates/reports/expedition-pallet-label/locale/es.yml new file mode 100644 index 000000000..f97730aef --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/locale/es.yml @@ -0,0 +1 @@ +reportName: labelPalletExpedition \ No newline at end of file diff --git a/print/templates/reports/expedition-pallet-label/options.json b/print/templates/reports/expedition-pallet-label/options.json new file mode 100644 index 000000000..269e058f0 --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/options.json @@ -0,0 +1,11 @@ +{ + "width": "10cm", + "height": "15cm", + "margin": { + "top": "0.5cm", + "right": "0.2cm", + "bottom": "0cm", + "left": "0cm" + }, + "printBackground": true +} \ No newline at end of file diff --git a/print/templates/reports/expedition-pallet-label/sql/labelData.sql b/print/templates/reports/expedition-pallet-label/sql/labelData.sql new file mode 100644 index 000000000..0661dbe0f --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/sql/labelData.sql @@ -0,0 +1,19 @@ +SELECT ep.id palletFk, + t.routeFk, + et2.description truck, + r.description `zone`, + COUNT(es.id) labels, + t.warehouseFk warehouseFk, + dayname(r.created) `dayName`, + et.id <=> rm.expeditionTruckFk isMatch + FROM vn.expeditionTruck et + JOIN vn.expeditionPallet ep ON ep.truckFk = et.id + JOIN vn.expeditionScan es ON es.palletFk = ep.id + JOIN vn.expedition e ON e.id = es.expeditionFk + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn2008.Rutas_monitor rm ON rm.Id_Ruta = r.id + LEFT JOIN vn.expeditionTruck et2 ON et2.id = rm.expeditionTruckFk + WHERE ep.id = ? + GROUP BY ep.id, t.routeFk + ORDER BY t.routeFk \ No newline at end of file diff --git a/print/templates/reports/expedition-pallet-label/sql/username.sql b/print/templates/reports/expedition-pallet-label/sql/username.sql new file mode 100644 index 000000000..e2ca3c65a --- /dev/null +++ b/print/templates/reports/expedition-pallet-label/sql/username.sql @@ -0,0 +1,3 @@ +SELECT `name` + FROM account.user + WHERE id = ? \ No newline at end of file