feat: refs #7266 Item label QR
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-10-21 14:57:55 +02:00
parent 34deba406b
commit bf2d7541a5
17 changed files with 298 additions and 175 deletions

View File

@ -1723,7 +1723,7 @@ INSERT INTO `ACL` VALUES (378,'OsTicket','osTicketReportEmail','WRITE','ALLOW','
INSERT INTO `ACL` VALUES (379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system',NULL);
INSERT INTO `ACL` VALUES (380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee',NULL);
INSERT INTO `ACL` VALUES (381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager',NULL);
INSERT INTO `ACL` VALUES (382,'Item','labelPdf','READ','ALLOW','ROLE','employee',NULL);
INSERT INTO `ACL` VALUES (382,'Item','itemLabelQr','READ','ALLOW','ROLE','employee',NULL);
INSERT INTO `ACL` VALUES (383,'Sector','*','READ','ALLOW','ROLE','employee',NULL);
INSERT INTO `ACL` VALUES (384,'Sector','*','WRITE','ALLOW','ROLE','employee',NULL);
INSERT INTO `ACL` VALUES (385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee',NULL);

View File

@ -383,5 +383,5 @@
"No valid travel thermograph found": "No se encontró un termógrafo válido",
"The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea",
"type cannot be blank": "Se debe rellenar el tipo",
"There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero"
"There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero"
}

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethodCtx('labelPdf', {
Self.remoteMethodCtx('itemLabelQr', {
description: 'Returns the item label pdf',
accessType: 'READ',
accepts: [
@ -11,26 +11,15 @@ module.exports = Self => {
http: {source: 'path'}
},
{
arg: 'recipientId',
arg: 'copies',
type: 'number',
description: 'The recipient id',
required: false
},
{
arg: 'warehouseId',
}, {
arg: 'userId',
type: 'number',
description: 'The warehouse id',
description: 'The user id from accessToken',
http: ctx => ctx.req.accessToken.userId,
required: true
},
{
arg: 'labelNumber',
type: 'number',
required: false
},
{
arg: 'totalLabels',
type: 'number',
required: false
}
],
returns: [
@ -49,11 +38,11 @@ module.exports = Self => {
}
],
http: {
path: '/:id/label-pdf',
path: '/:id/item-label-qr',
verb: 'GET'
},
accessScopes: ['DEFAULT', 'read:multimedia']
});
Self.labelPdf = (ctx, id) => Self.printReport(ctx, id, 'item-label');
Self.itemLabelQr = (ctx, id) => Self.printReport(ctx, id, 'item-label-qr');
};

View File

@ -15,7 +15,7 @@ module.exports = Self => {
require('../methods/item/getWasteByItem')(Self);
require('../methods/item/createIntrastat')(Self);
require('../methods/item/buyerWasteEmail')(Self);
require('../methods/item/labelPdf')(Self);
require('../methods/item/itemLabelQr')(Self);
require('../methods/item/setVisibleDiscard')(Self);
require('../methods/item/get')(Self);

View File

@ -0,0 +1,87 @@
html {
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
margin-top: -7px;
}
.leftTable {
width: 47%;
font-size: 12px;
float: left;
text-align: center;
}
.leftTable img {
width: 110px;
}
.rightTable {
width: 53%;
font-size: 14px;
float: right;
}
.rightTable td {
border: 3px solid white;
}
.center {
text-align: center;
}
.cursive {
font-style: italic;
}
.bold {
font-weight: bold;
}
.black-bg {
background-color: black;
color: white;
}
.md-txt {
font-size: 20px;
}
.xl-txt {
font-size: 36px;
}
.cell {
border: 2px solid black;
box-sizing: content-box;
width: 100%;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
}
.padding {
padding: 7px;
}
.md-height {
height: 60px;
max-height: 60px;
}
.xs-width {
width: 60px;
max-width: 60px;
}
.sm-width {
width: 140px;
max-width: 140px;
}
.md-width {
width: 200px;
max-width: 200px;
}
.lg-width {
width: 270px;
max-width: 270px;
}
.overflow-multiline {
max-height: inherit;
display: -webkit-box;
overflow: hidden;
word-wrap: break-word;
line-clamp: 2;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.overflow-line {
width: inherit;
max-width: inherit;
overflow: hidden;
white-space: nowrap;
}

View File

@ -0,0 +1,112 @@
<!DOCTYPE html>
<html>
<body table v-for="item in items" style="break-before: page">
<table class="leftTable">
<tr>
<td>
<img v-bind:src="qr"/>
</td>
<td>
<img v-bind:src="qr"/>
</td>
</tr>
<tr>
<td colspan="2">
{{item.buyFk}}
</td>
</tr>
<tr>
<td>
<img v-bind:src="qr"/>
</td>
<td>
<img v-bind:src="qr"/>
</td>
</tr>
</table>
<table class="rightTable">
<tr>
<td colspan="3" class="lg-width black-bg center bold xl-txt padding">
<div class="overflow-line">
{{item.itemFk}}
</div>
</td>
</tr>
<tr>
<td colspan="2" class="black-bg center bold md-txt md-width md-height">
<div class="overflow-multiline">
{{item.item}}
</div>
</td>
<td class="xs-width black-bg center bold xl-txt">
<div class="overflow-line">
{{item.size}}
</div>
</td>
</tr>
<tr>
<td class="sm-width">
<div class="overflow-line">
<i>Color:</i> <b>{{item.inkFk}}</b>
</div>
</td>
<td rowspan="2" class="xs-width center md-txt">
<div class="overflow-line cell">
{{item.packing}}
</div>
</td>
<td rowspan="2" class="xs-width center md-txt">
<div class="overflow-line cell">
{{item.stems}}
</div>
</td>
</tr>
<tr>
<td class="sm-width">
<div class="overflow-line">
<i>Origen:</i> {{item.origin}}
</div>
</td>
</tr>
<tr>
<td colspan="2" class="md-width">
<div class="overflow-line">
<i>Productor:</i> {{item.producer}}
</div>
</td>
<td></td>
</tr>
<tr>
<td class="sm-width">
<div class="overflow-line">
<i>Comprador:</i> {{item.buyerName}}
</div>
</td>
<td rowspan="2" class="xs-width">
<div class="overflow-line">
<i>F:</i> {{date}}
</div>
</td>
<td rowspan="2" class="xs-width center cursive bold md-txt">
<div class="overflow-line">
{{`${item.labelNum} / ${totalPages}`}}
</div>
</td>
</tr>
<tr>
<td class="sm-width">
<div class="overflow-line">
<i>Entrada:</i> {{item.entryFk}}
</div>
</td>
</tr>
<tr>
<td colspan="3" class="lg-width center cursive bold">
<div class="overflow-line">
{{item.comment}}
</div>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,43 @@
const UserError = require('vn-loopback/util/user-error');
const moment = require('moment');
const qrcode = require('qrcode');
module.exports = {
name: 'item-label-qr',
async serverPrefetch() {
this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.id]);
if (!this.items.length) throw new UserError(`Empty data source`);
this.qr = await this.getQr(this.items[0].buyFk);
this.vnDate = Date.vnNew();
this.date = moment(this.vnDate).format('YY/DD');
this.totalPages = this.items.length;
},
methods: {
getQr(data) {
data = {
company: 'vnl',
user: this.userId,
created: this.vnDate,
table: 'buy',
id: data
};
return qrcode.toDataURL(JSON.stringify(data), {
margin: 0,
errorCorrectionLevel: 'H'
});
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
copies: {
type: Number
},
userId: {
type: Number
}
}
};

View File

@ -0,0 +1 @@
reportName: Etiqueta de artículo QR

View File

@ -2,7 +2,7 @@
"width": "10.4cm",
"height": "4.8cm",
"margin": {
"top": "0cm",
"top": "0.17cm",
"right": "0cm",
"bottom": "0cm",
"left": "0cm"

View File

@ -0,0 +1,42 @@
WITH RECURSIVE numbers AS (
SELECT 1 n
UNION ALL
SELECT n + 1
FROM numbers
WHERE n < ?
)
SELECT ROW_NUMBER() OVER() labelNum,
b.id buyFk,
b.itemFk,
b.quantity,
b.packing,
b.isPickedOff,
b.entryFk,
e.sub,
o.code origin,
COALESCE(p.`name`, p.id, '') producer,
i.name item,
i.`size`,
i.category,
i.stems,
i.inkFk,
IFNULL(CONCAT(ig.longName, ' ', ig.`size`, ' ', ig.subName), i.comment) comment,
i.typeFk,
i.isLaid,
w.code buyerName,
w.code,
s.company_name companyName,
t.shipped
FROM vn.buy b
JOIN vn.item i ON i.id = b.itemFk
LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk
LEFT JOIN edi.ekt e ON e.id = b.ektFk
JOIN vn.origin o ON o.id = i.originFk
LEFT JOIN vn.producer p ON p.id = i.producerFk
JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.worker w ON w.id = it.workerFk
LEFT JOIN edi.supplier s ON s.supplier_id = e.pro
JOIN vn.entry e2 ON e2.id = b.entryFk
JOIN vn.travel t ON t.id = e2.travelFk
JOIN numbers num
WHERE b.id = ?

View File

@ -1,37 +0,0 @@
html {
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
font-size: 12px;
}
table {
width: 50%;
font-size: 12px;
float: right;
}
td {
border: 3px solid white;
}
.center {
text-align: center;
}
.cursive {
font-style: italic;
}
.bold {
font-weight: bold;
}
.black {
background-color: black;
color: white;
}
.md {
font-size: 18px;
}
.xl {
font-size: 36px;
}
.border-black {
border: 2px solid #000000;
}
.regular-with {
width: 60px;
}

View File

@ -1,37 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<td colspan="3" class="black center bold xl">1</td>
</tr>
<tr>
<td colspan="2" class="black center bold md">EUC Cinerea</td>
<td class="black center bold xl regular-with">60</td>
</tr>
<tr>
<td>Color: LIV</td>
<td rowspan="2" class="center md border-black regular-with">15</td>
<td rowspan="2" class="center md border-black regular-with">0</td>
</tr>
<tr>
<td>Origen: VCL</td>
</tr>
<tr>
<td colspan="2">Productor: L'Arenal</td>
<td></td>
</tr>
<tr>
<td>Comprador: ATJ</td>
<td rowspan="2">F:42/1</td>
<td rowspan="2" class="center cursive bold md">1 / 50</td>
</tr>
<tr>
<td>Entrada: 358799</td>
</tr>
<tr>
<td colspan="3" class="center cursive bold">E622/2</td>
</tr>
</table>
</body>
</html>

View File

@ -1,58 +0,0 @@
const vnReport = require('../../../core/mixins/vn-report.js');
const qrcode = require('qrcode');
module.exports = {
name: 'item-label',
mixins: [vnReport],
async serverPrefetch() {
this.item = await this.findOneFromDef('item', [this.id, this.warehouseId]);
this.checkMainEntity(this.item);
this.tags = await this.fetchItemTags(this.id);
this.barcode = await this.getBarcodeBase64(this.id);
},
computed: {
labelPage() {
const labelNumber = this.labelNumber ? this.labelNumber : 1;
const totalLabels = this.totalLabels ? this.totalLabels : 1;
return `${labelNumber}/${totalLabels}`;
}
},
methods: {
fetchItemTags(id) {
return this.rawSqlFromDef('itemTags', [id]).then(rows => {
const tags = {};
rows.forEach(row => tags[row.code] = row.value);
return tags;
});
},
getBarcodeBase64(id) {
const data = String(id);
return qrcode.toDataURL(data, {margin: 0});
},
packing() {
const stems = this.item.stems ? this.item.stems : 1;
return `${this.item.packing}x${stems}`;
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
warehouseId: {
type: Number,
required: true
},
labelNumber: {
type: Number
},
totalLabels: {
type: Number
}
}
};

View File

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

View File

@ -1,14 +0,0 @@
SELECT
i.id,
i.name,
i.stems,
i.size,
b.packing,
p.name as 'producer'
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
JOIN vn.producer p ON p.id = i.producerFk
WHERE i.id = ? AND clb.warehouse_id = ?

View File

@ -1,4 +0,0 @@
SELECT t.code, t.name, it.value
FROM vn.itemTag it
JOIN vn.tag t ON t.id = it.tagFk
WHERE it.itemFk = ?