feat: refs #7266 Requested changes and improvements

This commit is contained in:
Guillermo Bonet 2024-10-28 14:51:19 +01:00
parent c43bdb5021
commit a37b7b71a8
33 changed files with 81 additions and 256 deletions

View File

@ -1,14 +1,28 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('buyLabel', { Self.remoteMethodCtx('buyLabel', {
description: 'Returns the entry buy labels', description: 'Returns the buy label',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
{ {
arg: 'id', arg: 'id',
type: 'number', type: 'number',
required: true, required: true,
description: 'The entry id', description: 'The buy id',
http: {source: 'path'} http: {source: 'path'}
}, {
arg: 'labelType',
type: 'string',
required: true,
description: 'The label type',
http: {source: 'path'}
}, {
arg: 'packing',
type: 'number',
required: false
}, {
arg: 'copies',
type: 'number',
required: false
} }
], ],
returns: [ returns: [
@ -27,11 +41,16 @@ module.exports = Self => {
} }
], ],
http: { http: {
path: '/:id/buy-label', path: '/:id/:labelType/buy-label',
verb: 'GET' verb: 'GET'
}, },
accessScopes: ['DEFAULT', 'read:multimedia'] accessScopes: ['DEFAULT', 'read:multimedia']
}); });
Self.buyLabel = (ctx, id) => Self.printReport(ctx, id, 'buy-label'); Self.buyLabel = (ctx, id, labelType) => {
if (labelType == 'qr')
return Self.printReport(ctx, id, 'buy-label-qr');
else
return Self.printReport(ctx, id, 'buy-label-barcode');
};
}; };

View File

@ -1,22 +1,14 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('labelBarcodePdf', { Self.remoteMethodCtx('buyLabelSupplier', {
description: 'Returns the item label pdf with barcode', description: 'Returns the entry buy labels',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
{ {
arg: 'id', arg: 'id',
type: 'number', type: 'number',
required: true, required: true,
description: 'The item id', description: 'The entry id',
http: {source: 'path'} http: {source: 'path'}
}, {
arg: 'packing',
type: 'number',
required: false
}, {
arg: 'copies',
type: 'number',
required: false
} }
], ],
returns: [ returns: [
@ -35,14 +27,11 @@ module.exports = Self => {
} }
], ],
http: { http: {
path: '/:id/label-barcode-pdf', path: '/:id/buy-label-supplier',
verb: 'GET' verb: 'GET'
}, },
accessScopes: ['DEFAULT', 'read:multimedia'] accessScopes: ['DEFAULT', 'read:multimedia']
}); });
Self.labelBarcodePdf = (ctx, id) => { Self.buyLabelSupplier = (ctx, id) => Self.printReport(ctx, id, 'buy-label-supplier');
ctx.args.typeId = 'buy';
return Self.printReport(ctx, id, 'item-label-barcode');
};
}; };

View File

@ -1,49 +0,0 @@
module.exports = Self => {
Self.remoteMethodCtx('labelQrPdf', {
description: 'Returns the item label pdf with qr',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The item id',
http: {source: 'path'}
}, {
arg: 'packing',
type: 'number',
required: false
}, {
arg: 'copies',
type: 'number',
required: false
}
],
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/label-qr-pdf',
verb: 'GET'
},
accessScopes: ['DEFAULT', 'read:multimedia']
});
Self.labelQrPdf = (ctx, id) => {
ctx.args.userId = ctx.req.accessToken.userId;
ctx.args.typeId = 'buy';
return Self.printReport(ctx, id, 'item-label-qr');
};
};

View File

@ -2,6 +2,5 @@ module.exports = Self => {
require('../methods/entry/editLatestBuys')(Self); require('../methods/entry/editLatestBuys')(Self);
require('../methods/entry/latestBuysFilter')(Self); require('../methods/entry/latestBuysFilter')(Self);
require('../methods/entry/deleteBuys')(Self); require('../methods/entry/deleteBuys')(Self);
require('../methods/entry/labelBarcodePdf')(Self); require('../methods/entry/buyLabel')(Self);
require('../methods/entry/labelQrPdf')(Self);
}; };

View File

@ -1,52 +0,0 @@
module.exports = Self => {
Self.remoteMethodCtx('labelBarcodePdf', {
description: 'Returns the item label pdf with barcode',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The item id',
http: {source: 'path'}
}, {
arg: 'warehouseId',
type: 'number',
required: true
}, {
arg: 'packing',
type: 'number',
required: false
}, {
arg: 'copies',
type: 'number',
required: false
}
],
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/label-barcode-pdf',
verb: 'GET'
},
accessScopes: ['DEFAULT', 'read:multimedia']
});
Self.labelBarcodePdf = (ctx, id) => {
ctx.args.typeId = 'item';
return Self.printReport(ctx, id, 'item-label-barcode');
};
};

View File

@ -1,53 +0,0 @@
module.exports = Self => {
Self.remoteMethodCtx('labelQrPdf', {
description: 'Returns the item label pdf with qr',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The item id',
http: {source: 'path'}
}, {
arg: 'warehouseId',
type: 'number',
required: true
}, {
arg: 'packing',
type: 'number',
required: false
}, {
arg: 'copies',
type: 'number',
required: false
}
],
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/label-qr-pdf',
verb: 'GET'
},
accessScopes: ['DEFAULT', 'read:multimedia']
});
Self.labelQrPdf = (ctx, id) => {
ctx.args.userId = ctx.req.accessToken.userId;
ctx.args.typeId = 'item';
return Self.printReport(ctx, id, 'item-label-qr');
};
};

View File

@ -15,8 +15,6 @@ module.exports = Self => {
require('../methods/item/getWasteByItem')(Self); require('../methods/item/getWasteByItem')(Self);
require('../methods/item/createIntrastat')(Self); require('../methods/item/createIntrastat')(Self);
require('../methods/item/buyerWasteEmail')(Self); require('../methods/item/buyerWasteEmail')(Self);
require('../methods/item/labelBarcodePdf')(Self);
require('../methods/item/labelQrPdf')(Self);
require('../methods/item/setVisibleDiscard')(Self); require('../methods/item/setVisibleDiscard')(Self);
require('../methods/item/get')(Self); require('../methods/item/get')(Self);

View File

@ -1,16 +1,16 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body table v-for="item in items" style="break-before: page"> <body table v-for="buy in buys" style="break-before: page">
<table> <table>
<tr> <tr>
<td class="md-txt bold center black-bg lg-width md-height"> <td class="md-txt bold center black-bg lg-width md-height">
<div class="overflow-multiline"> <div class="overflow-multiline">
{{item.item}} {{buy.item}}
</div> </div>
</td> </td>
<td colspan="2" class="xl-txt bold center black-bg md-height md-width"> <td colspan="2" class="xl-txt bold center black-bg md-height md-width">
<div class="overflow-line"> <div class="overflow-line">
{{item.size}} {{buy.size}}
</div> </div>
</td> </td>
</tr> </tr>
@ -18,64 +18,64 @@
<td class="right lg-width"> <td class="right lg-width">
<div class="overflow-line"> <div class="overflow-line">
{{ {{
(item.longName && item.size && item.subName) (buy.longName && buy.size && buy.subName)
? `${item.longName} ${item.size} ${item.subName}` ? `${buy.longName} ${buy.size} ${buy.subName}`
: item.comment : buy.comment
}} }}
</div> </div>
</td> </td>
<td class="center sm-width"> <td class="center sm-width">
<div class="overflow-line"> <div class="overflow-line">
{{item.producerName || item.producerFk}} {{buy.producerName || buy.producerFk}}
</div> </div>
</td> </td>
<td class="center sm-width"> <td class="center sm-width">
<div class="overflow-line"> <div class="overflow-line">
{{item.inkFk}} {{buy.inkFk}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="md-txt xl-width bold center"> <td class="md-txt xl-width bold center">
<div class="overflow-line"> <div class="overflow-line">
{{item.itemFk}} {{buy.itemFk}}
</div> </div>
</td> </td>
<td colspan="2" class="md-txt md-width center"> <td colspan="2" class="md-txt md-width center">
<div class="overflow-line"> <div class="overflow-line">
{{`${(packing || item.packing)} x ${item.stems || ''}`}} {{`${(packing || buy.packing)} x ${buy.stems || ''}`}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td rowspan="2" class="center"> <td rowspan="2" class="center">
<div v-html="getBarcode(item.buyFk)"></div> <div v-html="getBarcode(buy.buyFk)"></div>
</td> </td>
<td colspan="2" class="center md-width xs-height xs-txt"> <td colspan="2" class="center md-width xs-height xs-txt">
<div v-if="item.isLaid && typeId === 'buy'" class="overflow-line black-bg bold"> <div v-if="buy.isLaid && typeId === 'buy'" class="overflow-line black-bg bold">
{{'LAID'}} {{'LAID'}}
</div> </div>
<div v-else class="overflow-line"> <div v-else class="overflow-line">
{{item.entryFk}} {{buy.entryFk}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="center xs-txt sm-width"> <td class="center xs-txt sm-width">
<div class="overflow-line"> <div class="overflow-line">
{{item.buyerName}} {{buy.buyerName}}
</div> </div>
</td> </td>
<td class="center xs-txt sm-width"> <td class="center xs-txt sm-width">
<div class="overflow-line"> <div class="overflow-line">
{{item.origin}} {{buy.origin}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="center xl-width"> <td class="center xl-width">
<div class="overflow-line"> <div class="overflow-line">
{{item.buyFk}} {{buy.buyFk}}
</div> </div>
</td> </td>
<td class="xs-txt sm-width center"> <td class="xs-txt sm-width center">
@ -85,7 +85,7 @@
</td> </td>
<td class="xs-txt sm-width cursive center bold"> <td class="xs-txt sm-width cursive center bold">
<div class="overflow-line"> <div class="overflow-line">
{{`${item.labelNum}/${item.quantity / (packing || item.packing)}`}} {{`${buy.labelNum}/${buy.quantity / (packing || buy.packing)}`}}
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -4,21 +4,11 @@ const moment = require('moment');
const jsbarcode = require('jsbarcode'); const jsbarcode = require('jsbarcode');
module.exports = { module.exports = {
name: 'item-label-barcode', name: 'buy-label-barcode',
async serverPrefetch() { async serverPrefetch() {
this.date = Date.vnNew(); this.date = Date.vnNew();
if (this.typeId === 'item') { this.buys = await this.rawSqlFromDef('buy', [this.copies || 1, this.id]);
this.company = await this.findOneFromDef('company', [this.warehouseId]); if (!this.buys.length) throw new UserError(`Empty data source`);
if (!this.company)
throw new UserError(`There is no company associated with that warehouse`);
this.lastBuy = await this.findOneFromDef('lastBuy', [
this.id,
this.warehouseId,
this.date
]);
}
this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.lastBuy?.id || this.id]);
if (!this.items.length) throw new UserError(`Empty data source`);
this.date = moment(this.date).format('WW/E'); this.date = moment(this.date).format('WW/E');
}, },
methods: { methods: {

View File

@ -23,7 +23,8 @@ SELECT ROW_NUMBER() OVER() labelNum,
ig.subName, ig.subName,
i.comment, i.comment,
w.code buyerName, w.code buyerName,
i.isLaid i.isLaid,
c.code company
FROM vn.buy b FROM vn.buy b
JOIN vn.item i ON i.id = b.itemFk JOIN vn.item i ON i.id = b.itemFk
LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk
@ -31,5 +32,7 @@ SELECT ROW_NUMBER() OVER() labelNum,
LEFT JOIN vn.producer p ON p.id = i.producerFk LEFT JOIN vn.producer p ON p.id = i.producerFk
JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.worker w ON w.id = it.workerFk JOIN vn.worker w ON w.id = it.workerFk
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.company c ON c.id = e.companyFk
JOIN numbers num JOIN numbers num
WHERE b.id = ? WHERE b.id = ?

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body v-for="item in items" style="break-before: page"> <body v-for="buy in buys" style="break-before: page">
<table class="leftTable"> <table class="leftTable">
<tr> <tr>
<td> <td>
@ -12,7 +12,7 @@
</tr> </tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
{{item.buyFk}} {{buy.buyFk}}
</td> </td>
</tr> </tr>
<tr> <tr>
@ -28,65 +28,65 @@
<tr> <tr>
<td colspan="3" class="lg-width black-bg center bold xl-txt padding"> <td colspan="3" class="lg-width black-bg center bold xl-txt padding">
<div class="overflow-line"> <div class="overflow-line">
{{item.itemFk}} {{buy.itemFk}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="2" class="black-bg center bold md-txt md-width md-height"> <td colspan="2" class="black-bg center bold md-txt md-width md-height">
<div class="overflow-multiline"> <div class="overflow-multiline">
{{item.item}} {{buy.item}}
</div> </div>
</td> </td>
<td class="xs-width black-bg center bold xl-txt"> <td class="xs-width black-bg center bold xl-txt">
<div class="overflow-line"> <div class="overflow-line">
{{item.size}} {{buy.size}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="sm-width"> <td class="sm-width">
<div class="overflow-line"> <div class="overflow-line">
<i>Color:</i> <b>{{item.inkFk}}</b> <i>Color:</i> <b>{{buy.inkFk}}</b>
</div> </div>
</td> </td>
<td rowspan="2" class="xs-width center md-txt"> <td rowspan="2" class="xs-width center md-txt">
<div class="overflow-line cell"> <div class="overflow-line cell">
{{packing || item.packing}} {{packing || buy.packing}}
</div> </div>
</td> </td>
<td rowspan="2" class="xs-width center md-txt"> <td rowspan="2" class="xs-width center md-txt">
<div class="overflow-line cell"> <div class="overflow-line cell">
{{item.stems}} {{buy.stems}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="sm-width"> <td class="sm-width">
<div class="overflow-line"> <div class="overflow-line">
<i>Origen:</i> {{item.origin}} <i>Origen:</i> {{buy.origin}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="2" class="md-width"> <td colspan="2" class="md-width">
<div class="overflow-line"> <div class="overflow-line">
<i>Productor:</i> {{item.producerName || item.producerFk}} <i>Productor:</i> {{buy.producerName || buy.producerFk}}
</div> </div>
</td> </td>
<td class="center xs-width xs-txt"> <td class="center xs-width xs-txt">
<div v-if="item.isLaid && typeId === 'buy'" class="overflow-line black-bg bold"> <div v-if="buy.isLaid && typeId === 'buy'" class="overflow-line black-bg bold">
{{'LAID'}} {{'LAID'}}
</div> </div>
<div v-else class="overflow-line"> <div v-else class="overflow-line">
{{item.entryFk}} {{buy.entryFk}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="sm-width"> <td class="sm-width">
<div class="overflow-line"> <div class="overflow-line">
<i>Comprador:</i> {{item.buyerName}} <i>Comprador:</i> {{buy.buyerName}}
</div> </div>
</td> </td>
<td rowspan="2" class="xs-width"> <td rowspan="2" class="xs-width">
@ -96,14 +96,14 @@
</td> </td>
<td rowspan="2" class="xs-width center cursive bold md-txt"> <td rowspan="2" class="xs-width center cursive bold md-txt">
<div class="overflow-line"> <div class="overflow-line">
{{`${item.labelNum}/${item.quantity / (packing || item.packing)}`}} {{`${buy.labelNum}/${buy.quantity / (packing || buy.packing)}`}}
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="sm-width"> <td class="sm-width">
<div class="overflow-line"> <div class="overflow-line">
<i>Entrada:</i> {{item.entryFk}} <i>Entrada:</i> {{buy.entryFk}}
</div> </div>
</td> </td>
</tr> </tr>
@ -111,9 +111,9 @@
<td colspan="3" class="lg-width center cursive bold"> <td colspan="3" class="lg-width center cursive bold">
<div class="overflow-line"> <div class="overflow-line">
{{ {{
(item.longName && item.size && item.subName) (buy.longName && buy.size && buy.subName)
? `${item.longName} ${item.size} ${item.subName}` ? `${buy.longName} ${buy.size} ${buy.subName}`
: item.comment : buy.comment
}} }}
</div> </div>
</td> </td>

View File

@ -3,28 +3,18 @@ const moment = require('moment');
const qrcode = require('qrcode'); const qrcode = require('qrcode');
module.exports = { module.exports = {
name: 'item-label-qr', name: 'buy-label-qr',
async serverPrefetch() { async serverPrefetch() {
this.date = Date.vnNew(); this.date = Date.vnNew();
if (this.typeId === 'item') { this.buys = await this.rawSqlFromDef('buy', [this.copies || 1, this.id]);
this.company = await this.findOneFromDef('company', [this.warehouseId]); if (!this.buys.length) throw new UserError(`Empty data source`);
if (!this.company) this.qr = await this.getQr(this.buys[0].buyFk);
throw new UserError(`There is no company associated with that warehouse`);
this.lastBuy = await this.findOneFromDef('lastBuy', [
this.id,
this.warehouseId,
this.date
]);
}
this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.lastBuy?.id || this.id]);
if (!this.items.length) throw new UserError(`Empty data source`);
this.qr = await this.getQr(this.items[0].buyFk);
this.date = moment(this.date).format('WW/E'); this.date = moment(this.date).format('WW/E');
}, },
methods: { methods: {
getQr(data) { getQr(data) {
data = { data = {
company: this.company, company: this.buys.company,
user: this.userId, user: this.userId,
created: this.date, created: this.date,
table: 'buy', table: 'buy',

View File

@ -23,7 +23,8 @@ SELECT ROW_NUMBER() OVER() labelNum,
ig.subName, ig.subName,
i.comment, i.comment,
w.code buyerName, w.code buyerName,
i.isLaid i.isLaid,
c.code company
FROM vn.buy b FROM vn.buy b
JOIN vn.item i ON i.id = b.itemFk JOIN vn.item i ON i.id = b.itemFk
LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk
@ -31,5 +32,7 @@ SELECT ROW_NUMBER() OVER() labelNum,
LEFT JOIN vn.producer p ON p.id = i.producerFk LEFT JOIN vn.producer p ON p.id = i.producerFk
JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.worker w ON w.id = it.workerFk JOIN vn.worker w ON w.id = it.workerFk
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.company c ON c.id = e.companyFk
JOIN numbers num JOIN numbers num
WHERE b.id = ? WHERE b.id = ?

View File

@ -5,7 +5,7 @@ const jsBarcode = require('jsbarcode');
const moment = require('moment'); const moment = require('moment');
module.exports = { module.exports = {
name: 'buy-label', name: 'buy-label-supplier',
mixins: [vnReport], mixins: [vnReport],
async serverPrefetch() { async serverPrefetch() {
const buy = await models.Buy.findById(this.id, null); const buy = await models.Buy.findById(this.id, null);

View File

@ -1,5 +0,0 @@
SELECT co.code
FROM warehouse w
JOIN address a ON a.id = w.addressFk
JOIN company co ON co.clientFk = a.clientFk
WHERE w.id = ?

View File

@ -1 +0,0 @@
SELECT buy_getUltimate(?, ?, ?) id

View File

@ -1,5 +0,0 @@
SELECT co.code
FROM warehouse w
JOIN address a ON a.id = w.addressFk
JOIN company co ON co.clientFk = a.clientFk
WHERE w.id = ?

View File

@ -1 +0,0 @@
SELECT buy_getUltimate(?, ?, ?) id