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) => {
const userId = ctx.req.accessToken.userId;
const origin = ctx.req.headers.origin;
const url = Self.app.models.Application.getUrl();
const $t = ctx.req.__;
const myOptions = {};
@ -36,7 +36,6 @@ module.exports = Self => {
myOptions.userId = userId;
const promises = [];
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
const sales = await Self.rawSql(`
SELECT s.ticketFk,
@ -46,11 +45,11 @@ module.exports = Self => {
i.longName,
i.size,
ic.color,
o.code origin,
o.code url,
ish.packing,
ish.grouping,
s.isAdded,
s.originalQuantity,
s.urlalQuantity,
s.quantity saleQuantity,
iss.quantity reservedQuantity,
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 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
LEFT JOIN url o ON o.id = i.urlFk
WHERE tc.collectionFk = ?
GROUP BY ish.id, p.code, p2.code
ORDER BY pickingOrder;`, [id], myOptions);
@ -86,24 +85,19 @@ module.exports = Self => {
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`,
ticketUrl: `${url}/#!/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
@ -114,13 +108,10 @@ module.exports = Self => {
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) {
@ -131,7 +122,6 @@ module.exports = Self => {
}
}
}
ticket.sales.push(sale);
}
}
@ -140,7 +130,6 @@ module.exports = Self => {
}
}
await Promise.all(promises);
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) {
require('../methods/application/status')(Self);
require('../methods/application/post')(Self);
require('../methods/application/getUrl')(Self);
};

View File

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

View File

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

View File

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

View File

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