This commit is contained in:
Pablo Natek 2023-10-15 11:08:33 +02:00
parent dea3bb7a98
commit f832c1d9ec
7 changed files with 54 additions and 28 deletions

View File

@ -26,7 +26,7 @@ module.exports = Self => {
Self.getTickets = async(ctx, id, print, options) => { Self.getTickets = async(ctx, id, print, options) => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const origin = ctx.req.headers.origin; const url = Self.app.models.Application.getUrl();
const $t = ctx.req.__; const $t = ctx.req.__;
const myOptions = {}; const myOptions = {};
@ -36,7 +36,6 @@ module.exports = Self => {
myOptions.userId = userId; myOptions.userId = userId;
const promises = []; const promises = [];
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions); const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
const sales = await Self.rawSql(` const sales = await Self.rawSql(`
SELECT s.ticketFk, SELECT s.ticketFk,
@ -46,11 +45,11 @@ module.exports = Self => {
i.longName, i.longName,
i.size, i.size,
ic.color, ic.color,
o.code origin, o.code url,
ish.packing, ish.packing,
ish.grouping, ish.grouping,
s.isAdded, s.isAdded,
s.originalQuantity, s.urlalQuantity,
s.quantity saleQuantity, s.quantity saleQuantity,
iss.quantity reservedQuantity, iss.quantity reservedQuantity,
SUM(iss.quantity) OVER (PARTITION BY s.id ORDER BY ish.id) accumulatedQuantity, SUM(iss.quantity) OVER (PARTITION BY s.id ORDER BY ish.id) accumulatedQuantity,
@ -74,7 +73,7 @@ module.exports = Self => {
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN shelving sh ON sh.code = ish.shelvingFk
LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN parking p ON p.id = sh.parkingFk
LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
LEFT JOIN origin o ON o.id = i.originFk LEFT JOIN url o ON o.id = i.urlFk
WHERE tc.collectionFk = ? WHERE tc.collectionFk = ?
GROUP BY ish.id, p.code, p2.code GROUP BY ish.id, p.code, p2.code
ORDER BY pickingOrder;`, [id], myOptions); ORDER BY pickingOrder;`, [id], myOptions);
@ -86,24 +85,19 @@ module.exports = Self => {
if (tickets && tickets.length) { if (tickets && tickets.length) {
for (const ticket of tickets) { for (const ticket of tickets) {
const ticketId = ticket.ticketFk; const ticketId = ticket.ticketFk;
// SEND ROCKET
if (ticket.observaciones != '') { if (ticket.observaciones != '') {
for (observation of ticket.observaciones.split(' ')) { for (observation of ticket.observaciones.split(' ')) {
if (['#', '@'].includes(observation.charAt(0))) { if (['#', '@'].includes(observation.charAt(0))) {
promises.push(Self.app.models.Chat.send(ctx, observation, promises.push(Self.app.models.Chat.send(ctx, observation,
$t('The ticket is in preparation', { $t('The ticket is in preparation', {
ticketId: ticketId, ticketId: ticketId,
ticketUrl: `${origin}/#!/ticket/${ticketId}/summary`, ticketUrl: `${url}/#!/ticket/${ticketId}/summary`,
salesPersonId: ticket.salesPersonFk salesPersonId: ticket.salesPersonFk
}))); })));
} }
} }
} }
// SET COLLECTION
if (sales && sales.length) { if (sales && sales.length) {
// GET BARCODES
const barcodes = await Self.rawSql(` const barcodes = await Self.rawSql(`
SELECT s.id saleFk, b.code, c.id SELECT s.id saleFk, b.code, c.id
FROM vn.sale s FROM vn.sale s
@ -114,13 +108,10 @@ module.exports = Self => {
WHERE s.ticketFk = ? WHERE s.ticketFk = ?
AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`, AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`,
[ticketId], myOptions); [ticketId], myOptions);
// BINDINGS
ticket.sales = []; ticket.sales = [];
for (const sale of sales) { for (const sale of sales) {
if (sale.ticketFk === ticketId) { if (sale.ticketFk === ticketId) {
sale.Barcodes = []; sale.Barcodes = [];
if (barcodes && barcodes.length) { if (barcodes && barcodes.length) {
for (const barcode of barcodes) { for (const barcode of barcodes) {
if (barcode.saleFk === sale.saleFk) { if (barcode.saleFk === sale.saleFk) {
@ -131,7 +122,6 @@ module.exports = Self => {
} }
} }
} }
ticket.sales.push(sale); ticket.sales.push(sale);
} }
} }
@ -140,7 +130,6 @@ module.exports = Self => {
} }
} }
await Promise.all(promises); await Promise.all(promises);
return collection; return collection;
}; };
}; };

View File

@ -0,0 +1,29 @@
module.exports = Self => {
Self.remoteMethodCtx('getUrl', {
description: 'Returns the colling app name',
accepts: [
{
arg: 'appName',
type: 'string',
required: false
}
],
returns: {
type: 'object',
root: true
},
http: {
path: `/getUrl`,
verb: 'get'
}
});
Self.getUrl = async(appName = 'salix') => {
const {url} = Self.app.models.Url.findOne({
where: {
appName,
enviroment: process.env.NODE_ENV || 'development'
}
});
return url;
};
};

View File

@ -2,4 +2,5 @@
module.exports = function(Self) { module.exports = function(Self) {
require('../methods/application/status')(Self); require('../methods/application/status')(Self);
require('../methods/application/post')(Self); require('../methods/application/post')(Self);
require('../methods/application/getUrl')(Self);
}; };

View File

@ -13,6 +13,12 @@
"principalType": "ROLE", "principalType": "ROLE",
"principalId": "$everyone", "principalId": "$everyone",
"permission": "ALLOW" "permission": "ALLOW"
} },
{
"property": "getUrl",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
] ]
} }

View File

@ -43,9 +43,8 @@ module.exports = Self => {
Self.claimPickupEmail = async ctx => { Self.claimPickupEmail = async ctx => {
const models = Self.app.models; const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const origin = ctx.req.headers.origin; const url = await Self.app.models.Application.getUrl();
const args = Object.assign({}, ctx.args); const args = Object.assign({}, ctx.args);
const params = { const params = {
@ -70,9 +69,9 @@ module.exports = Self => {
const message = $t('Claim pickup order sent', { const message = $t('Claim pickup order sent', {
claimId: args.id, claimId: args.id,
clientName: claim.client().name, clientName: claim.client().name,
claimUrl: `${origin}/#!/claim/${args.id}/summary`, claimUrl: `${url}/claim/${args.id}/summary`,
}); });
console.log(message);
const salesPersonId = claim.client().salesPersonFk; const salesPersonId = claim.client().salesPersonFk;
if (salesPersonId) if (salesPersonId)
await models.Chat.sendCheckingPresence(ctx, salesPersonId, message); await models.Chat.sendCheckingPresence(ctx, salesPersonId, message);

View File

@ -115,27 +115,28 @@ module.exports = Self => {
async function notifyStateChange(ctx, workerId, claim, state) { async function notifyStateChange(ctx, workerId, claim, state) {
const models = Self.app.models; const models = Self.app.models;
const origin = ctx.req.headers.origin; const url = await models.Application.getUrl();
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const message = $t(`Claim state has changed to ${state}`, { const message = $t(`Claim state has changed to ${state}`, {
claimId: claim.id, claimId: claim.id,
clientName: claim.client().name, clientName: claim.client().name,
claimUrl: `${origin}/#!/claim/${claim.id}/summary` claimUrl: `${url}/claim/${claim.id}/summary`
}); });
await models.Chat.sendCheckingPresence(ctx, workerId, message); await models.Chat.sendCheckingPresence(ctx, workerId, message);
} }
async function notifyPickUp(ctx, workerId, claim) { async function notifyPickUp(ctx, workerId, claim) {
const origin = ctx.req.headers.origin;
const models = Self.app.models; const models = Self.app.models;
const url = await models.Application.getUrl();
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const message = $t('Claim will be picked', { const message = $t('Claim will be picked', {
claimId: claim.id, claimId: claim.id,
clientName: claim.client().name, clientName: claim.client().name,
claimUrl: `${origin}/#!/claim/${claim.id}/summary` claimUrl: `${url}/claim/${claim.id}/summary`
}); });
console.log(message);
await models.Chat.sendCheckingPresence(ctx, workerId, message); await models.Chat.sendCheckingPresence(ctx, workerId, message);
} }
}; };

View File

@ -80,16 +80,17 @@ module.exports = Self => {
const salesPerson = sale.ticket().client().salesPersonUser(); const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const origin = ctx.req.headers.origin; const url = await models.Application.getUrl();
const message = $t('Changed sale quantity', { const message = $t('Changed sale quantity', {
ticketId: sale.ticket().id, ticketId: sale.ticket().id,
itemId: sale.itemFk, itemId: sale.itemFk,
concept: sale.concept, concept: sale.concept,
oldQuantity: oldQuantity, oldQuantity: oldQuantity,
newQuantity: newQuantity, newQuantity: newQuantity,
ticketUrl: `${origin}/#!/ticket/${sale.ticket().id}/sale`, ticketUrl: `${url}/ticket/${sale.ticket().id}/sale`,
itemUrl: `${origin}/#!/item/${sale.itemFk}/summary` itemUrl: `${url}/item/${sale.itemFk}/summary`
}); });
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions);
} }