refs #4898 Created report expedition-pallet-label
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2022-12-12 18:27:45 +01:00
parent 6cb0e518d4
commit d7a6350995
10 changed files with 248 additions and 0 deletions

View File

@ -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"`];
};
};

View File

@ -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);
};

View File

@ -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();

View File

@ -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;
}

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<body>
<table class="mainTable">
<tbody>
<tr>
<td colspan="2" id="truck" class="ellipsize">{{labelData.truck || '---'}}</td>
</tr>
<tr>
<td colspan="2">
<table v-for="labelData in labelsData" class="zoneTable">
<thead>
<tr v-if="!labelData.isMatch" id="black">
<td id="routeFk" class="ellipsize">{{labelData.routeFk}}</td>
<td id="zone" class="ellipsize">{{labelData.zone || '---'}}</td>
<td id="labels" class="ellipsize">{{labelData.labels}}</td>
</tr>
<tr v-else>
<td id="routeFk" class="ellipsize">{{labelData.routeFk}}</td>
<td id="zone" class="ellipsize">{{labelData.zone || '---'}}</td>
<td id="labels" class="ellipsize">{{labelData.labels || '--'}}</td>
</tr>
</thead>
</table>
</td>
</tr>
<tr>
<td><img :src="QR" id="QR"/></td>
<td class="ellipsize">
<div id="additionalInfo"><b>Pallet: </b>{{id}}</div>
<div id="additionalInfo"><b>User: </b> {{username.name || '---'}}</div>
<div id="additionalInfo"><b>Day: </b>{{labelData.dayName.toUpperCase() || '---'}}</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -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()
},
};

View File

@ -0,0 +1 @@
reportName: labelPalletExpedition

View File

@ -0,0 +1,11 @@
{
"width": "10cm",
"height": "15cm",
"margin": {
"top": "0.5cm",
"right": "0.2cm",
"bottom": "0cm",
"left": "0cm"
},
"printBackground": true
}

View File

@ -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

View File

@ -0,0 +1,3 @@
SELECT `name`
FROM account.user
WHERE id = ?