added item-label report and configurable report options
This commit is contained in:
parent
47d689ae50
commit
ff292baecf
|
@ -5,6 +5,13 @@
|
|||
"senderMail": "nocontestar@verdnatura.es",
|
||||
"senderName": "Verdnatura"
|
||||
},
|
||||
"pdf": {
|
||||
"format": "A4",
|
||||
"border": "1.5cm",
|
||||
"footer": {
|
||||
"height": "55px"
|
||||
}
|
||||
},
|
||||
"mysql": {
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
{"type": "report", "name": "rpt-zone"},
|
||||
{"type": "report", "name": "rpt-route"},
|
||||
{"type": "report", "name": "rpt-lcr"},
|
||||
{"type": "report", "name": "rpt-item-label"},
|
||||
{"type": "static", "name": "email-header"},
|
||||
{"type": "static", "name": "email-footer"},
|
||||
{"type": "static", "name": "report-header"},
|
||||
|
|
|
@ -2,9 +2,9 @@ const Vue = require('vue');
|
|||
const VueI18n = require('vue-i18n');
|
||||
const renderer = require('vue-server-renderer').createRenderer();
|
||||
const fs = require('fs-extra');
|
||||
// const pdf = require('phantom-html2pdf');
|
||||
const pdf = require('html-pdf');
|
||||
const juice = require('juice');
|
||||
const config = require('./config');
|
||||
|
||||
Vue.use(VueI18n);
|
||||
|
||||
|
@ -104,13 +104,11 @@ module.exports = {
|
|||
|
||||
async toPdf(name, ctx) {
|
||||
const html = await this.render(name, ctx);
|
||||
const options = {
|
||||
format: 'A4',
|
||||
border: '1.5cm',
|
||||
footer: {
|
||||
height: '55px',
|
||||
}
|
||||
};
|
||||
let options = config.pdf;
|
||||
|
||||
const optionsPath = `${this.path}/${name}/options.json`;
|
||||
if (fs.existsSync(optionsPath))
|
||||
options = Object.assign(options, require(optionsPath));
|
||||
|
||||
return new Promise(resolve => {
|
||||
pdf.create(html, options).toStream((err, stream) => {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"juice": "^5.0.1",
|
||||
"mysql2": "^1.6.5",
|
||||
"nodemailer": "^4.7.0",
|
||||
"qrcode": "^1.4.2",
|
||||
"strftime": "^0.10.0",
|
||||
"vue": "^2.6.7",
|
||||
"vue-i18n": "^8.8.2",
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
const CssReader = require(`${appPath}/lib/cssReader`);
|
||||
|
||||
module.exports = new CssReader([
|
||||
`${appPath}/common/css/layout.css`,
|
||||
`${appPath}/common/css/report.css`,
|
||||
`${appPath}/common/css/misc.css`,
|
||||
`${__dirname}/style.css`])
|
||||
.mergeStyles();
|
|
@ -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
|
||||
}
|
||||
|
||||
.barcode .image {
|
||||
text-align: center
|
||||
}
|
||||
|
||||
.barcode .image img {
|
||||
width: 180px
|
||||
}
|
||||
|
||||
.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
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<body>
|
||||
<section class="container" id="report">
|
||||
<section class="label">
|
||||
<section class="barcode">
|
||||
<h1>{{item.id}}</h1>
|
||||
<section class="image">
|
||||
<img v-bind:src="barcode"/>
|
||||
</section>
|
||||
</section>
|
||||
<section class="data">
|
||||
<section class="header">{{item.name}}</section>
|
||||
<section class="color">{{tags.color}}</section>
|
||||
<section class="producer">{{tags.producer}}</section>
|
||||
<section class="details">
|
||||
<section class="package">
|
||||
<section class="packing">{{packing()}}</section>
|
||||
<section class="dated">{{dated}}</section>
|
||||
<section class="labelNumber">{{labelPage()}}</section>
|
||||
</section>
|
||||
<section class="size">{{item.size}}</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,83 @@
|
|||
const database = require(`${appPath}/lib/database`);
|
||||
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
||||
const strftime = require('strftime');
|
||||
const qrcode = require('qrcode');
|
||||
|
||||
module.exports = {
|
||||
name: 'rpt-item-label',
|
||||
async asyncData(ctx, params) {
|
||||
Object.assign(this, this.methods);
|
||||
|
||||
if (!params.itemId)
|
||||
throw new UserException('No item id specified');
|
||||
|
||||
if (!params.warehouseId)
|
||||
throw new UserException('No warehouse id specified');
|
||||
|
||||
const data = {
|
||||
item: await this.fetchItem(params.itemId, params.warehouseId),
|
||||
tags: await this.fetchItemTags(params.itemId),
|
||||
barcode: await this.getBarcodeBase64(params.itemId),
|
||||
labelNumber: params.labelNumber,
|
||||
totalLabels: params.totalLabels
|
||||
};
|
||||
|
||||
return data;
|
||||
},
|
||||
computed: {
|
||||
dated() {
|
||||
return strftime('%W/%d', new Date());
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
fetchItem(id, warehouseId) {
|
||||
return database.pool.query(
|
||||
`SELECT
|
||||
i.id,
|
||||
i.name,
|
||||
i.stems,
|
||||
i.size,
|
||||
b.packing
|
||||
FROM vn.item i
|
||||
JOIN cache.last_buy clb ON clb.item_id = i.id
|
||||
JOIN vn.buy b ON b.id = clb.buy_id
|
||||
JOIN vn.entry e ON e.id = b.entryFk
|
||||
WHERE i.id = ? AND clb.warehouse_id = ?`, [id, warehouseId])
|
||||
.then(([rows]) => {
|
||||
if (rows.length == 0)
|
||||
throw new UserException(`Item #${id} not found on warehouse #${warehouseId}`);
|
||||
return rows[0];
|
||||
});
|
||||
},
|
||||
fetchItemTags(itemId) {
|
||||
return database.pool.query(
|
||||
`SELECT t.code, t.name, it.value
|
||||
FROM vn.itemTag it
|
||||
JOIN vn.tag t ON t.id = it.tagFk
|
||||
WHERE it.itemFk = ?`, [itemId])
|
||||
.then(([rows]) => {
|
||||
const tags = {};
|
||||
rows.forEach(row => tags[row.code] = row.value);
|
||||
|
||||
return tags;
|
||||
});
|
||||
},
|
||||
getBarcodeBase64(itemId) {
|
||||
return qrcode.toDataURL(itemId);
|
||||
},
|
||||
packing() {
|
||||
const stems = this.item.stems ? this.item.stems : 1;
|
||||
return `${this.item.packing}x${stems}`;
|
||||
},
|
||||
labelPage() {
|
||||
const labelNumber = this.labelNumber ? this.labelNumber : 1;
|
||||
const totalLabels = this.totalLabels ? this.totalLabels : 1;
|
||||
|
||||
return `${labelNumber}/${totalLabels}`;
|
||||
}
|
||||
},
|
||||
components: {
|
||||
'report-header': require('../report-header'),
|
||||
'report-footer': require('../report-footer'),
|
||||
},
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
module.exports = {
|
||||
messages: {
|
||||
es: {
|
||||
title: 'Recibo',
|
||||
date: 'Fecha',
|
||||
payed: 'En {0}, a {1} de {2} de {3}',
|
||||
client: 'Cliente {0}',
|
||||
months: [
|
||||
'Enero',
|
||||
'Febrero',
|
||||
'Marzo',
|
||||
'Abril',
|
||||
'Mayo',
|
||||
'Junio',
|
||||
'Julio',
|
||||
'Agosto',
|
||||
'Septiembre',
|
||||
'Octubre',
|
||||
'Noviembre',
|
||||
'Diciembre'
|
||||
]
|
||||
},
|
||||
},
|
||||
};
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"format": "A4",
|
||||
"orientation": "landscape",
|
||||
"width": "10.4cm",
|
||||
"height": "4.8cm",
|
||||
"border": "0cm",
|
||||
"footer": {
|
||||
"height": "0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue