diff --git a/db/docker.js b/db/docker.js index 3eb262a822..05217d659a 100644 --- a/db/docker.js +++ b/db/docker.js @@ -47,12 +47,8 @@ module.exports = class Docker { if (ci) network = `--network="${networkName}"`; log('Starting container...'); - const container = await this.execP(` - docker run \ - ${network} \ - --env RUN_CHOWN=${runChown} \ - -d ${dockerArgs} salix-db - `); + const container = await this.execP( + `docker run ${network} --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`); this.id = container.stdout.trim(); try { diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8c6f2cac83..36595c51bb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -239,5 +239,6 @@ "This route does not exists": "Esta ruta no existe", "Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*", "You don't have grant privilege": "No tienes privilegios para dar privilegios", - "You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario" + "You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario", + "Empty data source": "Origen de datos vacio" } diff --git a/modules/ticket/back/methods/ticket/collectionLabel.js b/modules/ticket/back/methods/ticket/collectionLabel.js new file mode 100644 index 0000000000..064ca0210b --- /dev/null +++ b/modules/ticket/back/methods/ticket/collectionLabel.js @@ -0,0 +1,50 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('collectionLabel', { + description: 'Returns the collection label', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The ticket 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/collection-label', + verb: 'GET' + } + }); + + Self.collectionLabel = 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('collection-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 9255e52e62..f265709e73 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -33,4 +33,5 @@ module.exports = function(Self) { require('../methods/ticket/closeByTicket')(Self); require('../methods/ticket/closeByAgency')(Self); require('../methods/ticket/closeByRoute')(Self); + require('../methods/ticket/collectionLabel')(Self); }; diff --git a/print/templates/reports/collection-label/assets/css/import.js b/print/templates/reports/collection-label/assets/css/import.js new file mode 100644 index 0000000000..37a98dfddb --- /dev/null +++ b/print/templates/reports/collection-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/collection-label/assets/css/style.css b/print/templates/reports/collection-label/assets/css/style.css new file mode 100644 index 0000000000..fe1975445d --- /dev/null +++ b/print/templates/reports/collection-label/assets/css/style.css @@ -0,0 +1,37 @@ +html { + font-family: "Roboto"; + margin-top: -7px; +} +* { + box-sizing: border-box; + text-align: center; + font-size: 26px; +} +#vertical { + writing-mode: vertical-rl; + height: 226px; + margin-left: -13px; +} +.outline { + border: 1px solid black; + padding: 5px; +} +#nickname { + font-size: 22px; +} +#agencyDescripton { + font-size: 32px; + font-weight: bold; +} +#bold { + font-weight: bold; +} +#barcode{ + width: 390px; +} +#shipped { + font-weight: bold; +} +#ticketFk, #vertical { + font-size: 34px; +} \ No newline at end of file diff --git a/print/templates/reports/collection-label/collection-label.html b/print/templates/reports/collection-label/collection-label.html new file mode 100644 index 0000000000..5ae375786a --- /dev/null +++ b/print/templates/reports/collection-label/collection-label.html @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{labelData.levelV}}{{labelData.ticketFk}} ⬸ {{labelData.clientFk}}{{labelData.shipped}}
{{labelData.workerCode}}
{{labelData.labelCount}}
{{labelData.size}}
{{labelData.agencyDescription}}
{{labelData.lineCount}}
{{labelData.nickName}}{{labelData.agencyHour}}
+ + \ No newline at end of file diff --git a/print/templates/reports/collection-label/collection-label.js b/print/templates/reports/collection-label/collection-label.js new file mode 100644 index 0000000000..1ae986c987 --- /dev/null +++ b/print/templates/reports/collection-label/collection-label.js @@ -0,0 +1,46 @@ +const jsBarcode = require('jsbarcode'); +const {DOMImplementation, XMLSerializer} = require('xmldom'); +const UserError = require('vn-loopback/util/user-error'); + +module.exports = { + name: 'collection-label', + props: { + id: { + type: Number, + required: true, + description: 'The ticket or collection id' + } + }, + async serverPrefetch() { + let ticketIds; + const res = await this.rawSqlFromDef('tickets', [this.id]); + + if (res.length) { + ticketIds = []; + for (const row of res) + ticketIds.push(row.ticketFk); + } else + ticketIds = [this.id]; + + this.labelsData = await this.rawSqlFromDef('labelsData', [ticketIds]); + + if (!this.labelsData.length) + throw new UserError('Empty data source'); + }, + methods: { + getBarcode(id) { + const xmlSerializer = new XMLSerializer(); + const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null); + const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + + jsBarcode(svgNode, id, { + xmlDocument: document, + format: 'code128', + displayValue: false, + width: 3.8, + height: 110, + }); + return xmlSerializer.serializeToString(svgNode); + }, + } +}; diff --git a/print/templates/reports/collection-label/locale/es.yml b/print/templates/reports/collection-label/locale/es.yml new file mode 100644 index 0000000000..a54d3bad8b --- /dev/null +++ b/print/templates/reports/collection-label/locale/es.yml @@ -0,0 +1 @@ +reportName: labelCollection \ No newline at end of file diff --git a/print/templates/reports/collection-label/options.json b/print/templates/reports/collection-label/options.json new file mode 100644 index 0000000000..175b3c1db8 --- /dev/null +++ b/print/templates/reports/collection-label/options.json @@ -0,0 +1,11 @@ +{ + "width": "10.4cm", + "height": "4.8cm", + "margin": { + "top": "0cm", + "right": "0.5cm", + "bottom": "0cm", + "left": "0cm" + }, + "printBackground": true +} \ No newline at end of file diff --git a/print/templates/reports/collection-label/sql/labelsData.sql b/print/templates/reports/collection-label/sql/labelsData.sql new file mode 100644 index 0000000000..6f5b47a54d --- /dev/null +++ b/print/templates/reports/collection-label/sql/labelsData.sql @@ -0,0 +1,35 @@ +SELECT c.itemPackingTypeFk, + CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color, + CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.`level`) levelV, + tc.ticketFk, + LEFT(COALESCE(et.description, zo.name, am.name),12) agencyDescription, + am.name, + t.clientFk, + CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 , + CAST(IF(ic.code = 'plant', CONCAT(MAX(i.`size`),' cm'), COUNT(*)) AS CHAR) size, + w.code workerCode, + tt.labelCount, + IF(HOUR(t.shipped), TIME_FORMAT(t.shipped, '%H:%i'), TIME_FORMAT(zo.`hour`, '%H:%i')) agencyHour, + DATE_FORMAT(t.shipped, '%d/%m/%y') shipped, + COUNT(*) lineCount, + t.nickName + FROM vn.ticket t + JOIN vn.ticketCollection tc ON tc.ticketFk = t.id + JOIN vn.collection c ON c.id = tc.collectionFk + LEFT JOIN vn.collectionColors cc ON cc.shelve = tc.`level` + AND cc.wagon = tc.wagon + AND cc.trainFk = c.trainFk + JOIN vn.sale s ON s.ticketFk = t.id + LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.worker w ON w.id = c.workerFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id + LEFT JOIN vn.`zone` zo ON t.zoneFk = zo.id + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + WHERE tc.ticketFk IN (?) + GROUP BY t.id + ORDER BY cc.`code`; \ No newline at end of file diff --git a/print/templates/reports/collection-label/sql/tickets.sql b/print/templates/reports/collection-label/sql/tickets.sql new file mode 100644 index 0000000000..05deeba83a --- /dev/null +++ b/print/templates/reports/collection-label/sql/tickets.sql @@ -0,0 +1,3 @@ +SELECT ticketFk + FROM ticketCollection + WHERE collectionFk = ? \ No newline at end of file