Merge pull request '6254-collection_getTickets' (!1769) from 6254-collection_getTickets into test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1769 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
83d1e5cb74
|
@ -0,0 +1,146 @@
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('getTickets', {
|
||||||
|
description: 'Make a new collection of tickets',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The collection id',
|
||||||
|
required: true,
|
||||||
|
http: {source: 'path'}
|
||||||
|
}, {
|
||||||
|
arg: 'print',
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'True if you want to print'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:id/getTickets`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getTickets = async(ctx, id, print, options) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const origin = ctx.req.headers.origin;
|
||||||
|
const $t = ctx.req.__;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
myOptions.userId = userId;
|
||||||
|
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
|
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
|
||||||
|
const sales = await Self.rawSql(`
|
||||||
|
SELECT s.ticketFk,
|
||||||
|
sgd.saleGroupFk,
|
||||||
|
s.id saleFk,
|
||||||
|
s.itemFk,
|
||||||
|
i.longName,
|
||||||
|
i.size,
|
||||||
|
ic.color,
|
||||||
|
o.code origin,
|
||||||
|
ish.packing,
|
||||||
|
ish.grouping,
|
||||||
|
s.isAdded,
|
||||||
|
s.originalQuantity,
|
||||||
|
s.quantity saleQuantity,
|
||||||
|
iss.quantity reservedQuantity,
|
||||||
|
SUM(iss.quantity) OVER (PARTITION BY s.id ORDER BY ish.id) accumulatedQuantity,
|
||||||
|
ROW_NUMBER () OVER (PARTITION BY s.id ORDER BY pickingOrder) currentItemShelving,
|
||||||
|
COUNT(*) OVER (PARTITION BY s.id ORDER BY s.id) totalItemShelving,
|
||||||
|
sh.code,
|
||||||
|
IFNULL(p2.code, p.code) parkingCode,
|
||||||
|
IFNULL(p2.pickingOrder, p.pickingOrder) pickingOrder,
|
||||||
|
iss.id itemShelvingSaleFk,
|
||||||
|
iss.isPicked
|
||||||
|
FROM ticketCollection tc
|
||||||
|
LEFT JOIN collection c ON c.id = tc.collectionFk
|
||||||
|
JOIN ticket t ON t.id = tc.ticketFk
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||||
|
LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
||||||
|
LEFT JOIN parking p2 ON p2.id = sg.parkingFk
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
|
||||||
|
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
||||||
|
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk
|
||||||
|
LEFT JOIN parking p ON p.id = sh.parkingFk
|
||||||
|
LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
|
||||||
|
LEFT JOIN origin o ON o.id = i.originFk
|
||||||
|
WHERE tc.collectionFk = ?
|
||||||
|
GROUP BY ish.id, p.code, p2.code
|
||||||
|
ORDER BY pickingOrder;`, [id], myOptions);
|
||||||
|
|
||||||
|
if (print)
|
||||||
|
await Self.rawSql(`CALL vn.collection_printSticker(?, ?)`, [id, null], myOptions);
|
||||||
|
|
||||||
|
const collection = {collectionFk: id, tickets: []};
|
||||||
|
if (tickets && tickets.length) {
|
||||||
|
for (const ticket of tickets) {
|
||||||
|
const ticketId = ticket.ticketFk;
|
||||||
|
|
||||||
|
// SEND ROCKET
|
||||||
|
if (ticket.observaciones != '') {
|
||||||
|
for (observation of ticket.observaciones.split(' ')) {
|
||||||
|
if (['#', '@'].includes(observation.charAt(0))) {
|
||||||
|
promises.push(Self.app.models.Chat.send(ctx, observation,
|
||||||
|
$t('The ticket is in preparation', {
|
||||||
|
ticketId: ticketId,
|
||||||
|
ticketUrl: `${origin}/#!/ticket/${ticketId}/summary`,
|
||||||
|
salesPersonId: ticket.salesPersonFk
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET COLLECTION
|
||||||
|
if (sales && sales.length) {
|
||||||
|
// GET BARCODES
|
||||||
|
const barcodes = await Self.rawSql(`
|
||||||
|
SELECT s.id saleFk, b.code, c.id
|
||||||
|
FROM vn.sale s
|
||||||
|
LEFT JOIN vn.itemBarcode b ON b.itemFk = s.itemFk
|
||||||
|
LEFT JOIN vn.buy c ON c.itemFk = s.itemFk
|
||||||
|
LEFT JOIN vn.entry e ON e.id = c.entryFk
|
||||||
|
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
|
||||||
|
WHERE s.ticketFk = ?
|
||||||
|
AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`,
|
||||||
|
[ticketId], myOptions);
|
||||||
|
|
||||||
|
// BINDINGS
|
||||||
|
ticket.sales = [];
|
||||||
|
for (const sale of sales) {
|
||||||
|
if (sale.ticketFk === ticketId) {
|
||||||
|
sale.Barcodes = [];
|
||||||
|
|
||||||
|
if (barcodes && barcodes.length) {
|
||||||
|
for (const barcode of barcodes) {
|
||||||
|
if (barcode.saleFk === sale.saleFk) {
|
||||||
|
for (const prop in barcode) {
|
||||||
|
if (['id', 'code'].includes(prop) && barcode[prop])
|
||||||
|
sale.Barcodes.push(barcode[prop].toString(), '0' + barcode[prop]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ticket.sales.push(sale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collection.tickets.push(ticket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,39 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('collection getTickets()', () => {
|
||||||
|
let ctx;
|
||||||
|
beforeAll(async() => {
|
||||||
|
ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get tickets, sales and barcodes from collection', async() => {
|
||||||
|
const tx = await models.Collection.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const collectionId = 1;
|
||||||
|
|
||||||
|
const collectionTickets = await models.Collection.getTickets(ctx, collectionId, null, options);
|
||||||
|
|
||||||
|
expect(collectionTickets.collectionFk).toEqual(collectionId);
|
||||||
|
expect(collectionTickets.tickets.length).toEqual(3);
|
||||||
|
expect(collectionTickets.tickets[0].ticketFk).toEqual(1);
|
||||||
|
expect(collectionTickets.tickets[1].ticketFk).toEqual(2);
|
||||||
|
expect(collectionTickets.tickets[2].ticketFk).toEqual(23);
|
||||||
|
expect(collectionTickets.tickets[0].sales[0].ticketFk).toEqual(1);
|
||||||
|
expect(collectionTickets.tickets[0].sales[1].ticketFk).toEqual(1);
|
||||||
|
expect(collectionTickets.tickets[0].sales[2].ticketFk).toEqual(1);
|
||||||
|
expect(collectionTickets.tickets[0].sales[0].Barcodes.length).toBeTruthy();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -4,4 +4,5 @@ module.exports = Self => {
|
||||||
require('../methods/collection/getSectors')(Self);
|
require('../methods/collection/getSectors')(Self);
|
||||||
require('../methods/collection/setSaleQuantity')(Self);
|
require('../methods/collection/setSaleQuantity')(Self);
|
||||||
require('../methods/collection/previousLabel')(Self);
|
require('../methods/collection/previousLabel')(Self);
|
||||||
|
require('../methods/collection/getTickets')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL`(model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('Collection', 'getTickets', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
@ -188,5 +188,6 @@
|
||||||
"The ticket doesn't exist.": "The ticket doesn't exist.",
|
"The ticket doesn't exist.": "The ticket doesn't exist.",
|
||||||
"The sales do not exists": "The sales do not exists",
|
"The sales do not exists": "The sales do not exists",
|
||||||
"Ticket without Route": "Ticket without route",
|
"Ticket without Route": "Ticket without route",
|
||||||
"Booking completed": "Booking completed"
|
"Booking completed": "Booking complete",
|
||||||
|
"The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation"
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,5 +318,6 @@
|
||||||
"Street should be uppercase": "La dirección fiscal debe ir en mayúscula",
|
"Street should be uppercase": "La dirección fiscal debe ir en mayúscula",
|
||||||
"The response is not a PDF": "La respuesta no es un PDF",
|
"The response is not a PDF": "La respuesta no es un PDF",
|
||||||
"Ticket without Route": "Ticket sin ruta",
|
"Ticket without Route": "Ticket sin ruta",
|
||||||
"Booking completed": "Reserva completada"
|
"Booking completed": "Reserva completada",
|
||||||
}
|
"The ticket is in preparation": "El ticket [{{ticketId}}]({{{ticketUrl}}}) del comercial {{salesPersonId}} está en preparación"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue