refs #6254 collection_getTickets
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
d4e5815d41
commit
9a7cb3ef7b
|
@ -30,46 +30,37 @@ module.exports = Self => {
|
|||
const $t = ctx.req.__; // $translate
|
||||
const myOptions = {};
|
||||
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
myOptions.userId = userId;
|
||||
|
||||
const promises = [];
|
||||
try {
|
||||
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
|
||||
const sales = await Self.rawSql(`
|
||||
SELECT
|
||||
s.ticketFk,
|
||||
|
||||
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,
|
||||
IFNULL(sub2.semaphore,st.semaphore) semaphore,
|
||||
ic.color,
|
||||
ip.productor,
|
||||
o.code origin,
|
||||
s.concept,
|
||||
b.packing,
|
||||
b.grouping,
|
||||
ish.packing,
|
||||
ish.grouping,
|
||||
s.isAdded,
|
||||
c.workerFk,
|
||||
i.packingShelve,
|
||||
sm.id hasMistake,
|
||||
s.originalQuantity,
|
||||
s.quantity saleQuantity,
|
||||
IF(p2.code IS NOT NULL, s.quantity, iss.quantity) reservedQuantity,
|
||||
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.isChecked
|
||||
FROM ticketCollection tc
|
||||
LEFT JOIN collection c ON c.id = tc.collectionFk
|
||||
JOIN ticket t ON t.id = tc.ticketFk
|
||||
|
@ -77,103 +68,79 @@ module.exports = Self => {
|
|||
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
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk
|
||||
LEFT JOIN buy b ON b.id = lb.buy_id
|
||||
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 (
|
||||
SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity, sub.semaphore
|
||||
FROM (
|
||||
SELECT DISTINCT st.id,
|
||||
st.saleFk, st.isChecked, st.stateFk, st.originalQuantity ,sta.semaphore
|
||||
FROM ticketCollection tc
|
||||
JOIN sale s ON s.ticketFk = tc.ticketFk
|
||||
JOIN saleTracking st ON st.saleFk = s.id
|
||||
JOIN state sta ON sta.id = st.stateFk
|
||||
WHERE tc.collectionFk = ?
|
||||
ORDER BY st.id DESC
|
||||
LIMIT 10000000000000000000) sub
|
||||
GROUP BY sub.saleFk, sub.stateFK
|
||||
) sub2 ON sub2.saleFk = s.id AND sub2.isChecked = 1
|
||||
LEFT JOIN state st ON st.id = sub2.stateFk
|
||||
LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
|
||||
LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk
|
||||
LEFT JOIN origin o ON o.id = i.originFk
|
||||
LEFT JOIN saleMistake sm ON sm.saleFk = s.id
|
||||
WHERE tc.collectionFk = ?
|
||||
GROUP BY s.id, p.code, p2.code
|
||||
ORDER BY pickingOrder`, [id, id], myOptions);
|
||||
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);
|
||||
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;
|
||||
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
|
||||
})));
|
||||
}
|
||||
// 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 >= DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR)`,
|
||||
[ticketId], myOptions);
|
||||
// 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 = [];
|
||||
// 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 (let prop in barcode) {
|
||||
if (['id', 'code'].includes(prop) && barcode[prop])
|
||||
sale.Barcodes.push(barcode[prop].toString(), '0' + barcode[prop]);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
ticket.sales.push(sale);
|
||||
}
|
||||
}
|
||||
collection.tickets.push(ticket);
|
||||
}
|
||||
collection.tickets.push(ticket);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
await Promise.all(promises);
|
||||
|
||||
return collection;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
await Promise.all(promises);
|
||||
|
||||
return collection;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -318,6 +318,5 @@
|
|||
"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",
|
||||
"Ticket without Route": "Ticket sin ruta",
|
||||
"The ticket is in preparation": "El ticket [{{ticketId}}]({{{ticketUrl}}}) del comercial {{salesPersonId}} està en preparación",
|
||||
"Invalid collection or ticket": "Invalid collection or ticket"
|
||||
"The ticket is in preparation": "El ticket [{{ticketId}}]({{{ticketUrl}}}) del comercial {{salesPersonId}} està en preparación"
|
||||
}
|
Loading…
Reference in New Issue