7152-devToTest_2414 #2228
|
@ -7,18 +7,11 @@ module.exports = Self => {
|
||||||
arg: 'collectionOrTicketFk',
|
arg: 'collectionOrTicketFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
}, {
|
||||||
{
|
arg: 'print',
|
||||||
arg: 'sectorFk',
|
type: 'boolean',
|
||||||
type: 'number',
|
|
||||||
required: true
|
required: true
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
arg: 'printFk',
|
|
||||||
type: 'number',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'source',
|
arg: 'source',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
|
@ -35,36 +28,34 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, sectorFk, printFk, source, options) => {
|
Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, print, source, options) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {userId};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const [collectionOrTicket] = await Self.rawSql('SELECT vn.ticket_get(?) as id', [collectionOrTicketFk]);
|
const [{id}] = await Self.rawSql('SELECT vn.ticket_get(?) as id',
|
||||||
|
[collectionOrTicketFk],
|
||||||
|
myOptions);
|
||||||
|
|
||||||
const [tickets] = await Self.rawSql('CALL vn.collection_getTickets(?)', [collectionOrTicket.id]);
|
const [tickets] = await Self.rawSql('CALL vn.collection_getTickets(?)', [id], myOptions);
|
||||||
|
|
||||||
if (source == 'PRECHECKER' || source == 'ON_CHECKING') {
|
await setState(source, id, myOptions);
|
||||||
await Self.rawSql(
|
const [sales] = await Self.rawSql('CALL vn.sale_getFromTicketOrCollection(?)',
|
||||||
'CALL vn.ticketStateToday_setState(?,?)',
|
[id], myOptions);
|
||||||
[collectionOrTicket.id, source]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [sales] = await Self.rawSql('CALL vn.sale_getFromTicketOrCollection(?)', [collectionOrTicket.id]);
|
|
||||||
|
|
||||||
const isPicker = source == 'CHECKER';
|
const isPicker = source == 'CHECKER';
|
||||||
const [placements] = await Self.rawSql(
|
const [placements] = await Self.rawSql('CALL vn.collectionPlacement_get(?, ?)',
|
||||||
'CALL vn.collectionPlacement_get(?, ?)', [collectionOrTicket.id, isPicker]
|
[id, isPicker], myOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
if (printFk == 1) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [collectionOrTicket.id]);
|
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
|
||||||
|
|
||||||
if (tickets.length) await sendRocketTickets(tickets);
|
if (tickets.length) await sendRocketTickets(tickets);
|
||||||
|
|
||||||
return getCollection(collectionOrTicket.id, tickets, sales, placements);
|
return getCollection(id, tickets, sales, placements, myOptions);
|
||||||
|
|
||||||
async function sendRocketTickets(tickets) {
|
async function sendRocketTickets(tickets) {
|
||||||
for (let ticket of tickets) {
|
for (let ticket of tickets) {
|
||||||
|
@ -83,7 +74,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCollection(id, tickets, sales, placements) {
|
async function getCollection(id, tickets, sales, placements, options) {
|
||||||
const collection = {
|
const collection = {
|
||||||
collectionFk: id,
|
collectionFk: id,
|
||||||
tickets: [],
|
tickets: [],
|
||||||
|
@ -95,7 +86,8 @@ module.exports = Self => {
|
||||||
const barcodes = await getBarcodes(ticketFk);
|
const barcodes = await getBarcodes(ticketFk);
|
||||||
await Self.rawSql(
|
await Self.rawSql(
|
||||||
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
|
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null]
|
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let sale of sales) {
|
for (let sale of sales) {
|
||||||
|
@ -106,7 +98,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
sale.barcodes = [];
|
sale.barcodes = [];
|
||||||
for (const barcode of barcodes) {
|
for (const barcode of barcodes) {
|
||||||
if (barcode.movementId) {
|
if (barcode.movementId == sale.saleFk) {
|
||||||
if (barcode.code) {
|
if (barcode.code) {
|
||||||
sale.barcodes.push(barcode.code);
|
sale.barcodes.push(barcode.code);
|
||||||
sale.barcodes.push(`0 ${barcode.code}`);
|
sale.barcodes.push(`0 ${barcode.code}`);
|
||||||
|
@ -142,5 +134,19 @@ module.exports = Self => {
|
||||||
AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`;
|
AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`;
|
||||||
return Self.rawSql(query, [ticketId]);
|
return Self.rawSql(query, [ticketId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setState(source, id, options) {
|
||||||
|
let state;
|
||||||
|
if (source == 'PRECHECKER') state = 'PREVIOUS_CONTROL';
|
||||||
|
else if (source == 'CHECKER') state = 'ON_CHECKING';
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
await Self.rawSql(
|
||||||
|
'CALL vn.ticketStateToday_setState(?,?)',
|
||||||
|
[id, source],
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
fdescribe('collection getSalesFromTicketOrCollection()', () => {
|
||||||
|
const collectionOrTicketFk = 999999;
|
||||||
|
const print = true;
|
||||||
|
const source = 'CHECKER';
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
headers: {origin: 'http://localhost'},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a collection with tickets, placements and barcodes settled correctly', async() => {
|
||||||
|
const options = {};
|
||||||
|
const collection = await models.Collection.getSalesFromTicketOrCollection(ctx,
|
||||||
|
collectionOrTicketFk, print, source, options);
|
||||||
|
|
||||||
|
const [firstTicket] = collection.tickets;
|
||||||
|
const [firstSale] = firstTicket.sales;
|
||||||
|
const [firstPlacement] = firstSale.placements;
|
||||||
|
|
||||||
|
expect(collection.tickets.length).toBeGreaterThan(0);
|
||||||
|
expect(collection.collectionFk).toEqual(firstTicket.ticketFk);
|
||||||
|
|
||||||
|
expect(firstSale.ticketFk).toEqual(firstTicket.ticketFk);
|
||||||
|
expect(firstSale.placements.length).toBeGreaterThan(0);
|
||||||
|
expect(firstSale.barcodes.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
expect(firstSale.saleFk).toEqual(firstPlacement.saleFk);
|
||||||
|
});
|
||||||
|
});
|
|
@ -3711,4 +3711,6 @@ INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) VALUES (104,1,'2001-01-
|
||||||
|
|
||||||
UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1;
|
UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1;
|
||||||
|
|
||||||
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
|
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
|
||||||
|
|
||||||
|
INSERT INTO vn.report (name) VALUES ('LabelCollection')
|
|
@ -351,5 +351,6 @@
|
||||||
"No se ha podido marcar la línea": "No se ha podido marcar la línea",
|
"No se ha podido marcar la línea": "No se ha podido marcar la línea",
|
||||||
"The sale can not be tracked": "La línea no puede ser rastreada",
|
"The sale can not be tracked": "La línea no puede ser rastreada",
|
||||||
"Shelving not valid": "Carro no válido",
|
"Shelving not valid": "Carro no válido",
|
||||||
"Carro no válido": "Carro no válido"
|
"Carro no válido": "Carro no válido",
|
||||||
|
"printerNotExists": "printerNotExists"
|
||||||
}
|
}
|
Loading…
Reference in New Issue