Merge branch 'dev' into 6822-entryTransfer

This commit is contained in:
Robert Ferrús 2025-01-21 08:48:24 +00:00
commit 7292ac48b2
13 changed files with 153 additions and 37 deletions

View File

@ -1,26 +1,27 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zone_getAddresses`(
vSelf INT, vSelf INT,
vShipped DATE, vLanded DATE,
vDepartmentFk INT vDepartmentFk INT
) )
BEGIN BEGIN
/** /**
* Devuelve un listado de todos los clientes activos * Devuelve un listado de todos los clientes activos
* con consignatarios a los que se les puede * con consignatarios a los que se les puede
* vender producto para esa zona. * entregar producto para esa zona.
* *
* @param vSelf Id de zona * @param vSelf Id de zona
* @param vShipped Fecha de envio * @param vLanded Fecha de entrega
* @param vDepartmentFk Id de departamento * @param vDepartmentFk Id de departamento | NULL para mostrar todos
* @return Un select * @return Un select
*/ */
CALL zone_getPostalCode(vSelf); CALL zone_getPostalCode(vSelf);
WITH clientWithTicket AS ( WITH clientWithTicket AS (
SELECT clientFk SELECT DISTINCT clientFk
FROM vn.ticket FROM vn.ticket
WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped) WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded)
AND NOT isDeleted
) )
SELECT c.id, SELECT c.id,
c.name, c.name,
@ -30,7 +31,7 @@ BEGIN
u.name username, u.name username,
aai.invoiced, aai.invoiced,
cnb.lastShipped, cnb.lastShipped,
cwt.clientFk IF(cwt.clientFk, TRUE, FALSE) hasTicket
FROM vn.client c FROM vn.client c
JOIN vn.worker w ON w.id = c.salesPersonFk JOIN vn.worker w ON w.id = c.salesPersonFk
JOIN vn.workerDepartment wd ON wd.workerFk = w.id JOIN vn.workerDepartment wd ON wd.workerFk = w.id
@ -50,7 +51,7 @@ BEGIN
AND c.isActive AND c.isActive
AND ct.code = 'normal' AND ct.code = 'normal'
AND bt.code <> 'worker' AND bt.code <> 'worker'
AND (d.id = vDepartmentFk OR NOT vDepartmentFk) AND (d.id = vDepartmentFk OR vDepartmentFk IS NULL)
GROUP BY c.id; GROUP BY c.id;
DROP TEMPORARY TABLE tmp.zoneNodes; DROP TEMPORARY TABLE tmp.zoneNodes;

View File

@ -0,0 +1 @@
CREATE INDEX ticket_landed_IDX USING BTREE ON vn.ticket (landed);

View File

@ -247,9 +247,11 @@
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}", "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
"The raid information is not correct": "The raid information is not correct", "The raid information is not correct": "The raid information is not correct",
"Payment method is required": "Payment method is required", "Payment method is required": "Payment method is required",
"Sales already moved": "Sales already moved",
"Holidays to past days not available": "Holidays to past days not available",
"Price cannot be blank": "Price cannot be blank", "Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "There are tickets to be invoiced", "There are tickets to be invoiced": "There are tickets to be invoiced",
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent",
"Sales already moved": "Sales already moved",
"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 }}",
"Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order."
} }

View File

@ -390,13 +390,11 @@
"The web user's email already exists": "El correo del usuario web ya existe", "The web user's email already exists": "El correo del usuario web ya existe",
"Sales already moved": "Ya han sido transferidas", "Sales already moved": "Ya han sido transferidas",
"The raid information is not correct": "La información de la redada no es correcta", "The raid information is not correct": "La información de la redada no es correcta",
"No trips found because input coordinates are not connected": "No se encontraron rutas porque las coordenadas de entrada no están conectadas",
"This request is not supported": "Esta solicitud no es compatible",
"Invalid options or too many coordinates": "Opciones invalidas o demasiadas coordenadas",
"No address has coordinates": "Ninguna dirección tiene coordenadas",
"An item type with the same code already exists": "Un tipo con el mismo código ya existe", "An item type with the same code already exists": "Un tipo con el mismo código ya existe",
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles",
"All tickets have a route order": "Todos los tickets tienen orden de ruta", "All tickets have a route order": "Todos los tickets tienen orden de ruta",
"Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "La zona tiene tickets por facturar",
"There are tickets to be invoiced": "La zona tiene tickets por facturar" "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 sigo entregado en su orden.",
"Price cannot be blank": "El precio no puede estar en blanco"
} }

View File

@ -366,5 +366,7 @@
"The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne",
"You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé", "You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé",
"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 }}",
"Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre."
} }

View File

@ -365,5 +365,7 @@
"Cannot send mail": "Não é possível enviar o email", "Cannot send mail": "Não é possível enviar o email",
"The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha",
"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 }}",
"Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem."
} }

View File

@ -94,7 +94,7 @@ module.exports = Self => {
AND r1.started = r2.maxStarted AND r1.started = r2.maxStarted
) r ON r.clientFk = c.id ) r ON r.clientFk = c.id
LEFT JOIN workerDepartment wd ON wd.workerFk = u.id LEFT JOIN workerDepartment wd ON wd.workerFk = u.id
JOIN department dp ON dp.id = wd.departmentFk LEFT JOIN department dp ON dp.id = wd.departmentFk
WHERE WHERE
d.created = ? d.created = ?
AND d.amount > 0 AND d.amount > 0

View File

@ -19,6 +19,9 @@
}, },
"created": { "created": {
"type": "date" "type": "date"
},
"workerFk": {
"type": "number"
} }
}, },
"relations": { "relations": {

View File

@ -74,7 +74,8 @@ module.exports = Self => {
AND t.companyFk = ? AND t.companyFk = ?
AND NOT t.isDeleted AND NOT t.isDeleted
GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id) GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id)
HAVING SUM(t.totalWithVat) > 0;`; HAVING SUM(t.totalWithVat) > 0
ORDER BY c.id`;
const addresses = await Self.rawSql(query, [ const addresses = await Self.rawSql(query, [
minShipped, minShipped,

View File

@ -28,6 +28,7 @@ module.exports = Self => {
delete args.ctx; delete args.ctx;
if (!args.name) throw new UserError('The social name cannot be empty'); if (!args.name) throw new UserError('The social name cannot be empty');
if (args.name !== args.name.toUpperCase()) throw new UserError('Social name should be uppercase');
const data = {...args, ...{nickname: args.name}}; const data = {...args, ...{nickname: args.name}};
const supplier = await models.Supplier.create(data, myOptions); const supplier = await models.Supplier.create(data, myOptions);

View File

@ -28,7 +28,6 @@ module.exports = Self => {
verb: 'POST' verb: 'POST'
} }
}); });
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};
@ -111,6 +110,12 @@ module.exports = Self => {
scope: { scope: {
fields: ['id'] fields: ['id']
} }
},
{
relation: 'zone',
scope: {
fields: ['id', 'zoneFk,', 'name']
}
}] }]
}, myOptions); }, myOptions);
@ -151,6 +156,28 @@ module.exports = Self => {
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions);
if (stateCode == 'DELIVERED' && ticket.priority) {
const orderState = await models.State.findOne({
where: {code: 'DELIVERED'},
fields: ['id']
}, myOptions);
const ticketIncorrect = await Self.rawSql(`
SELECT t.id
FROM ticket t
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN state s ON s.code = ts.code
WHERE t.routeFk = ?
AND s.\`order\` < ?
AND priority <(SELECT t.priority
FROM ticket t
WHERE t.id = ?)`
, [ticket.routeFk, orderState.id, ticket.id], myOptions);
if (ticketIncorrect?.length > 0)
await sendMail(ctx, 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) {
await models.Ticket.saveCmr(ctx, [ticketId], myOptions); await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
externalTickets.push(ticketId); externalTickets.push(ticketId);
@ -163,4 +190,25 @@ module.exports = Self => {
} }
await models.Ticket.sendCmrEmail(ctx, externalTickets); await models.Ticket.sendCmrEmail(ctx, externalTickets);
}; };
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

@ -1,12 +1,20 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('Ticket saveSign()', () => { describe('Ticket saveSign()', () => {
let ctx = {req: { let ctx = {req: {
getLocale: () => { getLocale: () => {
return 'en'; return 'en';
}, },
__: () => {},
accessToken: {userId: 9} accessToken: {userId: 9}
}}; }
};
beforeEach(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx
});
});
it(`should throw error if the ticket's alert level is lower than 2`, async() => { it(`should throw error if the ticket's alert level is lower than 2`, async() => {
const tx = await models.TicketDms.beginTransaction({}); const tx = await models.TicketDms.beginTransaction({});
@ -51,4 +59,46 @@ describe('Ticket saveSign()', () => {
expect(ticketTrackingAfter.name).toBe('Entregado en parte'); expect(ticketTrackingAfter.name).toBe('Entregado en parte');
}); });
it('should send an email to notify that the delivery order is not correct', async() => {
const tx = await models.Ticket.beginTransaction({});
const ticketFk = 8;
const priority = 5;
const stateFk = 10;
const stateTicketFk = 2;
const expeditionFk = 11;
const expeditionStateFK = 2;
let mailCountBefore;
let mailCountAfter;
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]);
const options = {transaction: tx};
const tickets = [ticketFk];
const expedition = await models.Expedition.findById(expeditionFk, null, options);
expedition.updateAttribute('stateTypeFk', expeditionStateFK, options);
const ticket = await models.Ticket.findById(ticketFk, null, options);
ticket.updateAttribute('priority', priority, options);
const filter = {where: {
ticketFk: ticketFk,
stateFk: stateTicketFk}
};
try {
const ticketTracking = await models.TicketTracking.findOne(filter, options);
ticketTracking.updateAttribute('stateFk', stateFk, options);
mailCountBefore = await models.Mail.count(options);
await models.Ticket.saveSign(ctx, tickets, null, null, options);
mailCountAfter = await models.Mail.count(options);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(mailCountAfter).toBeGreaterThan(mailCountBefore);
});
}); });

View File

@ -1,4 +1,3 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const buildFilter = require('vn-loopback/util/filter').buildFilter; const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters; const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
@ -91,6 +90,11 @@ module.exports = Self => {
arg: 'landed', arg: 'landed',
type: 'date', type: 'date',
description: 'The landed date' description: 'The landed date'
},
{
arg: 'awbFk',
type: 'number',
description: 'The awbFk id'
} }
], ],
returns: { returns: {
@ -168,14 +172,17 @@ module.exports = Self => {
t.totalEntries, t.totalEntries,
t.isRaid, t.isRaid,
t.daysInForward, t.daysInForward,
t.awbFk,
am.name agencyModeName, am.name agencyModeName,
a.code awbCode,
win.name warehouseInName, win.name warehouseInName,
wout.name warehouseOutName, wout.name warehouseOutName,
cnt.code continent cnt.code continent
FROM vn.travel t FROM travel t
JOIN vn.agencyMode am ON am.id = t.agencyModeFk JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN vn.warehouse win ON win.id = t.warehouseInFk JOIN warehouse win ON win.id = t.warehouseInFk
JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk JOIN warehouse wout ON wout.id = t.warehouseOutFk
LEFT JOIN awb a ON a.id = t.awbFk
JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN warehouse wo ON wo.id = t.warehouseOutFk
JOIN country c ON c.id = wo.countryFk JOIN country c ON c.id = wo.countryFk
LEFT JOIN continent cnt ON cnt.id = c.continentFk) AS t` LEFT JOIN continent cnt ON cnt.id = c.continentFk) AS t`