Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-test This commit looks good Details

This commit is contained in:
Alex Moreno 2025-02-04 13:03:17 +01:00
commit fe7a1c60cc
12 changed files with 57 additions and 54 deletions

View File

@ -24,7 +24,7 @@ BEGIN
SELECT ish.id, SELECT ish.id,
p.pickingOrder, p.pickingOrder,
p.code parking, p.code parking,
ish.shelvingFk, sh.code,
ish.itemFk, ish.itemFk,
i.longName, i.longName,
ish.visible, ish.visible,

View File

@ -20,6 +20,7 @@ trig:BEGIN
THEN THEN
CALL entry_isEditable(OLD.entryFk); CALL entry_isEditable(OLD.entryFk);
CALL entry_isEditable(NEW.entryFk);
END IF; END IF;
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
@ -88,11 +89,11 @@ trig:BEGIN
SET NEW.buyerFk = vBuyerFk; SET NEW.buyerFk = vBuyerFk;
END IF; END IF;
IF NOT (NEW.itemFk <=> OLD.itemFk) OR IF NOT (NEW.itemFk <=> OLD.itemFk) OR
NOT (OLD.entryFk <=> NEW.entryFk) THEN NOT (OLD.entryFk <=> NEW.entryFk) THEN
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck
SELECT NEW.id; SELECT NEW.id;
CALL buy_checkItem(); CALL buy_checkItem();
END IF; END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -6,8 +6,7 @@ BEGIN
INSERT INTO zoneLog INSERT INTO zoneLog
SET `action` = 'delete', SET `action` = 'delete',
`changedModel` = 'zoneIncluded', `changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk, `changedModelId` = OLD.id,
`userFk` = account.myUser_getId(); `userFk` = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -253,5 +253,5 @@
"Sales already moved": "Sales already moved", "Sales already moved": "Sales already moved",
"Holidays to past days not available": "Holidays to past days not available", "Holidays to past days not available": "Holidays to past days not available",
"Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}",
"Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order." "Ticket has been delivered out of order": "The ticket {{ticket}} of route {{{fullUrl}}} has been delivered out of order."
} }

View File

@ -397,4 +397,5 @@
"Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}",
"Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sido entregado en su orden.", "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sido entregado en su orden.",
"Price cannot be blank": "El precio no puede estar en blanco" "Price cannot be blank": "El precio no puede estar en blanco"
} }

View File

@ -368,5 +368,5 @@
"ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}",
"The web user's email already exists": "L'email de l'internaute existe déjà", "The web user's email already exists": "L'email de l'internaute existe déjà",
"Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}", "Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}",
"Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre." "Ticket has been delivered out of order": "Le ticket {{ticket}} de la route {{{fullUrl}}} a été livré hors service."
} }

View File

@ -367,5 +367,5 @@
"ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}",
"The web user's email already exists": "O e-mail do utilizador da web já existe.", "The web user's email already exists": "O e-mail do utilizador da web já existe.",
"Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}", "Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}",
"Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem." "Ticket has been delivered out of order": "O ticket {{ticket}} da rota {{{fullUrl}}} foi entregue fora de ordem."
} }

View File

@ -109,7 +109,8 @@ module.exports = Self => {
where: { where: {
clientFk: clientFk, clientFk: clientFk,
shipped: {lte: maxShipped} shipped: {lte: maxShipped}
} },
order: 'shipped DESC'
}, myOptions); }, myOptions);
companyFk = company.companyFk; companyFk = company.companyFk;
} }

View File

@ -52,7 +52,9 @@ module.exports = Self => {
JOIN vn.shelving sh ON sh.id = is2.shelvingFk JOIN vn.shelving sh ON sh.id = is2.shelvingFk
LEFT JOIN vn.parking p ON p.id = sh.parkingFk LEFT JOIN vn.parking p ON p.id = sh.parkingFk
LEFT JOIN vn.sector s ON s.id = p.sectorFk LEFT JOIN vn.sector s ON s.id = p.sectorFk
WHERE sh.code = ? AND (? IS NULL OR is2.itemFk = ?) WHERE sh.code = ?
AND (? IS NULL OR is2.itemFk = ?)
AND is2.visible > 0
), ),
itemShelvings AS ( itemShelvings AS (
SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder, p.code AS parkingFk SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder, p.code AS parkingFk
@ -61,15 +63,16 @@ module.exports = Self => {
JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.sector s ON s.id = p.sectorFk
WHERE is2.visible > 0
), ),
parkingDestiny AS ( parkingDestiny AS (
SELECT ? AS pickingOrder SELECT ? AS pickingOrder
) )
SELECT ish.*, SELECT ish.*,
CASE CASE
WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created
AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "old" AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "old"
WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created
AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "new" AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "new"
END AS itemCreated END AS itemCreated
FROM itemShelvings ish FROM itemShelvings ish
@ -77,8 +80,8 @@ module.exports = Self => {
JOIN currentItemShelving aish ON ish.itemFk = aish.itemFk JOIN currentItemShelving aish ON ish.itemFk = aish.itemFk
WHERE ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? WHERE ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ?
AND ( AND (
(ish.pickingOrder < d.pickingOrder AND aish.created < ish.created) (ish.pickingOrder < d.pickingOrder AND aish.created < ish.created)
OR OR
(ish.pickingOrder > d.pickingOrder AND aish.created > ish.created) (ish.pickingOrder > d.pickingOrder AND aish.created > ish.created)
); );
`, `,

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const smtp = require('vn-print/core/smtp');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('saveSign', { Self.remoteMethodCtx('saveSign', {
@ -31,6 +32,7 @@ module.exports = Self => {
Self.saveSign = async(ctx, tickets, location, signedTime, options) => { Self.saveSign = async(ctx, tickets, location, signedTime, options) => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {userId: ctx.req.accessToken.userId}; const myOptions = {userId: ctx.req.accessToken.userId};
const url = await Self.app.models.Url.getUrl('lilium');
let tx; let tx;
let ticket; let ticket;
let dms; let dms;
@ -146,11 +148,11 @@ module.exports = Self => {
await ticket.updateAttribute('isSigned', true, myOptions); await ticket.updateAttribute('isSigned', true, myOptions);
const [{stateCode}] = await Self.rawSql(` const [{stateCode}] = await Self.rawSql(`
SELECT SELECT
IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)),
'DELIVERED','PARTIAL_DELIVERED') stateCode 'DELIVERED','PARTIAL_DELIVERED') stateCode
FROM vn.expedition e FROM vn.expedition e
JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
WHERE e.ticketFk = ?; WHERE e.ticketFk = ?;
`, [ticketId], myOptions); `, [ticketId], myOptions);
@ -159,23 +161,24 @@ module.exports = Self => {
if (stateCode == 'DELIVERED' && ticket.priority) { if (stateCode == 'DELIVERED' && ticket.priority) {
const orderState = await models.State.findOne({ const orderState = await models.State.findOne({
where: {code: 'DELIVERED'}, where: {code: 'DELIVERED'},
fields: ['id'] fields: ['order']
}, myOptions); }, myOptions);
const ticketIncorrect = await Self.rawSql(` const ticketIncorrect = await Self.rawSql(`
SELECT t.id SELECT tls.ticketFk
FROM ticket t FROM ticketLastState tls
JOIN ticketState ts ON ts.ticketFk = t.id JOIN ticketTracking tt ON tt.id = tls.ticketTrackingFk
JOIN state s ON s.code = ts.code JOIN ticket t ON t.id = tt.ticketFk
WHERE t.routeFk = ? JOIN state s ON s.id = tt.stateFk
AND s.\`order\` < ? WHERE t.routeFk = ?
AND priority <(SELECT t.priority AND s.\`order\` < ?
FROM ticket t AND priority < (SELECT priority
WHERE t.id = ?)` FROM ticket
, [ticket.routeFk, orderState.id, ticket.id], myOptions); WHERE id = ?)
`, [ticket.routeFk, orderState.order, ticket.id], myOptions);
if (ticketIncorrect?.length > 0) if (ticketIncorrect?.length > 0)
await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name); await sendMail(ticket.routeFk, ticket.id, ticket.zone().name);
} }
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) { if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) {
@ -189,26 +192,21 @@ module.exports = Self => {
throw e; throw e;
} }
await models.Ticket.sendCmrEmail(ctx, externalTickets); await models.Ticket.sendCmrEmail(ctx, externalTickets);
async function sendMail(route, ticket, zoneName) {
const $t = ctx.req.__;
const fullUrl = `<a href="${url}route/${route}/summary">${route}</a>`;
await smtp.send({
to: 'repartos@verdnatura.es',
subject: $t('Incorrect delivery order alert on route', {
route,
zone: zoneName
}),
html: $t('Ticket has been delivered out of order', {
ticket,
fullUrl
})
});
}
}; };
async function sendMail(ctx, route, ticket, zoneName) {
const $t = ctx.req.__;
const url = await Self.app.models.Url.getUrl();
const sendTo = 'repartos@verdnatura.es';
const fullUrl = `${url}route/${route}/summary`;
const emailSubject = $t('Incorrect delivery order alert on route', {
route,
zone: zoneName
});
const emailBody = $t('Ticket has been delivered out of order', {
ticket,
fullUrl
});
await Self.app.models.Mail.create({
receiver: sendTo,
subject: emailSubject,
body: emailBody
});
}
}; };

View File

@ -6,7 +6,7 @@ describe('Ticket saveSign()', () => {
getLocale: () => { getLocale: () => {
return 'en'; return 'en';
}, },
__: () => {}, __: t => t,
accessToken: {userId: 9} accessToken: {userId: 9}
} }
}; };

View File

@ -1,9 +1,9 @@
WITH tickets AS( WITH tickets AS(
SELECT id, addressFk, packages, refFk SELECT id, addressFk, packages, refFk, weight
FROM vn.ticket FROM vn.ticket
WHERE refFk = ? WHERE refFk = ?
), volume AS( ), volume AS(
SELECT SUM(volume) volume, MAX(weight)weight SELECT SUM(sv.volume) volume, MAX(t.weight)weight
FROM tickets t FROM tickets t
JOIN vn.saleVolume sv ON sv.ticketFk = t.id JOIN vn.saleVolume sv ON sv.ticketFk = t.id
), intrastat AS( ), intrastat AS(