diff --git a/CHANGELOG.md b/CHANGELOG.md index ca491d9ee..8bb1af8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia ### Changed +- (Envíos -> Extra comunitarios) Se agrupan las entradas del mismo travel. Añadidos campos Referencia y Importe. - (Envíos -> Índice) Cambiado el buscador superior por uno lateral ### Fixed diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index 915120d49..79b20e307 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -30,16 +30,23 @@ module.exports = Self => { const recipient = to.replace('@', ''); if (sender.name != recipient) { - await models.Chat.create({ + const chat = await models.Chat.create({ senderFk: sender.id, recipient: to, dated: Date.vnNew(), checkUserStatus: 0, message: message, - status: 0, + status: 'sending', attempts: 0 }); + try { + await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); + await Self.updateChat(chat, 'sent'); + } catch (error) { + await Self.updateChat(chat, 'error', error); + } + return true; } diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 883a1b693..29232490a 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -24,18 +24,13 @@ module.exports = Self => { } }); - Self.sendCheckingPresence = async(ctx, recipientId, message, options) => { + Self.sendCheckingPresence = async(ctx, recipientId, message) => { if (!recipientId) return false; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - const models = Self.app.models; const userId = ctx.req.accessToken.userId; - const sender = await models.Account.findById(userId); - const recipient = await models.Account.findById(recipientId, null, myOptions); + const sender = await models.Account.findById(userId, {fields: ['id']}); + const recipient = await models.Account.findById(recipientId, null); // Prevent sending messages to yourself if (recipientId == userId) return false; @@ -46,16 +41,23 @@ module.exports = Self => { if (process.env.NODE_ENV == 'test') message = `[Test:Environment to user ${userId}] ` + message; - await models.Chat.create({ + const chat = await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, dated: Date.vnNew(), checkUserStatus: 1, message: message, - status: 0, + status: 'sending', attempts: 0 }); + try { + await Self.sendCheckingUserStatus(chat); + await Self.updateChat(chat, 'sent'); + } catch (error) { + await Self.updateChat(chat, 'error', error); + } + return true; }; }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index 66fbfcdc5..ef1a417ab 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -3,7 +3,6 @@ module.exports = Self => { Self.remoteMethodCtx('sendQueued', { description: 'Send a RocketChat message', accessType: 'WRITE', - accepts: [], returns: { type: 'object', root: true @@ -16,14 +15,17 @@ module.exports = Self => { Self.sendQueued = async() => { const models = Self.app.models; - const maxAttempts = 3; - const sentStatus = 1; - const errorStatus = 2; const chats = await models.Chat.find({ where: { - status: {neq: sentStatus}, - attempts: {lt: maxAttempts} + status: { + nin: [ + 'sent', + 'sending' + ] + + }, + attempts: {lt: 3} } }); @@ -31,16 +33,16 @@ module.exports = Self => { if (chat.checkUserStatus) { try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, sentStatus); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, errorStatus, error); + await Self.updateChat(chat, 'error', error); } } else { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, sentStatus); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, errorStatus, error); + await Self.updateChat(chat, 'error', error); } } } @@ -128,15 +130,17 @@ module.exports = Self => { * @param {object} chat - The chat * @param {string} status - The new status * @param {string} error - The error + * @param {object} options - Query options * @return {Promise} - The request promise - */ - async function updateChat(chat, status, error) { + */ + + Self.updateChat = async(chat, status, error) => { return chat.updateAttributes({ status: status, attempts: ++chat.attempts, error: error }); - } + }; /** * Returns the current user status on Rocketchat diff --git a/back/methods/chat/spec/sendQueued.spec.js b/back/methods/chat/spec/sendQueued.spec.js index ed791756b..67cd47f4a 100644 --- a/back/methods/chat/spec/sendQueued.spec.js +++ b/back/methods/chat/spec/sendQueued.spec.js @@ -10,7 +10,7 @@ describe('Chat sendCheckingPresence()', () => { const chat = { checkUserStatus: 1, - status: 0, + status: 'pending', attempts: 0 }; @@ -27,7 +27,7 @@ describe('Chat sendCheckingPresence()', () => { const chat = { checkUserStatus: 0, - status: 0, + status: 'pending', attempts: 0 }; diff --git a/db/changes/231201/00-chatRefactor.sql b/db/changes/231201/00-chatRefactor.sql new file mode 100644 index 000000000..66d1bf3bf --- /dev/null +++ b/db/changes/231201/00-chatRefactor.sql @@ -0,0 +1,16 @@ +ALTER TABLE `vn`.`chat` ADD statusNew enum('pending','sent','error','sending') DEFAULT 'pending' NOT NULL; + +UPDATE `vn`.`chat` + SET statusNew = 'pending' +WHERE status = 0; + +UPDATE `vn`.`chat` + SET statusNew = 'sent' +WHERE status = 1; + +UPDATE `vn`.`chat` + SET statusNew = 'error' +WHERE status = 2; + +ALTER TABLE `vn`.`chat` CHANGE status status__ tinyint(1) DEFAULT NULL NULL; +ALTER TABLE `vn`.`chat` CHANGE statusNew status enum('pending','sent','error','sending') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'pending' NOT NULL; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f78313cc9..e9c70878f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -501,7 +501,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`) (3, 'Delivery', 'delivery'), (4, 'SalesPerson', 'salesPerson'), (5, 'Administrative', 'administrative'), - (6, 'Weight', 'weight'); + (6, 'Weight', 'weight'), + (7, 'InvoiceOut', 'invoiceOut'); INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) VALUES @@ -738,7 +739,9 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des (9, 23, 5, 'care with the dog'), (10, 23, 4, 'Reclama ticket: 8'), (11, 24, 4, 'Reclama ticket: 7'), - (12, 11, 3, 'Delivery after 10am'); + (12, 11, 3, 'Delivery after 10am'), + (13, 1, 7, 'observation of ticket one'), + (14, 2, 7, 'observation of ticket two'); -- FIX for state hours on local, inter_afterInsert -- UPDATE vncontrol.inter SET odbc_date = DATE_ADD(util.VN_CURDATE(), INTERVAL -10 SECOND); @@ -2631,8 +2634,8 @@ INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackage INSERT INTO `vn`.`chat` (`senderFk`, `recipient`, `dated`, `checkUserStatus`, `message`, `status`, `attempts`) VALUES - (1101, '@PetterParker', util.VN_CURDATE(), 1, 'First test message', 0, 0), - (1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 0); + (1101, '@PetterParker', util.VN_CURDATE(), 1, 'First test message', 0, 'sent'), + (1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 'pending'); INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`) diff --git a/modules/claim/back/methods/claim/logs.js b/modules/claim/back/methods/claim/logs.js index c7e69680b..f47513e9e 100644 --- a/modules/claim/back/methods/claim/logs.js +++ b/modules/claim/back/methods/claim/logs.js @@ -1,7 +1,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; -const {mergeFilters, mergeWhere} = require('vn-loopback/util/filter'); +const { mergeFilters, mergeWhere } = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethodCtx('logs', { @@ -12,27 +12,27 @@ module.exports = Self => { arg: 'id', type: 'Number', description: 'The claim id', - http: {source: 'path'} + http: { source: 'path' } }, { arg: 'filter', type: 'object', - http: {source: 'query'} + http: { source: 'query' } }, { arg: 'search', type: 'string', - http: {source: 'query'} + http: { source: 'query' } }, { arg: 'userFk', type: 'number', - http: {source: 'query'} + http: { source: 'query' } }, { arg: 'created', type: 'date', - http: {source: 'query'} + http: { source: 'query' } }, ], returns: { @@ -45,7 +45,7 @@ module.exports = Self => { } }); - Self.logs = async(ctx, id, filter, options) => { + Self.logs = async (ctx, id, filter, options) => { const conn = Self.dataSource.connector; const args = ctx.args; const myOptions = {}; @@ -56,25 +56,25 @@ module.exports = Self => { let where = buildFilter(args, (param, value) => { switch (param) { - case 'search': - return { - or: [ - {changedModel: {like: `%${value}%`}}, - {oldInstance: {like: `%${value}%`}} - ] - }; - case 'userFk': - return {'cl.userFk': value}; - case 'created': - value.setHours(0, 0, 0, 0); - to = new Date(value); - to.setHours(23, 59, 59, 999); + case 'search': + return { + or: [ + { changedModel: { like: `%${value}%` } }, + { oldInstance: { like: `%${value}%` } } + ] + }; + case 'userFk': + return { 'cl.userFk': value }; + case 'created': + value.setHours(0, 0, 0, 0); + to = new Date(value); + to.setHours(23, 59, 59, 999); - return {creationDate: {between: [value, to]}}; + return { creationDate: { between: [value, to] } }; } }); - where = mergeWhere(where, {['cl.originFk']: id}); - filter = mergeFilters(args.filter, {where}); + where = mergeWhere(where, { ['cl.originFk']: id }); + filter = mergeFilters(args.filter, { where }); const stmts = []; @@ -102,8 +102,8 @@ module.exports = Self => { const logs = []; for (const row of result) { const changes = []; - const oldInstance = JSON.parse(row.oldInstance); - const newInstance = JSON.parse(row.newInstance); + const oldInstance = JSON.parse(row.oldInstance) || {}; + const newInstance = JSON.parse(row.newInstance) || {}; const mergedProperties = [...Object.keys(oldInstance), ...Object.keys(newInstance)]; const properties = new Set(mergedProperties); for (const property of properties) { diff --git a/modules/travel/back/methods/travel/extraCommunityFilter.js b/modules/travel/back/methods/travel/extraCommunityFilter.js index 027261c4b..5ee51de8e 100644 --- a/modules/travel/back/methods/travel/extraCommunityFilter.js +++ b/modules/travel/back/methods/travel/extraCommunityFilter.js @@ -130,6 +130,7 @@ module.exports = Self => { SUM(b.stickers) AS stickers, s.id AS cargoSupplierFk, s.nickname AS cargoSupplierNickname, + s.name AS supplierName, CAST(SUM(b.weight * b.stickers) as DECIMAL(10,0)) as loadedKg, CAST(SUM(vc.aerealVolumetricDensity * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) as DECIMAL(10,0)) as volumeKg FROM travel t @@ -167,6 +168,7 @@ module.exports = Self => { SUM(b.stickers) AS stickers, e.evaNotes, e.notes, + e.invoiceAmount, CAST(SUM(b.weight * b.stickers) AS DECIMAL(10,0)) as loadedkg, CAST(SUM(vc.aerealVolumetricDensity * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) AS DECIMAL(10,0)) as volumeKg FROM tmp.travel tr diff --git a/modules/travel/front/extra-community/index.html b/modules/travel/front/extra-community/index.html index 376c81aaf..c888f97da 100644 --- a/modules/travel/front/extra-community/index.html +++ b/modules/travel/front/extra-community/index.html @@ -3,7 +3,7 @@ url="Travels/extraCommunityFilter" user-params="::$ctrl.defaultFilter" data="travels" - order="shipped ASC, landed ASC, travelFk, loadPriority, agencyModeFk, evaNotes" + order="landed ASC, shipped ASC, travelFk, loadPriority, agencyModeFk, supplierName, evaNotes" limit="20" auto-load="true"> @@ -48,6 +48,9 @@ Agency + + Amount + Reference @@ -107,6 +110,7 @@ {{::travel.cargoSupplierNickname}} + {{::travel.agencyModeName}} @@ -157,22 +161,15 @@ {{::entry.supplierName}} + {{::entry.invoiceAmount | currency: 'EUR': 2}} - {{::entry.ref}} + {{::entry.invoiceNumber}} {{::entry.stickers}} {{::entry.loadedkg}} {{::entry.volumeKg}} - - - {{::entry.notes}} - - - - - {{::entry.evaNotes}} - - + + diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index 2d180878a..7a1ed3319 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -240,13 +240,18 @@ -
+
{{$t('observations')}}
-
{{$t('wireTransfer')}}
-
{{$t('accountNumber', [invoice.iban])}}
+
+
{{$t('wireTransfer')}}
+
{{$t('accountNumber', [invoice.iban])}}
+
+
+ {{ticketObservations}} +
diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index b135e152b..42988113f 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -21,11 +21,15 @@ module.exports = { const map = new Map(); + this.ticketObservations = ''; for (let ticket of tickets) { ticket.sales = []; map.set(ticket.id, ticket); + + if (ticket.description) this.ticketObservations += ticket.description + ' '; } + this.ticketObservations = this.ticketObservations.trim(); for (let sale of sales) { const ticket = map.get(sale.ticketFk); diff --git a/print/templates/reports/invoice/sql/tickets.sql b/print/templates/reports/invoice/sql/tickets.sql index 162f043e2..a8385599c 100644 --- a/print/templates/reports/invoice/sql/tickets.sql +++ b/print/templates/reports/invoice/sql/tickets.sql @@ -1,8 +1,12 @@ SELECT t.id, t.shipped, - t.nickname -FROM invoiceOut io - JOIN ticket t ON t.refFk = io.ref + t.nickname, + tto.description +FROM invoiceOut io + JOIN ticket t ON t.refFk = io.REF + LEFT JOIN observationType ot ON ot.code = 'invoiceOut' + LEFT JOIN ticketObservation tto ON tto.ticketFk = t.id + AND tto.observationTypeFk = ot.id WHERE t.refFk = ? -ORDER BY t.shipped \ No newline at end of file +ORDER BY t.shipped