From fb3f3c64c9c19baab8fee929ec8414485f82ee1b Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 19 Dec 2022 09:59:03 +0100 Subject: [PATCH 01/71] refs #4858 --- back/methods/chat/sendCheckingPresence.js | 4 +++- back/methods/chat/sendQueued.js | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 3bc022429..5520abb7c 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -43,7 +43,7 @@ module.exports = Self => { if (!recipient) throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); - await models.Chat.create({ + const chat = await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, dated: new Date(), @@ -52,6 +52,8 @@ module.exports = Self => { status: 0, attempts: 0 }); + console.log(chat); + await models.Chat.sendQueued(chat.id); return true; }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index 66fbfcdc5..cbe963235 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -3,7 +3,11 @@ module.exports = Self => { Self.remoteMethodCtx('sendQueued', { description: 'Send a RocketChat message', accessType: 'WRITE', - accepts: [], + accepts: [{ + arg: 'id', + type: 'number', + description: 'The message id' + }], returns: { type: 'object', root: true @@ -14,17 +18,20 @@ module.exports = Self => { } }); - Self.sendQueued = async() => { + Self.sendQueued = async id => { const models = Self.app.models; const maxAttempts = 3; const sentStatus = 1; const errorStatus = 2; + let filter = { + status: {neq: sentStatus}, + attempts: {lt: maxAttempts} + }; + // NOTA: Igual se deberia transaccionar por si coincidiera que en el momento que se esta enviando directamente + // tambien se esta ejecutando la cola que no lo envie dos veces. const chats = await models.Chat.find({ - where: { - status: {neq: sentStatus}, - attempts: {lt: maxAttempts} - } + where: id ? {id} : filter }); for (let chat of chats) { From d85717ca0466fea7d7ab409fdbd9c630efa32ae8 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 Jan 2023 11:23:06 +0100 Subject: [PATCH 02/71] feat: chat in real time --- back/methods/chat/send.js | 2 +- back/methods/chat/sendCheckingPresence.js | 39 ++++++++++++++++++++--- back/methods/chat/sendQueued.js | 31 +++++++++--------- db/changes/230201/00-chatRefactor.sql | 16 ++++++++++ 4 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 db/changes/230201/00-chatRefactor.sql diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index c5c8feead..7fda97c82 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -36,7 +36,7 @@ module.exports = Self => { dated: new Date(), checkUserStatus: 0, message: message, - status: 0, + status: 'pending', attempts: 0 }); diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 5520abb7c..604c471d7 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -27,11 +27,17 @@ module.exports = Self => { Self.sendCheckingPresence = async(ctx, recipientId, message, options) => { if (!recipientId) return false; + let tx; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + const models = Self.app.models; const userId = ctx.req.accessToken.userId; const sender = await models.Account.findById(userId); @@ -49,12 +55,37 @@ module.exports = Self => { dated: new Date(), checkUserStatus: 1, message: message, - status: 0, + status: 'sending', attempts: 0 - }); - console.log(chat); - await models.Chat.sendQueued(chat.id); + }, myOptions); + + try { + await Self.sendCheckingUserStatus(chat); + await updateChat(chat, 'sent', myOptions); + } catch (error) { + await updateChat(chat, 'error', error, myOptions); + } + + if (tx) await tx.commit(); return true; }; + + /** + * Update status and attempts of a chat + * + * @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, options) { + return chat.updateAttributes({ + status: status, + attempts: ++chat.attempts, + error: error + }, options); + } }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index cbe963235..dcd530873 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -3,11 +3,6 @@ module.exports = Self => { Self.remoteMethodCtx('sendQueued', { description: 'Send a RocketChat message', accessType: 'WRITE', - accepts: [{ - arg: 'id', - type: 'number', - description: 'The message id' - }], returns: { type: 'object', root: true @@ -18,20 +13,25 @@ module.exports = Self => { } }); - Self.sendQueued = async id => { + Self.sendQueued = async() => { const models = Self.app.models; const maxAttempts = 3; - const sentStatus = 1; - const errorStatus = 2; - let filter = { - status: {neq: sentStatus}, - attempts: {lt: maxAttempts} - }; + const sentStatus = 'sent'; + const sendingStatus = 'sending'; + const errorStatus = 'error'; - // NOTA: Igual se deberia transaccionar por si coincidiera que en el momento que se esta enviando directamente - // tambien se esta ejecutando la cola que no lo envie dos veces. const chats = await models.Chat.find({ - where: id ? {id} : filter + where: { + status: { + neq: { + and: [ + sentStatus, + sendingStatus + ] + } + }, + attempts: {lt: maxAttempts} + } }); for (let chat of chats) { @@ -137,6 +137,7 @@ module.exports = Self => { * @param {string} error - The error * @return {Promise} - The request promise */ + async function updateChat(chat, status, error) { return chat.updateAttributes({ status: status, diff --git a/db/changes/230201/00-chatRefactor.sql b/db/changes/230201/00-chatRefactor.sql new file mode 100644 index 000000000..66d1bf3bf --- /dev/null +++ b/db/changes/230201/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; From 44055775cb278ed4720d3008b7b89cef5ea11e92 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 6 Feb 2023 10:11:41 +0100 Subject: [PATCH 03/71] fix: not use variables and direct send in send --- back/methods/chat/send.js | 11 +++++++++-- back/methods/chat/sendQueued.js | 18 +++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index 21e25c1f0..5e3821677 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: 'pending', + status: 'sending', attempts: 0 }); + try { + await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); + await updateChat(chat, 'sent'); + } catch (error) { + await updateChat(chat, 'error', error); + } + return true; } diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index dcd530873..ad8363627 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -15,22 +15,18 @@ module.exports = Self => { Self.sendQueued = async() => { const models = Self.app.models; - const maxAttempts = 3; - const sentStatus = 'sent'; - const sendingStatus = 'sending'; - const errorStatus = 'error'; const chats = await models.Chat.find({ where: { status: { neq: { and: [ - sentStatus, - sendingStatus + 'sent', + 'sending' ] } }, - attempts: {lt: maxAttempts} + attempts: {lt: 3} } }); @@ -38,16 +34,16 @@ module.exports = Self => { if (chat.checkUserStatus) { try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, sentStatus); + await updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, errorStatus, error); + await updateChat(chat, 'error', error); } } else { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, sentStatus); + await updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, errorStatus, error); + await updateChat(chat, 'error', error); } } } From f06fc92ae80dd38cb9e4afcbd34ef75e3ba791fb Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 8 Feb 2023 15:15:26 +0100 Subject: [PATCH 04/71] refactor(chat): not use transactions --- back/methods/chat/send.js | 4 +-- back/methods/chat/sendCheckingPresence.js | 43 ++++------------------- back/methods/chat/sendQueued.js | 7 ++-- 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index 5e3821677..79b20e307 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -42,9 +42,9 @@ module.exports = Self => { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, 'sent'); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error); + await Self.updateChat(chat, 'error', error); } return true; diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index cabd3d85e..3eaf6b86b 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -24,24 +24,13 @@ module.exports = Self => { } }); - Self.sendCheckingPresence = async(ctx, recipientId, message, options) => { + Self.sendCheckingPresence = async(ctx, recipientId, message) => { if (!recipientId) return false; - let tx; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - 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; @@ -57,35 +46,15 @@ module.exports = Self => { message: message, status: 'sending', attempts: 0 - }, myOptions); + }); try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, 'sent', myOptions); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error, myOptions); + await Self.updateChat(chat, 'error', error); } - if (tx) await tx.commit(); - return true; }; - - /** - * Update status and attempts of a chat - * - * @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, options) { - return chat.updateAttributes({ - status: status, - attempts: ++chat.attempts, - error: error - }, options); - } }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index ad8363627..8a0bdee34 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -131,16 +131,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 From 2a4d41cbca3e4ecfbb80389e00610b8fc8bcc926 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 24 Feb 2023 14:41:02 +0100 Subject: [PATCH 05/71] refs #4632 saveSign refactored, working on tests, check if dmsRecover is needed --- back/methods/dms/saveSign.js | 215 ------------------ back/model-config.json | 3 + back/models/delivery.json | 24 +- back/models/dms-recover.json | 37 +++ back/models/dms.js | 1 - db/changes/230801/00-delivery.sql | 72 ++++++ .../back/methods/ticket-dms/saveSign.js | 157 +++++++++++++ .../methods/ticket-dms/specs/saveSign.spec.js | 57 +++++ modules/ticket/back/models/ticket-dms.js | 1 + modules/ticket/back/models/ticket.json | 7 +- 10 files changed, 350 insertions(+), 224 deletions(-) delete mode 100644 back/methods/dms/saveSign.js create mode 100644 back/models/dms-recover.json create mode 100644 db/changes/230801/00-delivery.sql create mode 100644 modules/ticket/back/methods/ticket-dms/saveSign.js create mode 100644 modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js diff --git a/back/methods/dms/saveSign.js b/back/methods/dms/saveSign.js deleted file mode 100644 index ed462a301..000000000 --- a/back/methods/dms/saveSign.js +++ /dev/null @@ -1,215 +0,0 @@ -const md5 = require('md5'); -const fs = require('fs-extra'); - -module.exports = Self => { - Self.remoteMethodCtx('saveSign', { - description: 'Save sign', - accessType: 'WRITE', - accepts: - [ - { - arg: 'signContent', - type: 'string', - required: true, - description: 'The sign content' - }, { - arg: 'tickets', - type: ['number'], - required: true, - description: 'The tickets' - }, { - arg: 'signedTime', - type: 'date', - description: 'The signed time' - }, { - arg: 'addressFk', - type: 'number', - required: true, - description: 'The address fk' - } - ], - returns: { - type: 'Object', - root: true - }, - http: { - path: `/saveSign`, - verb: 'POST' - } - }); - - async function createGestDoc(ticketId, userFk) { - const models = Self.app.models; - if (!await gestDocExists(ticketId)) { - const result = await models.Ticket.findOne({ - where: { - id: ticketId - }, - include: [ - { - relation: 'warehouse', - scope: { - fields: ['id'] - } - }, { - relation: 'client', - scope: { - fields: ['name'] - } - }, { - relation: 'route', - scope: { - fields: ['id'] - } - } - ] - }); - - const warehouseFk = result.warehouseFk; - const companyFk = result.companyFk; - const client = result.client.name; - const route = result.route.id; - - const resultDmsType = await models.DmsType.findOne({ - where: { - code: 'Ticket' - } - }); - - const resultDms = await models.Dms.create({ - dmsTypeFk: resultDmsType.id, - reference: ticketId, - description: `Ticket ${ticketId} Cliente ${client} Ruta ${route}`, - companyFk: companyFk, - warehouseFk: warehouseFk, - workerFk: userFk - }); - - return resultDms.insertId; - } - } - - async function gestDocExists(ticket) { - const models = Self.app.models; - const result = await models.TicketDms.findOne({ - where: { - ticketFk: ticket - }, - fields: ['dmsFk'] - }); - - if (result == null) - return false; - - const isSigned = await models.Ticket.findOne({ - where: { - id: ticket - }, - fields: ['isSigned'] - }); - - if (isSigned) - return true; - else - await models.Dms.destroyById(ticket); - } - - async function dmsRecover(ticket, signContent) { - const models = Self.app.models; - await models.DmsRecover.create({ - ticketFk: ticket, - sign: signContent - }); - } - - async function ticketGestdoc(ticket, dmsFk) { - const models = Self.app.models; - models.TicketDms.replaceOrCreate({ - ticketFk: ticket, - dmsFk: dmsFk - }); - - const queryVnTicketSetState = `CALL vn.ticket_setState(?, ?)`; - - await Self.rawSql(queryVnTicketSetState, [ticket, 'DELIVERED']); - } - - async function updateGestdoc(file, ticket) { - const models = Self.app.models; - models.Dms.updateOne({ - where: { - id: ticket - }, - file: file, - contentType: 'image/png' - }); - } - - Self.saveSign = async(ctx, signContent, tickets, signedTime) => { - const models = Self.app.models; - let tx = await Self.beginTransaction({}); - try { - const userId = ctx.req.accessToken.userId; - - const dmsDir = `storage/dms`; - - let image = null; - - for (let i = 0; i < tickets.length; i++) { - const alertLevel = await models.TicketState.findOne({ - where: { - ticketFk: tickets[i] - }, - fields: ['alertLevel'] - }); - - signedTime ? signedTime != undefined : signedTime = Date.vnNew(); - - if (alertLevel >= 2) { - let dir; - let id = null; - let fileName = null; - - if (!await gestDocExists(tickets[i])) { - id = await createGestDoc(tickets[i], userId); - - const hashDir = md5(id).substring(0, 3); - dir = `${dmsDir}/${hashDir}`; - - if (!fs.existsSync(dir)) - fs.mkdirSync(dir); - - fileName = `${id}.png`; - image = `${dir}/${fileName}`; - } else - - if (image != null) { - if (!fs.existsSync(dir)) - dmsRecover(tickets[i], signContent); - else { - fs.writeFile(image, signContent, 'base64', async function(err) { - if (err) { - await tx.rollback(); - return err.message; - } - }); - } - } else - dmsRecover(tickets[i], signContent); - - if (id != null && fileName.length > 0) { - ticketGestdoc(tickets[i], id); - updateGestdoc(id, fileName); - } - } - } - - if (tx) await tx.commit(); - - return 'OK'; - } catch (err) { - await tx.rollback(); - throw err.message; - } - }; -}; diff --git a/back/model-config.json b/back/model-config.json index 29676e979..6724db151 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -44,6 +44,9 @@ "DmsType": { "dataSource": "vn" }, + "DmsRecover": { + "dataSource": "vn" + }, "Docuware": { "dataSource": "vn" }, diff --git a/back/models/delivery.json b/back/models/delivery.json index 65a0eef1b..c66c31b45 100644 --- a/back/models/delivery.json +++ b/back/models/delivery.json @@ -9,17 +9,29 @@ "properties": { "id": { "id": true, - "type": "number", - "forceId": false + "type": "number" }, - "date": { + "created": { "type": "date" }, - "m3":{ + "longitude":{ "type": "number" }, - "warehouseFk":{ + "latitude":{ + "type": "number" + }, + "dated":{ + "type": "date" + }, + "ticketFk":{ "type": "number" } - } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + } + } } diff --git a/back/models/dms-recover.json b/back/models/dms-recover.json new file mode 100644 index 000000000..3449347a7 --- /dev/null +++ b/back/models/dms-recover.json @@ -0,0 +1,37 @@ + +{ + "name": "DmsRecover", + "description": "Documental Managment System Recover", + "base": "VnModel", + "log": { + "showField": "ticketFk" + }, + "options": { + "mysql": { + "table": "dmsRecover" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "ticketFk": { + "type": "number" + }, + "sign": { + "type": "string" + }, + "created": { + "type": "date" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + } + } +} diff --git a/back/models/dms.js b/back/models/dms.js index fc586201f..24c072f56 100644 --- a/back/models/dms.js +++ b/back/models/dms.js @@ -6,7 +6,6 @@ module.exports = Self => { require('../methods/dms/removeFile')(Self); require('../methods/dms/updateFile')(Self); require('../methods/dms/deleteTrashFiles')(Self); - require('../methods/dms/saveSign')(Self); Self.checkRole = async function(ctx, id) { const models = Self.app.models; diff --git a/db/changes/230801/00-delivery.sql b/db/changes/230801/00-delivery.sql new file mode 100644 index 000000000..38c0a7971 --- /dev/null +++ b/db/changes/230801/00-delivery.sql @@ -0,0 +1,72 @@ +ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; +ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; +ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; +ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); + +DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) + VALUES + ('TicketDms','saveSign','WRITE','ALLOW','employee'); + +DROP PROCEDURE IF EXISTS vn.route_getTickets; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * + * @select Información de los tickets + */ + + SELECT + t.id Id, + t.clientFk Client, + a.id Address, + t.packages Packages, + a.street AddressName, + a.postalCode PostalCode, + a.city City, + sub2.itemPackingTypeFk PackingType, + c.phone ClientPhone, + c.mobile ClientMobile, + a.phone AddressPhone, + a.mobile AddressMobile, + d.longitude Longitude, + d.latitude Latitude, + wm.mediaValue SalePersonPhone, + tob.Note Note, + t.isSigned Signed + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN delivery d ON t.id = d.ticketFk + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN + (SELECT tob.description Note, t.id + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.id = t.id + LEFT JOIN + (SELECT sub.ticketFk, + CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk + FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id,i.itemPackingTypeFk)sub + GROUP BY sub.ticketFk + ) sub2 ON sub2.ticketFk = t.id + WHERE t.routeFk = vRouteFk + GROUP BY t.id + ORDER BY t.priority; +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/ticket-dms/saveSign.js b/modules/ticket/back/methods/ticket-dms/saveSign.js new file mode 100644 index 000000000..725abfe67 --- /dev/null +++ b/modules/ticket/back/methods/ticket-dms/saveSign.js @@ -0,0 +1,157 @@ +module.exports = Self => { + Self.remoteMethodCtx('saveSign', { + description: 'Save sign', + accessType: 'WRITE', + accepts: + [ + { + arg: 'tickets', + type: ['number'], + required: true, + description: 'The tickets' + }, + { + arg: 'location', + type: 'object', + description: 'The employee location the moment the sign is saved' + }, + { + arg: 'signedTime', + type: 'date', + description: 'The signed time' + } + ], + returns: { + type: 'string', + root: true + }, + http: { + path: `/saveSign`, + verb: 'POST' + } + }); + + Self.saveSign = async(ctx, options) => { + const args = Object.assign({}, ctx.args); + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + async function setLocation(ticketId) { + if (args.signedTime) { + await models.Delivery.create({ + ticketFk: ticketId, + longitude: args.location.Longitude, + latitude: args.location.Latitude, + dated: args.signedTime + }, myOptions); + } + } + + async function gestDocExists(ticketId) { + const ticketDms = await models.TicketDms.findOne({ + where: { + ticketFk: ticketId + }, + fields: ['dmsFk'] + }, myOptions); + + if (!ticketDms) return false; + + const ticket = await models.Ticket.findById(ticketId, {fields: ['isSigned']}, myOptions); + if (ticket.isSigned == true) return true; + else + await models.Dms.destroyAll({where: {reference: ticketId}}, myOptions); + + return false; + } + + async function createGestDoc(id) { + const ticket = await models.Ticket.findById(id, + {include: [ + { + relation: 'warehouse', + scope: { + fields: ['id'] + } + }, { + relation: 'client', + scope: { + fields: ['name'] + } + }, { + relation: 'route', + scope: { + fields: ['id'] + } + } + ] + }, myOptions); + const dmsType = await models.DmsType.findOne({where: {code: 'Ticket'}, fields: ['id']}, myOptions); + const ctxUploadFile = Object.assign({}, ctx); + ctxUploadFile.args = { + warehouseId: ticket.warehouseFk, + companyId: ticket.companyFk, + dmsTypeId: dmsType.id, + reference: id, + description: `Ticket ${id} Cliente ${ticket.client().name} Ruta ${ticket.route().id}`, + hasFile: true + }; + await models.Ticket.uploadFile(ctxUploadFile, id, myOptions); + } + + // async function dmsRecover(ticketFk, sign) { + // await models.DmsRecover.create({ticketFk, sign}, myOptions); + // } + + try { + for (let i = 0; i < args.tickets.length; i++) { + const ticketState = await models.TicketState.findOne( + {where: {ticketFk: args.tickets[i]}, + fields: ['alertLevel'] + }, myOptions); + + if (ticketState.alertLevel >= 2 && !await gestDocExists(args.tickets[i])) { + if (!args.signedTime) args.signedTime = Date.vnNew(); + if (args.location) setLocation(args.tickets[i]); + await createGestDoc(args.tickets[i]); + + // if (image) { + // if (!fs.existsSync(dir)) + // dmsRecover(args.tickets[i], args.signContent); + // else { + // fs.writeFile(image, args.signContent, 'base64', async function(err) { + // if (err) { + // await tx.rollback(); + // throw err.message; + // } + // }); + // } + // } else + // dmsRecover(args.tickets[i], args.signContent); + + // if (id && fileName) { + // await models.TicketDms.replaceOrCreate({ticketFk: args.tickets[i], dmsFk: id}, myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions); + // await models.Dms.updateAll({id}, {file: fileName, contentType: 'image/png'}, myOptions); + // } + } + } + + if (tx) await tx.commit(); + + return 'Sign uploaded correctly'; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js new file mode 100644 index 000000000..b640fefb8 --- /dev/null +++ b/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js @@ -0,0 +1,57 @@ +const models = require('vn-loopback/server/server').models; + +fdescribe('TicketDms saveSign()', () => { + const FormData = require('form-data'); + const data = new FormData(); + let ctx = {req: { + accessToken: {userId: 9}, + headers: { + ...data.getHeaders() + }, + on: (param, cb) => {} + }}; + + it(`should not save sign if the ticket's alert level is lower than 2`, async() => { + const tx = await models.TicketDms.beginTransaction({}); + const ticketWithOkState = 12; + + try { + const options = {transaction: tx}; + ctx.args = {tickets: [ticketWithOkState]}; + + await models.TicketDms.saveSign(ctx, options); + const ticket = await models.Ticket.findById(ticketWithOkState, {fields: ['isSigned']}, options); + const ticketDms = await models.TicketDms.findOne({where: {ticketFk: ticketWithOkState}}, options); + + expect(ticket.isSigned).toEqual(false); + expect(ticketDms).toEqual(null); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should save sign if the ticket's alert level is greater than 2`, async() => { + const tx = await models.TicketDms.beginTransaction({}); + const ticketWithPackedState = 7; + + try { + const options = {transaction: tx}; + ctx.args = {tickets: [ticketWithPackedState]}; + + await models.TicketDms.saveSign(ctx, options); + const ticket = await models.Ticket.findById(ticketWithPackedState, {fields: ['isSigned']}, options); + const ticketDms = await models.TicketDms.findOne({where: {ticketFk: ticketWithPackedState}}, options); + + expect(ticket.isSigned).toEqual(true); + expect(ticketDms).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/models/ticket-dms.js b/modules/ticket/back/models/ticket-dms.js index 9bceaae6e..13d960270 100644 --- a/modules/ticket/back/models/ticket-dms.js +++ b/modules/ticket/back/models/ticket-dms.js @@ -2,6 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { require('../methods/ticket-dms/removeFile')(Self); + require('../methods/ticket-dms/saveSign')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') diff --git a/modules/ticket/back/models/ticket.json b/modules/ticket/back/models/ticket.json index 09b01d213..1cf2642a5 100644 --- a/modules/ticket/back/models/ticket.json +++ b/modules/ticket/back/models/ticket.json @@ -36,7 +36,7 @@ "type": "number" }, "updated": { - "type": "date", + "type": "date", "mysql": { "columnName": "created" } @@ -44,6 +44,9 @@ "isDeleted": { "type": "boolean" }, + "isSigned": { + "type": "boolean" + }, "priority": { "type": "number" }, @@ -136,4 +139,4 @@ "foreignKey": "zoneFk" } } -} \ No newline at end of file +} From be1993cf8b04f89bd0e2fc185054f13d07a469c0 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 2 Mar 2023 11:33:55 +0100 Subject: [PATCH 06/71] refs #5206 version with top-searcher and two fields for reference and id --- front/core/styles/variables.scss | 1 + front/salix/components/layout/style.scss | 6 +- .../front/extra-community/locale/es.yml | 4 +- modules/travel/front/index/index.html | 27 +- modules/travel/front/locale/es.yml | 10 +- modules/travel/front/main/index.html | 3 +- modules/travel/front/search-panel/index.html | 299 +++++++++++------- modules/travel/front/search-panel/index.js | 42 ++- modules/travel/front/search-panel/style.scss | 42 +++ modules/travel/front/summary/locale/es.yml | 6 +- 10 files changed, 279 insertions(+), 161 deletions(-) create mode 100644 modules/travel/front/search-panel/style.scss diff --git a/front/core/styles/variables.scss b/front/core/styles/variables.scss index bcc9fab66..c280838ca 100644 --- a/front/core/styles/variables.scss +++ b/front/core/styles/variables.scss @@ -2,6 +2,7 @@ $font-size: 11pt; $menu-width: 256px; +$right-menu-width: 318px; $topbar-height: 56px; $mobile-width: 800px; $float-spacing: 20px; diff --git a/front/salix/components/layout/style.scss b/front/salix/components/layout/style.scss index 612366228..6697bb1b0 100644 --- a/front/salix/components/layout/style.scss +++ b/front/salix/components/layout/style.scss @@ -88,13 +88,13 @@ vn-layout { } &.right-menu { & > vn-topbar > .end { - width: 80px + $menu-width; + width: 80px + $right-menu-width; } & > .main-view { - padding-right: $menu-width; + padding-right: $right-menu-width; } [fixed-bottom-right] { - right: $menu-width; + right: $right-menu-width; } } & > .main-view { diff --git a/modules/travel/front/extra-community/locale/es.yml b/modules/travel/front/extra-community/locale/es.yml index dc231226f..ed6179c91 100644 --- a/modules/travel/front/extra-community/locale/es.yml +++ b/modules/travel/front/extra-community/locale/es.yml @@ -6,6 +6,6 @@ Phy. KG: KG físico Vol. KG: KG Vol. Search by travel id or reference: Buscar por id de travel o referencia Search by extra community travel: Buscar por envío extra comunitario -Continent Out: Continente salida +Continent Out: Cont. salida W. Shipped: F. envío -W. Landed: F. llegada \ No newline at end of file +W. Landed: F. llegada diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 27a700083..14faef3ee 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -2,6 +2,9 @@ + + @@ -9,7 +12,6 @@ - Id Reference Agency Warehouse Out @@ -22,10 +24,9 @@ - - {{::travel.id}} {{::travel.ref}} {{::travel.agencyModeName}} {{::travel.warehouseOutName}} @@ -49,7 +50,7 @@ vn-tooltip="Clone" icon="icon-clone"> - @@ -78,7 +79,7 @@ fixed-bottom-right> - Filter by selection - Exclude selection - Remove filter - Remove all filters - Copy value - \ No newline at end of file + diff --git a/modules/travel/front/locale/es.yml b/modules/travel/front/locale/es.yml index 7231d37cd..043702b99 100644 --- a/modules/travel/front/locale/es.yml +++ b/modules/travel/front/locale/es.yml @@ -1,7 +1,7 @@ #Ordenar alfabeticamente Reference: Referencia -Warehouse Out: Almacén salida -Warehouse In: Almacén llegada +Warehouse Out: Alm salida +Warehouse In: Alm llegada Shipped from: Salida desde Shipped to: Salida hasta Landed from: Llegada desde @@ -10,12 +10,12 @@ Shipped: F. salida Landed: F. llegada Delivered: Enviado Received: Recibido -Travel id: Id envío -Search travels by id: Buscar envíos por identificador +Travel id: Id +Search travels by id: Buscar envíos por identificador o referencia New travel: Nuevo envío travel: envío # Sections Travels: Envíos Log: Historial -Thermographs: Termógrafos \ No newline at end of file +Thermographs: Termógrafos diff --git a/modules/travel/front/main/index.html b/modules/travel/front/main/index.html index feb1e8b01..acf1a1612 100644 --- a/modules/travel/front/main/index.html +++ b/modules/travel/front/main/index.html @@ -7,7 +7,6 @@ - \ No newline at end of file + diff --git a/modules/travel/front/search-panel/index.html b/modules/travel/front/search-panel/index.html index 2e9c796c3..26f6b96c6 100644 --- a/modules/travel/front/search-panel/index.html +++ b/modules/travel/front/search-panel/index.html @@ -1,109 +1,190 @@ -
-
- - - - - - - - - - - - - - - - -
- - - - - - Or - - - - - -
- - - - - - - - - - - - - - - - - - - -
-
\ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + Or +
+ + + + +
+
+ + + + + + + + + + + + +
+ + {{$ctrl.$t('Reference')}}: {{$ctrl.filter.ref}} + + + {{$ctrl.$t('Total entries')}}: {{$ctrl.filter.totalEntries}} + + + {{$ctrl.$t('Travel id')}}: {{$ctrl.filter.id}} + + + {{$ctrl.$t('Agency')}}: {{agency.selection.name}} + + + {{$ctrl.$t('Continent Out')}}: {{continent.selection.name}} + + + {{$ctrl.$t('Shipped from')}}: {{$ctrl.filter.shippedFrom | date:'dd/MM/yyyy'}} + + + {{$ctrl.$t('Shipped to')}}: {{$ctrl.filter.shippedTo | date:'dd/MM/yyyy'}} + + + {{$ctrl.$t('Days onward')}}: {{$ctrl.filter.scopeDays}} + + + {{$ctrl.$t('Landed from')}}: {{$ctrl.filter.landedFrom | date:'dd/MM/yyyy'}} + + + {{$ctrl.$t('Landed to')}}: {{$ctrl.filter.landedTo | date:'dd/MM/yyyy'}} + + + {{$ctrl.$t('Warehouse Out')}}: {{warehouseOut.selection.name}} + + + {{$ctrl.$t('Warehouse In')}}: {{warehouseIn.selection.name}} + +
+
diff --git a/modules/travel/front/search-panel/index.js b/modules/travel/front/search-panel/index.js index 877d4f9d3..69d8dafcd 100644 --- a/modules/travel/front/search-panel/index.js +++ b/modules/travel/front/search-panel/index.js @@ -1,43 +1,37 @@ import ngModule from '../module'; import SearchPanel from 'core/components/searchbar/search-panel'; +import './style.scss'; class Controller extends SearchPanel { constructor($, $element) { super($, $element); - this.filter = this.$.filter; } - get shippedFrom() { - return this._shippedFrom; - } - - set shippedFrom(value) { - this._shippedFrom = value; + changeShipped() { this.filter.scopeDays = null; + this.addFilters(); } - get shippedTo() { - return this._shippedTo; - } - - set shippedTo(value) { - this._shippedTo = value; - this.filter.scopeDays = null; - } - - get scopeDays() { - return this._scopeDays; - } - - set scopeDays(value) { - this._scopeDays = value; - + changeScopeDays() { this.filter.shippedFrom = null; this.filter.shippedTo = null; + this.addFilters(); + } + + addFilters() { + this.model.addFilter({}, this.filter); + } + + removeParamFilter(param) { + this.filter[param] = null; + this.addFilters(); } } ngModule.vnComponent('vnTravelSearchPanel', { template: require('./index.html'), - controller: Controller + controller: Controller, + bindings: { + model: '<' + } }); diff --git a/modules/travel/front/search-panel/style.scss b/modules/travel/front/search-panel/style.scss new file mode 100644 index 000000000..4d08c1402 --- /dev/null +++ b/modules/travel/front/search-panel/style.scss @@ -0,0 +1,42 @@ +@import "variables"; + +vn-travel-search-panel vn-side-menu { + .menu { + min-width: $right-menu-width; + } + & > div { + .input { + padding-left: $spacing-md; + padding-right: $spacing-md; + border-color: $color-spacer; + border-bottom: $border-thin; + } + .horizontal { + padding-left: $spacing-md; + padding-right: $spacing-md; + grid-auto-flow: column; + grid-column-gap: $spacing-sm; + align-items: center; + } + .chips { + display: flex; + flex-wrap: wrap; + padding: $spacing-md; + overflow: hidden; + max-width: 100%; + border-color: $color-spacer; + } + + .or { + align-self: center; + font-weight: bold; + font-size: 26px; + color: $color-font-secondary; + } + + .scope-days{ + display: flex; + align-items: center; + } + } +} diff --git a/modules/travel/front/summary/locale/es.yml b/modules/travel/front/summary/locale/es.yml index aa002fad0..aa6adc938 100644 --- a/modules/travel/front/summary/locale/es.yml +++ b/modules/travel/front/summary/locale/es.yml @@ -1,9 +1,9 @@ Reference: Referencia -Warehouse In: Almacén entrada -Warehouse Out: Almacén salida +Warehouse In: Alm. entrada +Warehouse Out: Alm. salida Shipped: F. envío Landed: F. entrega -Total entries: Entradas totales +Total entries: Ent. totales Delivered: Enviada Received: Recibida Agency: Agencia From dbe42e3bf4490ac60a8d4dc37ea982fb4bd5bc7c Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 2 Mar 2023 13:55:47 +0100 Subject: [PATCH 07/71] refs #5206 version with plane added, needs to implement general search --- front/core/locale/es.yml | 10 +++--- modules/travel/front/index/index.html | 27 +++++++++++--- modules/travel/front/index/index.js | 1 + modules/travel/front/index/style.scss | 11 ++++++ modules/travel/front/main/index.html | 13 ------- modules/travel/front/main/index.js | 22 ------------ modules/travel/front/search-panel/index.html | 37 ++++++-------------- modules/travel/front/search-panel/index.js | 31 ++++++++++++++++ 8 files changed, 82 insertions(+), 70 deletions(-) create mode 100644 modules/travel/front/index/style.scss diff --git a/front/core/locale/es.yml b/front/core/locale/es.yml index d849fcdd2..f654c61cf 100644 --- a/front/core/locale/es.yml +++ b/front/core/locale/es.yml @@ -26,7 +26,7 @@ Value should have at most %s characters: El valor debe tener un máximo de %s ca Enter a new search: Introduce una nueva búsqueda No results: Sin resultados Ups! It seems there was an error: ¡Vaya! Parece que ha habido un error -General search: Busqueda general +General search: Búsqueda general January: Enero February: Febrero March: Marzo @@ -42,9 +42,9 @@ December: Diciembre Monday: Lunes Tuesday: Martes Wednesday: Miércoles -Thursday: Jueves -Friday: Viernes -Saturday: Sábado +Thursday: Jueves +Friday: Viernes +Saturday: Sábado Sunday: Domingo Has delivery: Hay reparto Loading: Cargando @@ -63,4 +63,4 @@ Loading...: Cargando... No results found: Sin resultados No data: Sin datos Undo changes: Deshacer cambios -Load more results: Cargar más resultados \ No newline at end of file +Load more results: Cargar más resultados diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 14faef3ee..06acd92a1 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -5,6 +5,13 @@ + + @@ -16,10 +23,10 @@ Agency Warehouse Out Shipped - Delivered + Warehouse In Landed - Received + @@ -35,14 +42,26 @@ {{::travel.shipped | date:'dd/MM/yyyy'}} - + + + + {{::travel.warehouseInName}} {{::travel.landed | date:'dd/MM/yyyy'}} - + + + + - - - diff --git a/modules/travel/front/main/index.js b/modules/travel/front/main/index.js index fbaf78c16..6a153f21a 100644 --- a/modules/travel/front/main/index.js +++ b/modules/travel/front/main/index.js @@ -4,28 +4,6 @@ import ModuleMain from 'salix/components/module-main'; export default class Travel extends ModuleMain { constructor() { super(); - - this.filterParams = { - scopeDays: 1 - }; - } - - fetchParams($params) { - if (!Object.entries($params).length) - $params.scopeDays = 1; - - if (typeof $params.scopeDays === 'number') { - const shippedFrom = Date.vnNew(); - shippedFrom.setHours(0, 0, 0, 0); - - const shippedTo = new Date(shippedFrom.getTime()); - shippedTo.setDate(shippedTo.getDate() + $params.scopeDays); - shippedTo.setHours(23, 59, 59, 999); - - Object.assign($params, {shippedFrom, shippedTo}); - } - - return $params; } } diff --git a/modules/travel/front/search-panel/index.html b/modules/travel/front/search-panel/index.html index 26f6b96c6..d39f32a7d 100644 --- a/modules/travel/front/search-panel/index.html +++ b/modules/travel/front/search-panel/index.html @@ -1,23 +1,18 @@ + label="General search" + info="Search travels by id" + ng-model="$ctrl.search" + ng-keydown="$ctrl.onKeyPress($event, 'search')"> - - + ng-model="$ctrl.totalEntries" + ng-keydown="$ctrl.onKeyPress($event, 'totalEntries')"> @@ -61,12 +56,9 @@ label="Days onward" ng-model="$ctrl.filter.scopeDays" on-change="$ctrl.changeScopeDays()" - display-controls="true"> + display-controls="true" + info="Cannot choose a range of dates and days onward at the same time"> - - @@ -103,11 +95,11 @@
- {{$ctrl.$t('Reference')}}: {{$ctrl.filter.ref}} + Id/{{$ctrl.$t('Reference')}}: {{$ctrl.filter.search}} {{$ctrl.$t('Total entries')}}: {{$ctrl.filter.totalEntries}} - - {{$ctrl.$t('Travel id')}}: {{$ctrl.filter.id}} - Date: Thu, 2 Mar 2023 15:10:17 +0100 Subject: [PATCH 08/71] refs #5206 implemented general search, missing tests --- modules/travel/front/index/index.html | 3 +- modules/travel/front/main/index.js | 3 -- modules/travel/front/search-panel/index.js | 39 ++++++++-------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 06acd92a1..df7fd5611 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -9,8 +9,7 @@ vn-id="model" url="Travels/filter" limit="20" - order="shipped DESC, landed DESC" - auto-load="true"> + order="shipped DESC, landed DESC"> { + if (param) + this.checkJustOneResult(); + }); } removeParamFilter(param) { @@ -51,12 +36,16 @@ class Controller extends SearchPanel { } onKeyPress($event, param) { - console.log('event'); if ($event.key === 'Enter') { this.filter[param] = this[param]; - this.addFilters(); + this.addFilters(param === 'search'); } } + + checkJustOneResult() { + if (this.model._orgData.length === 1) + this.$state.go('travel.card.summary', {id: this.model._orgData[0].id}); + } } ngModule.vnComponent('vnTravelSearchPanel', { From 423ae852128fef840382044e056e2f704f9872b2 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 8 Mar 2023 12:29:09 +0100 Subject: [PATCH 09/71] refs #4632 dmsRecover deprecated --- back/model-config.json | 3 -- back/models/dms-recover.json | 37 ------------------- db/changes/231001/.gitkeep | 0 db/changes/{230801 => 231001}/00-delivery.sql | 2 + .../back/methods/ticket-dms/saveSign.js | 31 ++-------------- 5 files changed, 6 insertions(+), 67 deletions(-) delete mode 100644 back/models/dms-recover.json delete mode 100644 db/changes/231001/.gitkeep rename db/changes/{230801 => 231001}/00-delivery.sql (98%) diff --git a/back/model-config.json b/back/model-config.json index 6724db151..29676e979 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -44,9 +44,6 @@ "DmsType": { "dataSource": "vn" }, - "DmsRecover": { - "dataSource": "vn" - }, "Docuware": { "dataSource": "vn" }, diff --git a/back/models/dms-recover.json b/back/models/dms-recover.json deleted file mode 100644 index 3449347a7..000000000 --- a/back/models/dms-recover.json +++ /dev/null @@ -1,37 +0,0 @@ - -{ - "name": "DmsRecover", - "description": "Documental Managment System Recover", - "base": "VnModel", - "log": { - "showField": "ticketFk" - }, - "options": { - "mysql": { - "table": "dmsRecover" - } - }, - "properties": { - "id": { - "type": "number", - "id": true, - "description": "Identifier" - }, - "ticketFk": { - "type": "number" - }, - "sign": { - "type": "string" - }, - "created": { - "type": "date" - } - }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - } - } -} diff --git a/db/changes/231001/.gitkeep b/db/changes/231001/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/230801/00-delivery.sql b/db/changes/231001/00-delivery.sql similarity index 98% rename from db/changes/230801/00-delivery.sql rename to db/changes/231001/00-delivery.sql index 38c0a7971..06464b80f 100644 --- a/db/changes/230801/00-delivery.sql +++ b/db/changes/231001/00-delivery.sql @@ -1,3 +1,5 @@ +DROP TABLE `vn`.`dmsRecover`; + ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; diff --git a/modules/ticket/back/methods/ticket-dms/saveSign.js b/modules/ticket/back/methods/ticket-dms/saveSign.js index 725abfe67..9f1684539 100644 --- a/modules/ticket/back/methods/ticket-dms/saveSign.js +++ b/modules/ticket/back/methods/ticket-dms/saveSign.js @@ -51,7 +51,7 @@ module.exports = Self => { ticketFk: ticketId, longitude: args.location.Longitude, latitude: args.location.Latitude, - dated: args.signedTime + dated: args.signedTime || new Date() }, myOptions); } } @@ -67,7 +67,8 @@ module.exports = Self => { if (!ticketDms) return false; const ticket = await models.Ticket.findById(ticketId, {fields: ['isSigned']}, myOptions); - if (ticket.isSigned == true) return true; + if (ticket.isSigned == true) + return true; else await models.Dms.destroyAll({where: {reference: ticketId}}, myOptions); @@ -108,10 +109,6 @@ module.exports = Self => { await models.Ticket.uploadFile(ctxUploadFile, id, myOptions); } - // async function dmsRecover(ticketFk, sign) { - // await models.DmsRecover.create({ticketFk, sign}, myOptions); - // } - try { for (let i = 0; i < args.tickets.length; i++) { const ticketState = await models.TicketState.findOne( @@ -120,35 +117,15 @@ module.exports = Self => { }, myOptions); if (ticketState.alertLevel >= 2 && !await gestDocExists(args.tickets[i])) { - if (!args.signedTime) args.signedTime = Date.vnNew(); if (args.location) setLocation(args.tickets[i]); await createGestDoc(args.tickets[i]); - - // if (image) { - // if (!fs.existsSync(dir)) - // dmsRecover(args.tickets[i], args.signContent); - // else { - // fs.writeFile(image, args.signContent, 'base64', async function(err) { - // if (err) { - // await tx.rollback(); - // throw err.message; - // } - // }); - // } - // } else - // dmsRecover(args.tickets[i], args.signContent); - - // if (id && fileName) { - // await models.TicketDms.replaceOrCreate({ticketFk: args.tickets[i], dmsFk: id}, myOptions); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions); - // await models.Dms.updateAll({id}, {file: fileName, contentType: 'image/png'}, myOptions); - // } } } if (tx) await tx.commit(); - return 'Sign uploaded correctly'; + return 'Signs uploaded correctly'; } catch (e) { if (tx) await tx.rollback(); throw e; From 7c3c3a2d66ff836ccaa2f93e9f71ca4fb4763cb1 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 9 Mar 2023 08:31:38 +0100 Subject: [PATCH 10/71] refs #4632 added userError --- loopback/locale/es.json | 3 +- .../back/methods/ticket-dms/saveSign.js | 25 ++++++------ .../methods/ticket-dms/specs/saveSign.spec.js | 39 ++++--------------- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 507cc9003..0c624ed3d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -266,5 +266,6 @@ "There is no assigned email for this client": "No hay correo asignado para este cliente", "This locker has already been assigned": "Esta taquilla ya ha sido asignada", "Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}", - "Not exist this branch": "La rama no existe" + "Not exist this branch": "La rama no existe", + "This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado" } diff --git a/modules/ticket/back/methods/ticket-dms/saveSign.js b/modules/ticket/back/methods/ticket-dms/saveSign.js index 9f1684539..60dd03be1 100644 --- a/modules/ticket/back/methods/ticket-dms/saveSign.js +++ b/modules/ticket/back/methods/ticket-dms/saveSign.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethodCtx('saveSign', { description: 'Save sign', @@ -46,21 +48,17 @@ module.exports = Self => { } async function setLocation(ticketId) { - if (args.signedTime) { - await models.Delivery.create({ - ticketFk: ticketId, - longitude: args.location.Longitude, - latitude: args.location.Latitude, - dated: args.signedTime || new Date() - }, myOptions); - } + await models.Delivery.create({ + ticketFk: ticketId, + longitude: args.location.Longitude, + latitude: args.location.Latitude, + dated: args.signedTime || new Date() + }, myOptions); } async function gestDocExists(ticketId) { const ticketDms = await models.TicketDms.findOne({ - where: { - ticketFk: ticketId - }, + where: {ticketFk: ticketId}, fields: ['dmsFk'] }, myOptions); @@ -120,12 +118,13 @@ module.exports = Self => { if (args.location) setLocation(args.tickets[i]); await createGestDoc(args.tickets[i]); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions); - } + } else if (ticketState.alertLevel < 2) + throw new UserError('This ticket cannot be signed because it has not been boxed'); } if (tx) await tx.commit(); - return 'Signs uploaded correctly'; + return 'Signs uploaded successfully'; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js index b640fefb8..47902e257 100644 --- a/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js @@ -1,57 +1,32 @@ const models = require('vn-loopback/server/server').models; -fdescribe('TicketDms saveSign()', () => { +describe('TicketDms saveSign()', () => { const FormData = require('form-data'); const data = new FormData(); let ctx = {req: { accessToken: {userId: 9}, headers: { ...data.getHeaders() - }, - on: (param, cb) => {} + } + }}; - it(`should not save sign 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 ticketWithOkState = 12; - + let error; try { const options = {transaction: tx}; ctx.args = {tickets: [ticketWithOkState]}; await models.TicketDms.saveSign(ctx, options); - const ticket = await models.Ticket.findById(ticketWithOkState, {fields: ['isSigned']}, options); - const ticketDms = await models.TicketDms.findOne({where: {ticketFk: ticketWithOkState}}, options); - - expect(ticket.isSigned).toEqual(false); - expect(ticketDms).toEqual(null); await tx.rollback(); } catch (e) { + error = e; await tx.rollback(); - throw e; } - }); - it(`should save sign if the ticket's alert level is greater than 2`, async() => { - const tx = await models.TicketDms.beginTransaction({}); - const ticketWithPackedState = 7; - - try { - const options = {transaction: tx}; - ctx.args = {tickets: [ticketWithPackedState]}; - - await models.TicketDms.saveSign(ctx, options); - const ticket = await models.Ticket.findById(ticketWithPackedState, {fields: ['isSigned']}, options); - const ticketDms = await models.TicketDms.findOne({where: {ticketFk: ticketWithPackedState}}, options); - - expect(ticket.isSigned).toEqual(true); - expect(ticketDms).toBeDefined(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(error).toBeDefined(); }); }); From 874fd0656c58730df7b5bef998cfe0a99972fd0c Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 10 Mar 2023 10:05:16 +0100 Subject: [PATCH 11/71] refs #5206 url gets params --- modules/travel/front/index/index.html | 2 + modules/travel/front/search-panel/index.html | 145 ++++++++----------- modules/travel/front/search-panel/index.js | 58 +++++--- modules/travel/front/search-panel/style.scss | 5 - 4 files changed, 95 insertions(+), 115 deletions(-) diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index df7fd5611..a6952321f 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -26,6 +26,7 @@ Warehouse In Landed + Total entries @@ -61,6 +62,7 @@ ng-class="{active: travel.isReceived}"> + {{::travel.totalEntries}} - - - - + on-change="$ctrl.applyFilters()"> - - - - - - - - - - - Or -
- - -
-
- - - - - + on-change="$ctrl.applyFilters()"> + on-change="$ctrl.applyFilters()"> + + + + + + + + + + + + + + + +
Id/{{$ctrl.$t('Reference')}}: {{$ctrl.filter.search}} - - {{$ctrl.$t('Total entries')}}: {{$ctrl.filter.totalEntries}} - {{$ctrl.$t('Agency')}}: {{agency.selection.name}} - {{$ctrl.$t('Continent Out')}}: {{continent.selection.name}} + {{$ctrl.$t('Warehouse Out')}}: {{warehouseOut.selection.name}} - {{$ctrl.$t('Shipped from')}}: {{$ctrl.filter.shippedFrom | date:'dd/MM/yyyy'}} - - - {{$ctrl.$t('Shipped to')}}: {{$ctrl.filter.shippedTo | date:'dd/MM/yyyy'}} + {{$ctrl.$t('Warehouse In')}}: {{warehouseIn.selection.name}} {{$ctrl.$t('Landed to')}}: {{$ctrl.filter.landedTo | date:'dd/MM/yyyy'}} - {{$ctrl.$t('Warehouse Out')}}: {{warehouseOut.selection.name}} + {{$ctrl.$t('Continent Out')}}: {{continent.selection.name}} - {{$ctrl.$t('Warehouse In')}}: {{warehouseIn.selection.name}} + {{$ctrl.$t('Total entries')}}: {{$ctrl.filter.totalEntries}}
diff --git a/modules/travel/front/search-panel/index.js b/modules/travel/front/search-panel/index.js index 8269a7d51..9cf417da1 100644 --- a/modules/travel/front/search-panel/index.js +++ b/modules/travel/front/search-panel/index.js @@ -5,47 +5,59 @@ import './style.scss'; class Controller extends SearchPanel { constructor($, $element) { super($, $element); - this.filter = { - scopeDays: 1, - }; + this.initFilter(); + this.fetchData(); } - changeShipped() { - this.filter.scopeDays = null; - this.addFilters(); + $onChanges() { + if (this.model) + this.applyFilters(); } - changeScopeDays() { - this.filter.shippedFrom = null; - this.filter.shippedTo = null; - this.addFilters(); + fetchData() { + this.$http.get('AgencyModes').then(res => { + this.agencyModes = res.data; + }); + this.$http.get('Warehouses').then(res => { + this.warehouses = res.data; + }); + this.$http.get('Continents').then(res => { + this.continents = res.data; + }); } - addFilters(param) { - this.model.addFilter({}, this.filter) + initFilter() { + this.filter = {}; + if (this.$params.q) { + this.filter = JSON.parse(this.$params.q); + this.search = this.filter.search; + this.totalEntries = this.filter.totalEntries; + } + if (!this.filter.scopeDays) this.filter.scopeDays = 7; + } + + applyFilters(param) { + this.model.applyFilter({}, this.filter) .then(() => { - if (param) - this.checkJustOneResult(); + if (param && this.model._orgData.length === 1) + this.$state.go('travel.card.summary', {id: this.model._orgData[0].id}); + else + this.$state.go(this.$state.current.name, {q: JSON.stringify(this.filter)}, {location: 'replace'}); }); } removeParamFilter(param) { - if (this[param]) this[param] = null; - this.filter[param] = null; - this.addFilters(); + if (this[param]) delete this[param]; + delete this.filter[param]; + this.applyFilters(); } onKeyPress($event, param) { if ($event.key === 'Enter') { this.filter[param] = this[param]; - this.addFilters(param === 'search'); + this.applyFilters(param === 'search'); } } - - checkJustOneResult() { - if (this.model._orgData.length === 1) - this.$state.go('travel.card.summary', {id: this.model._orgData[0].id}); - } } ngModule.vnComponent('vnTravelSearchPanel', { diff --git a/modules/travel/front/search-panel/style.scss b/modules/travel/front/search-panel/style.scss index 4d08c1402..94fe7b239 100644 --- a/modules/travel/front/search-panel/style.scss +++ b/modules/travel/front/search-panel/style.scss @@ -33,10 +33,5 @@ vn-travel-search-panel vn-side-menu { font-size: 26px; color: $color-font-secondary; } - - .scope-days{ - display: flex; - align-items: center; - } } } From 0248c3c9e0eda364db04d4b20537b4b868faa798 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 13 Mar 2023 07:34:49 +0100 Subject: [PATCH 12/71] refs #5056 models and tables added --- db/changes/231001/.gitkeep | 0 db/changes/231001/00-wagon.sql | 67 +++++++++++++++++++ modules/wagon/back/model-config.json | 23 +++++++ .../wagon/back/models/collectionWagon.json | 34 ++++++++++ .../back/models/collectionWagonTicket.json | 43 ++++++++++++ modules/wagon/back/models/wagon.json | 31 +++++++++ modules/wagon/back/models/wagonConfig.json | 30 +++++++++ modules/wagon/back/models/wagonType.json | 18 +++++ modules/wagon/back/models/wagonTypeColor.json | 21 ++++++ modules/wagon/back/models/wagonTypeTray.json | 36 ++++++++++ 10 files changed, 303 insertions(+) delete mode 100644 db/changes/231001/.gitkeep create mode 100644 db/changes/231001/00-wagon.sql create mode 100644 modules/wagon/back/model-config.json create mode 100644 modules/wagon/back/models/collectionWagon.json create mode 100644 modules/wagon/back/models/collectionWagonTicket.json create mode 100644 modules/wagon/back/models/wagon.json create mode 100644 modules/wagon/back/models/wagonConfig.json create mode 100644 modules/wagon/back/models/wagonType.json create mode 100644 modules/wagon/back/models/wagonTypeColor.json create mode 100644 modules/wagon/back/models/wagonTypeTray.json diff --git a/db/changes/231001/.gitkeep b/db/changes/231001/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/231001/00-wagon.sql b/db/changes/231001/00-wagon.sql new file mode 100644 index 000000000..cd945cc46 --- /dev/null +++ b/db/changes/231001/00-wagon.sql @@ -0,0 +1,67 @@ +CREATE TABLE `vn`.`wagonType` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL UNIQUE, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `vn`.`wagonTypeColor` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL UNIQUE, + `rgb` varchar(30) NOT NULL UNIQUE, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `vn`.`wagonTypeTray` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `typeFk` int(11) unsigned, + `height` int(11) unsigned, + `colorFk` int(11) unsigned, + PRIMARY KEY (`id`), + UNIQUE KEY (`typeFk`,`height`), + CONSTRAINT `wagonTypeTray_type` FOREIGN KEY (`typeFk`) REFERENCES `wagonType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `wagonTypeTray_color` FOREIGN KEY (`colorFk`) REFERENCES `wagonTypeColor` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `vn`.`wagonConfig` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `width` int(11) unsigned DEFAULT 1350, + `height` int(11) unsigned DEFAULT 1900, + `trayStep` int(11) unsigned DEFAULT 50, + `minTrayHeight` int(11) unsigned DEFAULT 200, + `maxTrays` int(11) unsigned DEFAULT 6, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `vn`.`collectionWagon` ( + `collectionFk` int(11) NOT NULL, + `wagonFk` int(11) NOT NULL, + `position` int(11) unsigned, + PRIMARY KEY (`collectionFk`,`position`), + UNIQUE KEY `collectionWagon_unique` (`collectionFk`,`wagonFk`), + CONSTRAINT `collectionWagon_collection` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON UPDATE CASCADE, + CONSTRAINT `collectionWagon_wagon` FOREIGN KEY (`wagonFk`) REFERENCES `wagon` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `vn`.`collectionWagonTicket` ( + `ticketFk` int(11) NOT NULL, + `wagonFk` int(11) NOT NULL, + `trayFk` int(11) unsigned NOT NULL, + `side` SET('L', 'R') NULL, + PRIMARY KEY (`ticketFk`), + CONSTRAINT `collectionWagonTicket_ticket` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE, + CONSTRAINT `collectionWagonTicket_wagon` FOREIGN KEY (`wagonFk`) REFERENCES `wagon` (`id`) ON UPDATE CASCADE, + CONSTRAINT `collectionWagonTicket_tray` FOREIGN KEY (`trayFk`) REFERENCES `wagonTypeTray` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +ALTER TABLE `vn`.`wagon` ADD `typeFk` int(11) unsigned DEFAULT NULL; +ALTER TABLE `vn`.`wagon` ADD CONSTRAINT `wagon_type` FOREIGN KEY (`typeFk`) REFERENCES `wagonType` (`id`) ON UPDATE CASCADE; + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('WagonType', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('WagonTypeColor', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('WagonTypeTray', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('WagonConfig', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('CollectionWagon', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('CollectionWagonTicket', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('Wagon', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/modules/wagon/back/model-config.json b/modules/wagon/back/model-config.json new file mode 100644 index 000000000..279d55e5c --- /dev/null +++ b/modules/wagon/back/model-config.json @@ -0,0 +1,23 @@ +{ + "Wagon": { + "dataSource": "vn" + }, + "WagonType": { + "dataSource": "vn" + }, + "WagonTypeColor": { + "dataSource": "vn" + }, + "WagonTypeTray": { + "dataSource": "vn" + }, + "WagonConfig": { + "dataSource": "vn" + }, + "CollectionWagon": { + "dataSource": "vn" + }, + "CollectionWagonTicket": { + "dataSource": "vn" + } +} diff --git a/modules/wagon/back/models/collectionWagon.json b/modules/wagon/back/models/collectionWagon.json new file mode 100644 index 000000000..f3f237428 --- /dev/null +++ b/modules/wagon/back/models/collectionWagon.json @@ -0,0 +1,34 @@ +{ + "name": "CollectionWagon", + "base": "VnModel", + "options": { + "mysql": { + "table": "collectionWagon" + } + }, + "properties": { + "collectionFk": { + "id": true, + "type": "number" + }, + "wagonFk": { + "type": "number", + "required": true + }, + "position": { + "type": "number" + } + }, + "relations": { + "collection": { + "type": "belongsTo", + "model": "Collection", + "foreignKey": "collectionFk" + }, + "wagon": { + "type": "belongsTo", + "model": "Wagon", + "foreignKey": "wagonFk" + } + } +} diff --git a/modules/wagon/back/models/collectionWagonTicket.json b/modules/wagon/back/models/collectionWagonTicket.json new file mode 100644 index 000000000..04527205c --- /dev/null +++ b/modules/wagon/back/models/collectionWagonTicket.json @@ -0,0 +1,43 @@ +{ + "name": "CollectionWagonTicket", + "base": "VnModel", + "options": { + "mysql": { + "table": "collectionWagonTicket" + } + }, + "properties": { + "ticketFk": { + "id": true, + "type": "number" + }, + "wagonFk": { + "type": "number", + "required": true + }, + "trayFk": { + "type": "number", + "required": true + }, + "side": { + "type": "string" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "wagon": { + "type": "belongsTo", + "model": "Wagon", + "foreignKey": "wagonFk" + }, + "tray": { + "type": "belongsTo", + "model": "WagonTypeTray", + "foreignKey": "trayFk" + } + } +} diff --git a/modules/wagon/back/models/wagon.json b/modules/wagon/back/models/wagon.json new file mode 100644 index 000000000..81b9f23e6 --- /dev/null +++ b/modules/wagon/back/models/wagon.json @@ -0,0 +1,31 @@ +{ + "name": "Wagon", + "base": "VnModel", + "options": { + "mysql": { + "table": "wagon" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "volume": { + "type": "number" + }, + "plate": { + "type": "string" + }, + "typeFk": { + "type": "number" + } + }, + "relations": { + "type": { + "type": "belongsTo", + "model": "WagonType", + "foreignKey": "typeFk" + } + } +} diff --git a/modules/wagon/back/models/wagonConfig.json b/modules/wagon/back/models/wagonConfig.json new file mode 100644 index 000000000..ee33f312e --- /dev/null +++ b/modules/wagon/back/models/wagonConfig.json @@ -0,0 +1,30 @@ +{ + "name": "WagonConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "wagonConfig" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "width": { + "type": "number" + }, + "height": { + "type": "string" + }, + "trayStep": { + "type": "number" + }, + "minTrayHeight": { + "type": "number" + }, + "maxTrays": { + "type": "number" + } + } +} diff --git a/modules/wagon/back/models/wagonType.json b/modules/wagon/back/models/wagonType.json new file mode 100644 index 000000000..feb8d046c --- /dev/null +++ b/modules/wagon/back/models/wagonType.json @@ -0,0 +1,18 @@ +{ + "name": "WagonType", + "base": "VnModel", + "options": { + "mysql": { + "table": "wagonType" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "name": { + "type": "string" + } + } +} diff --git a/modules/wagon/back/models/wagonTypeColor.json b/modules/wagon/back/models/wagonTypeColor.json new file mode 100644 index 000000000..573fd60f5 --- /dev/null +++ b/modules/wagon/back/models/wagonTypeColor.json @@ -0,0 +1,21 @@ +{ + "name": "WagonTypeColor", + "base": "VnModel", + "options": { + "mysql": { + "table": "wagonTypeColor" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "name": { + "type": "string" + }, + "rgb": { + "type": "string" + } + } +} diff --git a/modules/wagon/back/models/wagonTypeTray.json b/modules/wagon/back/models/wagonTypeTray.json new file mode 100644 index 000000000..b61510bcf --- /dev/null +++ b/modules/wagon/back/models/wagonTypeTray.json @@ -0,0 +1,36 @@ +{ + "name": "WagonTypeTray", + "base": "VnModel", + "options": { + "mysql": { + "table": "wagonTypeTray" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "typeFk": { + "type": "number" + }, + "height": { + "type": "number" + }, + "colorFk": { + "type": "number" + } + }, + "relations": { + "type": { + "type": "belongsTo", + "model": "WagonType", + "foreignKey": "typeFk" + }, + "color": { + "type": "belongsTo", + "model": "WagonTypeColor", + "foreignKey": "colorFk" + } + } +} From 6a2542758b70bb33495c40a376b194e8e1411214 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 15 Mar 2023 10:29:44 +0100 Subject: [PATCH 13/71] refs #5056 added fixtures --- modules/item/front/diary/index.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/item/front/diary/index.html b/modules/item/front/diary/index.html index 0f00f5854..e29e76afa 100644 --- a/modules/item/front/diary/index.html +++ b/modules/item/front/diary/index.html @@ -16,15 +16,15 @@ - - + + @@ -44,7 +44,7 @@
- {{::sale.shipped | date:'dd/MM/yyyy' }} @@ -99,13 +99,13 @@ - - - From 53bca1e8a302d1939f39d2b80a93644a431954b7 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 15 Mar 2023 11:36:10 +0100 Subject: [PATCH 14/71] refs #5056 added fixtures --- db/dump/fixtures.sql | 11 +++++++++++ modules/item/front/diary/index.html | 28 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 80983a318..488285b6b 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2821,4 +2821,15 @@ INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `create (1, 1, util.VN_NOW()), (3, 3, util.VN_NOW()); +INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `trayStep`, `minTrayHeight`, `maxTrays`) + VALUES + (1, 1350, 1900, 50, 200, 6); + + +INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) + VALUES + (1, 'red', '#ff0000'), + (2, 'green', '#00ff00'), + (3, 'blue', '#0000ff'); + diff --git a/modules/item/front/diary/index.html b/modules/item/front/diary/index.html index e29e76afa..0f00f5854 100644 --- a/modules/item/front/diary/index.html +++ b/modules/item/front/diary/index.html @@ -16,15 +16,15 @@ - - + + @@ -44,7 +44,7 @@ - {{::sale.shipped | date:'dd/MM/yyyy' }} @@ -99,13 +99,13 @@ - - - From f706b66efcb270f37f17cffcfa4f046eb234702c Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 15 Mar 2023 11:57:09 +0100 Subject: [PATCH 15/71] refs #5056 added divisible in wagonType --- db/changes/231001/00-wagon.sql | 4 ++-- db/dump/fixtures.sql | 4 ++-- ...ollectionWagonTicket.json => collection-wagon-ticket.json} | 0 .../models/{collectionWagon.json => collection-wagon.json} | 0 .../wagon/back/models/{wagonConfig.json => wagon-config.json} | 3 --- .../models/{wagonTypeColor.json => wagon-type-color.json} | 0 .../back/models/{wagonTypeTray.json => wagon-type-tray.json} | 0 modules/wagon/back/models/{wagonType.json => wagon-type.json} | 3 +++ 8 files changed, 7 insertions(+), 7 deletions(-) rename modules/wagon/back/models/{collectionWagonTicket.json => collection-wagon-ticket.json} (100%) rename modules/wagon/back/models/{collectionWagon.json => collection-wagon.json} (100%) rename modules/wagon/back/models/{wagonConfig.json => wagon-config.json} (88%) rename modules/wagon/back/models/{wagonTypeColor.json => wagon-type-color.json} (100%) rename modules/wagon/back/models/{wagonTypeTray.json => wagon-type-tray.json} (100%) rename modules/wagon/back/models/{wagonType.json => wagon-type.json} (82%) diff --git a/db/changes/231001/00-wagon.sql b/db/changes/231001/00-wagon.sql index cd945cc46..5249c1faf 100644 --- a/db/changes/231001/00-wagon.sql +++ b/db/changes/231001/00-wagon.sql @@ -1,6 +1,7 @@ CREATE TABLE `vn`.`wagonType` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL UNIQUE, + `divisible` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; @@ -26,8 +27,7 @@ CREATE TABLE `vn`.`wagonConfig` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `width` int(11) unsigned DEFAULT 1350, `height` int(11) unsigned DEFAULT 1900, - `trayStep` int(11) unsigned DEFAULT 50, - `minTrayHeight` int(11) unsigned DEFAULT 200, + `minTrayHeight` int(11) unsigned DEFAULT 50, `maxTrays` int(11) unsigned DEFAULT 6, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 488285b6b..302d16d76 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2821,9 +2821,9 @@ INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `create (1, 1, util.VN_NOW()), (3, 3, util.VN_NOW()); -INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `trayStep`, `minTrayHeight`, `maxTrays`) +INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `minTrayHeight`, `maxTrays`) VALUES - (1, 1350, 1900, 50, 200, 6); + (1, 1350, 1900, 50, 6); INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) diff --git a/modules/wagon/back/models/collectionWagonTicket.json b/modules/wagon/back/models/collection-wagon-ticket.json similarity index 100% rename from modules/wagon/back/models/collectionWagonTicket.json rename to modules/wagon/back/models/collection-wagon-ticket.json diff --git a/modules/wagon/back/models/collectionWagon.json b/modules/wagon/back/models/collection-wagon.json similarity index 100% rename from modules/wagon/back/models/collectionWagon.json rename to modules/wagon/back/models/collection-wagon.json diff --git a/modules/wagon/back/models/wagonConfig.json b/modules/wagon/back/models/wagon-config.json similarity index 88% rename from modules/wagon/back/models/wagonConfig.json rename to modules/wagon/back/models/wagon-config.json index ee33f312e..8bad354f7 100644 --- a/modules/wagon/back/models/wagonConfig.json +++ b/modules/wagon/back/models/wagon-config.json @@ -17,9 +17,6 @@ "height": { "type": "string" }, - "trayStep": { - "type": "number" - }, "minTrayHeight": { "type": "number" }, diff --git a/modules/wagon/back/models/wagonTypeColor.json b/modules/wagon/back/models/wagon-type-color.json similarity index 100% rename from modules/wagon/back/models/wagonTypeColor.json rename to modules/wagon/back/models/wagon-type-color.json diff --git a/modules/wagon/back/models/wagonTypeTray.json b/modules/wagon/back/models/wagon-type-tray.json similarity index 100% rename from modules/wagon/back/models/wagonTypeTray.json rename to modules/wagon/back/models/wagon-type-tray.json diff --git a/modules/wagon/back/models/wagonType.json b/modules/wagon/back/models/wagon-type.json similarity index 82% rename from modules/wagon/back/models/wagonType.json rename to modules/wagon/back/models/wagon-type.json index feb8d046c..f57bf957d 100644 --- a/modules/wagon/back/models/wagonType.json +++ b/modules/wagon/back/models/wagon-type.json @@ -13,6 +13,9 @@ }, "name": { "type": "string" + }, + "divisible": { + "type": "boolean" } } } From 6609cce06521d4843f4d586a0d89dfafa737b23f Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 15 Mar 2023 12:14:58 +0100 Subject: [PATCH 16/71] refs #5056 minHeightBetweenTrays --- db/changes/231001/00-wagon.sql | 3 ++- db/dump/fixtures.sql | 5 +++-- modules/wagon/back/models/wagon-config.json | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/db/changes/231001/00-wagon.sql b/db/changes/231001/00-wagon.sql index 5249c1faf..c7725ab4f 100644 --- a/db/changes/231001/00-wagon.sql +++ b/db/changes/231001/00-wagon.sql @@ -27,7 +27,8 @@ CREATE TABLE `vn`.`wagonConfig` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `width` int(11) unsigned DEFAULT 1350, `height` int(11) unsigned DEFAULT 1900, - `minTrayHeight` int(11) unsigned DEFAULT 50, + `maxWagonHeight` int(11) unsigned DEFAULT 200, + `minHeightBetweenTrays` int(11) unsigned DEFAULT 50, `maxTrays` int(11) unsigned DEFAULT 6, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 302d16d76..45f90359e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2821,9 +2821,10 @@ INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `create (1, 1, util.VN_NOW()), (3, 3, util.VN_NOW()); -INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `minTrayHeight`, `maxTrays`) +INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`) VALUES - (1, 1350, 1900, 50, 6); + (1, 1350, 1900, 200, 50, 6); + INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) diff --git a/modules/wagon/back/models/wagon-config.json b/modules/wagon/back/models/wagon-config.json index 8bad354f7..3d96e2864 100644 --- a/modules/wagon/back/models/wagon-config.json +++ b/modules/wagon/back/models/wagon-config.json @@ -17,7 +17,10 @@ "height": { "type": "string" }, - "minTrayHeight": { + "maxWagonHeight": { + "type": "number" + }, + "minHeightBetweenTrays": { "type": "number" }, "maxTrays": { From 1b8ed05f71b7e7edb0b67f19405374172215d5b2 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 15 Mar 2023 13:28:28 +0100 Subject: [PATCH 17/71] =?UTF-8?q?refs=20#5395=20feat:=20modificado=20order?= =?UTF-8?q?By,=20a=C3=B1adida=20columna=20importa=20y=20corregidos=20error?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/claim-state/isEditable.js | 16 +++++++------- .../methods/travel/extraCommunityFilter.js | 2 ++ .../travel/front/extra-community/index.html | 21 ++++++++----------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/modules/claim/back/methods/claim-state/isEditable.js b/modules/claim/back/methods/claim-state/isEditable.js index 2d0a8dc44..ad51d543a 100644 --- a/modules/claim/back/methods/claim-state/isEditable.js +++ b/modules/claim/back/methods/claim-state/isEditable.js @@ -26,13 +26,13 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - - const state = await models.ClaimState.findById(id, { - include: { - relation: 'writeRole' - } - }, myOptions); - const roleWithGrants = state && state.writeRole().name; - return await models.Account.hasRole(userId, roleWithGrants, myOptions); + + const state = await models.ClaimState.findById(id, { + include: { + relation: 'writeRole' + } + }, myOptions); + const roleWithGrants = state && state.writeRole().name; + return await models.Account.hasRole(userId, roleWithGrants, myOptions); }; }; 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 ee8dcdf98..73e62b174 100644 --- a/modules/travel/front/extra-community/index.html +++ b/modules/travel/front/extra-community/index.html @@ -3,7 +3,7 @@ url="Travels/extraCommunityFilter" filter="::$ctrl.filter" 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}} - - + + From a99bd2577afe0f18084e527dc74324c095a0c73f Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 16 Mar 2023 08:24:34 +0100 Subject: [PATCH 18/71] refs #4632 changed route from TicketDms to Ticket --- db/changes/231001/00-delivery.sql | 2 +- .../ticket/back/methods/{ticket-dms => ticket}/saveSign.js | 0 .../methods/{ticket-dms => ticket}/specs/saveSign.spec.js | 4 ++-- modules/ticket/back/models/ticket-dms.js | 1 - modules/ticket/back/models/ticket-methods.js | 1 + 5 files changed, 4 insertions(+), 4 deletions(-) rename modules/ticket/back/methods/{ticket-dms => ticket}/saveSign.js (100%) rename modules/ticket/back/methods/{ticket-dms => ticket}/specs/saveSign.spec.js (88%) diff --git a/db/changes/231001/00-delivery.sql b/db/changes/231001/00-delivery.sql index 06464b80f..3a9269183 100644 --- a/db/changes/231001/00-delivery.sql +++ b/db/changes/231001/00-delivery.sql @@ -8,7 +8,7 @@ ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ti DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) VALUES - ('TicketDms','saveSign','WRITE','ALLOW','employee'); + ('Ticket','saveSign','WRITE','ALLOW','employee'); DROP PROCEDURE IF EXISTS vn.route_getTickets; diff --git a/modules/ticket/back/methods/ticket-dms/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js similarity index 100% rename from modules/ticket/back/methods/ticket-dms/saveSign.js rename to modules/ticket/back/methods/ticket/saveSign.js diff --git a/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js similarity index 88% rename from modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js rename to modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 47902e257..6b532a5d1 100644 --- a/modules/ticket/back/methods/ticket-dms/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('TicketDms saveSign()', () => { +describe('Ticket saveSign()', () => { const FormData = require('form-data'); const data = new FormData(); let ctx = {req: { @@ -19,7 +19,7 @@ describe('TicketDms saveSign()', () => { const options = {transaction: tx}; ctx.args = {tickets: [ticketWithOkState]}; - await models.TicketDms.saveSign(ctx, options); + await models.Ticket.saveSign(ctx, options); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/models/ticket-dms.js b/modules/ticket/back/models/ticket-dms.js index 13d960270..9bceaae6e 100644 --- a/modules/ticket/back/models/ticket-dms.js +++ b/modules/ticket/back/models/ticket-dms.js @@ -2,7 +2,6 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { require('../methods/ticket-dms/removeFile')(Self); - require('../methods/ticket-dms/saveSign')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 73df0579c..3992e7307 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -39,4 +39,5 @@ module.exports = function(Self) { require('../methods/ticket/isRoleAdvanced')(Self); require('../methods/ticket/collectionLabel')(Self); require('../methods/ticket/expeditionPalletLabel')(Self); + require('../methods/ticket/saveSign')(Self); }; From 70beaf9b6c12165c9995cde71155b131d3c7c272 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 16 Mar 2023 09:03:16 +0100 Subject: [PATCH 19/71] =?UTF-8?q?refs=20#5423=20a=C3=B1adido=203r=20decima?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/item/front/last-entries/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/item/front/last-entries/index.html b/modules/item/front/last-entries/index.html index f6cdf8343..8c883d46c 100644 --- a/modules/item/front/last-entries/index.html +++ b/modules/item/front/last-entries/index.html @@ -86,10 +86,10 @@ class="expendable"> + {{::$ctrl.$t('Cost')}}: {{::entry.buyingValue | currency: 'EUR':3 | dashIfEmpty}}
+ {{::$ctrl.$t('Package')}}: {{::entry.packageValue | currency: 'EUR':3 | dashIfEmpty}}
+ {{::$ctrl.$t('Freight')}}: {{::entry.freightValue | currency: 'EUR':3 | dashIfEmpty}}
+ {{::$ctrl.$t('Comission')}}: {{::entry.comissionValue | currency: 'EUR':3 | dashIfEmpty}}"> {{::entry.cost | currency: 'EUR':2 | dashIfEmpty}}
From 6e2269b428c0e847b50630f0271d9be08523cb92 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 16 Mar 2023 09:04:57 +0100 Subject: [PATCH 20/71] refs #4632 removed alert level id from code --- modules/ticket/back/methods/ticket/saveSign.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 60dd03be1..177cb9b46 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -114,12 +114,17 @@ module.exports = Self => { fields: ['alertLevel'] }, myOptions); - if (ticketState.alertLevel >= 2 && !await gestDocExists(args.tickets[i])) { + const boxedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'}, + fields: ['id'] + }, myOptions); + + if (ticketState.alertLevel < boxedAlertLevel.id) + throw new UserError('This ticket cannot be signed because it has not been boxed'); + else if (!await gestDocExists(args.tickets[i])) { if (args.location) setLocation(args.tickets[i]); await createGestDoc(args.tickets[i]); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions); - } else if (ticketState.alertLevel < 2) - throw new UserError('This ticket cannot be signed because it has not been boxed'); + } } if (tx) await tx.commit(); From a0be5c50fcffdffc91f4924b0987fea9b52b8399 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 16 Mar 2023 09:07:19 +0100 Subject: [PATCH 21/71] refs #4632 changed packed from boxed --- modules/ticket/back/methods/ticket/saveSign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 177cb9b46..c3d6e4baa 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -114,11 +114,11 @@ module.exports = Self => { fields: ['alertLevel'] }, myOptions); - const boxedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'}, + const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'}, fields: ['id'] }, myOptions); - if (ticketState.alertLevel < boxedAlertLevel.id) + if (ticketState.alertLevel < packedAlertLevel.id) throw new UserError('This ticket cannot be signed because it has not been boxed'); else if (!await gestDocExists(args.tickets[i])) { if (args.location) setLocation(args.tickets[i]); From 1a79bb586c1deeaba4062fae0913615a5cf7c772 Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 16 Mar 2023 09:07:59 +0100 Subject: [PATCH 22/71] Added version 2312.01 --- CHANGELOG.md | 14 +++++++++++--- db/changes/231201/.gitkeep | 0 package.json | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 db/changes/231201/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dadbafcf..dde790aaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2312.01] - 2023-04-06 + +### Added +- + +### Changed +- + +### Fixed +- + ## [2310.01] - 2023-03-23 ### Added - (Trabajadores -> Control de horario) Ahora se puede confirmar/no confirmar el registro horario de cada semana desde esta sección -### Changed -- - ### Fixed - (Clientes -> Listado extendido) Resuelto error al filtrar por clientes inactivos desde la columna "Activo" - (General) Al pasar el ratón por encima del icono de "Borrar" en un campo, se hacía más grande afectando a la interfaz diff --git a/db/changes/231201/.gitkeep b/db/changes/231201/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json index 10777d680..3d0fc4aed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.10.01", + "version": "23.12.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 60162fe71fe4ea9a1c5a5c1644acc2acbf09431b Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 16 Mar 2023 10:30:53 +0100 Subject: [PATCH 23/71] refs #4632 removed return --- modules/ticket/back/methods/ticket/saveSign.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index c3d6e4baa..79ed01361 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -128,8 +128,6 @@ module.exports = Self => { } if (tx) await tx.commit(); - - return 'Signs uploaded successfully'; } catch (e) { if (tx) await tx.rollback(); throw e; From 668fa733869f9c579f36674b81af704b38c16bfc Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 16 Mar 2023 10:32:00 +0100 Subject: [PATCH 24/71] refs #4632 deleted return in definition --- modules/ticket/back/methods/ticket/saveSign.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 79ed01361..ab1c32d1b 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -23,10 +23,6 @@ module.exports = Self => { description: 'The signed time' } ], - returns: { - type: 'string', - root: true - }, http: { path: `/saveSign`, verb: 'POST' From 2f2d65bfd67c3880a9fc76e8d0c4718027c86b31 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 16 Mar 2023 10:33:24 +0100 Subject: [PATCH 25/71] =?UTF-8?q?refs=20#5342=20feat:=20a=C3=B1adido=20ico?= =?UTF-8?q?no=20en=20los=20tickets=20que=20tengan=20sales=20fragiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- db/changes/231201/00-sale_getWarnings.sql | 35 +++++++++++++++ db/changes/231201/00-ticket_getWarnings.sql | 36 ++++++++++++++++ .../back/methods/sales-monitor/salesFilter.js | 19 +++++++- modules/monitor/front/index/locale/es.yml | 3 +- .../monitor/front/index/tickets/index.html | 43 +++++++++++-------- 6 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 db/changes/231201/00-sale_getWarnings.sql create mode 100644 db/changes/231201/00-ticket_getWarnings.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index dde790aaa..8f4e45398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2312.01] - 2023-04-06 ### Added -- +- (Monitor tickets) Muestra un icono al lado de la zona, si es frágil y se envía por agencia ### Changed - diff --git a/db/changes/231201/00-sale_getWarnings.sql b/db/changes/231201/00-sale_getWarnings.sql new file mode 100644 index 000000000..ee2c7b8f2 --- /dev/null +++ b/db/changes/231201/00-sale_getWarnings.sql @@ -0,0 +1,35 @@ +DROP PROCEDURE IF EXISTS `vn`.`sale_getWarnings`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_getWarnings`() +BEGIN +/** + * Calcula las advertencias de cada venta para un conjunto de tickets. + * + * @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular + * @return tmp.sale_warnings + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings; + CREATE TEMPORARY TABLE tmp.sale_warnings ( + ticketFk INT(11), + saleFk INT(11), + isFragile INTEGER(1) DEFAULT 0, + PRIMARY KEY (ticketFk, saleFk) + ) ENGINE = MEMORY; + + -- Frágil + INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile) + SELECT tt.ticketFk, s.id, TRUE + FROM tmp.sale_getWarnings tt + LEFT JOIN sale s ON s.ticketFk = tt.ticketFk + LEFT JOIN item i ON i.id = s.itemFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN agencyMode am ON am.id = tt.agencyModeFk + LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.code IN ('AGENCY', 'DELIVERY') + AND (ic.code = 'plant' OR it.code IN ('ZKA', 'ZKE')); +END$$ +DELIMITER ; diff --git a/db/changes/231201/00-ticket_getWarnings.sql b/db/changes/231201/00-ticket_getWarnings.sql new file mode 100644 index 000000000..0cd420bd3 --- /dev/null +++ b/db/changes/231201/00-ticket_getWarnings.sql @@ -0,0 +1,36 @@ +DROP PROCEDURE IF EXISTS `vn`.`ticket_getWarnings`; + +DELIMITER $$ +$$ +CREATE PROCEDURE `vn`.`ticket_getWarnings`() +BEGIN +/** + * Calcula las adventencias para un conjunto de tickets. + * Agrupados por ticket + * + * @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular + * @return tmp.ticket_warnings + */ + CALL sale_getWarnings(); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_warnings; + CREATE TEMPORARY TABLE tmp.ticket_warnings + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT + sw.ticketFk, + MAX(sw.isFragile) AS isFragile, + 0 AS totalWarnings + FROM tmp.sale_warnings sw + GROUP BY sw.ticketFk; + + UPDATE tmp.ticket_warnings tw + SET tw.totalWarnings = + ( + (tw.isFragile) + ); + + DROP TEMPORARY TABLE + tmp.sale_warnings; +END$$ +DELIMITER ; diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 881fc637a..c9a25b1a1 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -295,11 +295,26 @@ module.exports = Self => { risk = t.debt + t.credit, totalProblems = totalProblems + 1 `); + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getWarnings'); + stmt = new ParameterizedSQL(` - SELECT t.*, tp.*, - ((tp.risk) + cc.riskTolerance < 0) AS hasHighRisk + CREATE TEMPORARY TABLE tmp.sale_getWarnings + (INDEX (ticketFk, agencyModeFk)) + ENGINE = MEMORY + SELECT f.id ticketFk, f.agencyModeFk + FROM tmp.filter f`); + stmts.push(stmt); + + stmts.push('CALL ticket_getWarnings()'); + + stmt = new ParameterizedSQL(` + SELECT t.*, + tp.*, + ((tp.risk) + cc.riskTolerance < 0) AS hasHighRisk, + tw.* FROM tmp.tickets t LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = t.id + LEFT JOIN tmp.ticket_warnings tw ON tw.ticketFk = t.id JOIN clientConfig cc`); const hasProblems = args.problems; diff --git a/modules/monitor/front/index/locale/es.yml b/modules/monitor/front/index/locale/es.yml index 126528caa..f114a2259 100644 --- a/modules/monitor/front/index/locale/es.yml +++ b/modules/monitor/front/index/locale/es.yml @@ -12,4 +12,5 @@ Theoretical: Teórica Practical: Práctica Preparation: Preparación Auto-refresh: Auto-refresco -Toggle auto-refresh every 2 minutes: Conmuta el refresco automático cada 2 minutos \ No newline at end of file +Toggle auto-refresh every 2 minutes: Conmuta el refresco automático cada 2 minutos +Is fragile: Es frágil diff --git a/modules/monitor/front/index/tickets/index.html b/modules/monitor/front/index/tickets/index.html index b8559154e..539d4b3cb 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -19,13 +19,13 @@ Tickets monitor - + - State + Zone @@ -80,7 +81,7 @@ @@ -169,12 +170,20 @@ class="link"> {{ticket.refFk}} - {{ticket.state}} + + + + - Filter by selection - Exclude selection - Remove filter - Remove all filters - Copy value From 1cd768f7b87e74387b9fa7da9c86cf983d24359f Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 16 Mar 2023 10:39:02 +0100 Subject: [PATCH 26/71] refs #5056 moved sql --- db/changes/231201/.gitkeep | 0 db/changes/{231001 => 231201}/00-wagon.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 db/changes/231201/.gitkeep rename db/changes/{231001 => 231201}/00-wagon.sql (100%) diff --git a/db/changes/231201/.gitkeep b/db/changes/231201/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/231001/00-wagon.sql b/db/changes/231201/00-wagon.sql similarity index 100% rename from db/changes/231001/00-wagon.sql rename to db/changes/231201/00-wagon.sql From 23ce51abf07c23fb7b0253d72706bba3bd3e2ce7 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 16 Mar 2023 11:34:57 +0100 Subject: [PATCH 27/71] refs #5342 add changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f4e45398..e7d1da557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2312.01] - 2023-04-06 ### Added -- (Monitor tickets) Muestra un icono al lado de la zona, si es frágil y se envía por agencia +- (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia ### Changed - From 9565bb33f2c30635d4dd7e3660e5e35c31b442c0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 16 Mar 2023 14:12:54 +0100 Subject: [PATCH 28/71] refs #5425 modificacion de los campos --- e2e/helpers/selectors.js | 2 +- modules/entry/front/latest-buys/index.html | 2 +- modules/item/front/basic-data/index.html | 2 +- modules/item/front/index/index.html | 2 +- modules/item/front/locale/es.yml | 4 ++-- modules/item/front/summary/index.html | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f20d75310..d4c68ff00 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -410,7 +410,7 @@ export default { advancedSearchButton: 'vn-item-search-panel button[type=submit]', advancedSmartTableButton: 'vn-item-index vn-button[icon="search"]', advancedSmartTableGrouping: 'vn-item-index vn-textfield[name=grouping]', - weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight/Piece"]', + weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight per unit"]', saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button' }, itemFixedPrice: { diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index 727b19220..0fe2de94d 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -63,7 +63,7 @@ Origin - Weight/Piece + Weight per unit Active diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index 974aa37d8..5e6752aea 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -124,7 +124,7 @@ diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 6f5cce7c0..47e71c2df 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -46,7 +46,7 @@ Buyer - Weight/Piece + Weight per unit Multiplier diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 0fc014742..115a69528 100644 --- a/modules/item/front/locale/es.yml +++ b/modules/item/front/locale/es.yml @@ -40,11 +40,11 @@ Create: Crear Client card: Ficha del cliente Shipped: F. envío stems: Tallos -Weight/Piece: Peso/tallo +Weight per unit: Peso por unidad (gramos) Search items by id, name or barcode: Buscar articulos por identificador, nombre o codigo de barras SalesPerson: Comercial Concept: Concepto -Units/Box: Unidades/Caja +Units/Box: Unidades/caja # Sections Items: Artículos diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index 46a2baef4..cdcc2ae49 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -110,7 +110,7 @@ - Date: Fri, 17 Mar 2023 08:46:01 +0100 Subject: [PATCH 29/71] refs #4357 add operator model --- db/changes/231201/00-ACL.sql | 3 + db/changes/231201/00-operator.sql | 159 +++++++++++++++++++++++ db/dump/fixtures.sql | 4 + modules/worker/back/model-config.json | 3 + modules/worker/back/models/operator.json | 44 +++++++ 5 files changed, 213 insertions(+) create mode 100644 db/changes/231201/00-ACL.sql create mode 100644 db/changes/231201/00-operator.sql create mode 100644 modules/worker/back/models/operator.json diff --git a/db/changes/231201/00-ACL.sql b/db/changes/231201/00-ACL.sql new file mode 100644 index 000000000..47a818977 --- /dev/null +++ b/db/changes/231201/00-ACL.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES ('Operator', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Operator', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/231201/00-operator.sql b/db/changes/231201/00-operator.sql new file mode 100644 index 000000000..9b7815b41 --- /dev/null +++ b/db/changes/231201/00-operator.sql @@ -0,0 +1,159 @@ +ALTER TABLE `vn`.`operator` ADD sectorFk int(11) NULL; +ALTER TABLE `vn`.`operator` ADD labelerFk tinyint(3) unsigned NULL; +ALTER TABLE `vn`.`operator` ADD CONSTRAINT operator_FK_5 FOREIGN KEY (labelerFk) REFERENCES `vn`.`printer`(id) ON DELETE CASCADE ON UPDATE CASCADE; + +UPDATE `vn`.`operator` o +JOIN (SELECT id, sectorFk, labelerFk + FROM `vn`.`worker`) sub ON sub.id = o.workerFk + SET o.sectorFk = sub.sectorFk, + o.labelerFk = sub.labelerFk; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_printSticker`( + vSelf INT, + vLabelCount INT +) +BEGIN +/** + * Prints a yellow label from a collection or a ticket + * + * @param vSelf collection or ticket + * @param vLabelCount number of times the collection has been printed + */ + DECLARE vPrintArgs JSON DEFAULT JSON_OBJECT('collectionOrTicketFk', vSelf); + + IF vLabelCount IS NULL THEN + INSERT INTO ticketTrolley + SELECT ticketFk, 1 + FROM ticketCollection + WHERE collectionFk = vSelf + ON DUPLICATE KEY UPDATE labelCount = labelCount + 1; + ELSE + SET vPrintArgs = JSON_MERGE_PATCH(vPrintArgs, JSON_OBJECT('labelCount', vLabelCount)); + END IF; + + CALL report_print( + 'LabelCollection', + (SELECT o.labelerFk FROM operator o WHERE o.workerFk = account.myUser_getId()), + account.myUser_getId(), + vPrintArgs, + 'high' + ); +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_printLabel`(vSelf INT) +BEGIN +/** + * Calls the report_print procedure and passes it + * the necessary parameters for printing. + * + * @param vSelf expeditioPallet id. + */ + DECLARE vPrinterFk INT; + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SELECT o.labelerFk INTO vPrinterFk + FROM operator o + WHERE o.workerFk = vUserFk; + + CALL vn.report_print( + 'LabelPalletExpedition', + vPrinterFk, + account.myUser_getId(), + JSON_OBJECT('palletFk', vSelf, 'userFk', vUserFk), + 'high' + ); + + UPDATE vn.expeditionPallet + SET isPrint = TRUE + WHERE id = vSelf; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getAlternatives`(vShelvingFk VARCHAR(10)) +BEGIN +/** + * Devuelve un listado de posibles ubicaciones alternativas a ubicar los item de la matricula + * del carro que se le ha pasado. + * + * @param vShelvingFk matricula del carro + */ + SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder + FROM itemShelving is2 + JOIN shelving sh ON sh.code = is2.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + LEFT JOIN operator o ON o.sectorFk = s.id + LEFT JOIN worker w ON w.sectorFk = s.id AND w.id = account.myUser_getId() + JOIN warehouse wh ON wh.id = s.warehouseFk + JOIN itemShelving is3 ON is3.itemFk = is2.itemFk AND is3.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + WHERE is2.shelvingFk <> vShelvingFk COLLATE utf8_unicode_ci + GROUP BY is2.id + ORDER BY p.pickingOrder DESC; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`operator_beforeInsert` + BEFORE INSERT ON `operator` + FOR EACH ROW +BEGIN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`operator_beforeUpdate` + BEFORE UPDATE ON `operator` + FOR EACH ROW +BEGIN + IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); + END IF; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`worker_beforeUpdate` + BEFORE UPDATE ON `worker` + FOR EACH ROW +BEGIN + IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); + + INSERT IGNORE INTO vn.operator (workerFk) + VALUES (NEW.id); + + UPDATE operator + SET labelerFk = NEW.labelerFk, + sectorFk = NEW.sectorFk + WHERE workerFk = NEW.id; + END IF; +END$$ +DELIMITER ; + +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`operatorWorkerCode` +AS SELECT `o`.`workerFk` AS `workerFk`, + concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `fullName`, + `w`.`code` AS `code`, + `o`.`numberOfWagons` AS `numberOfWagons` +FROM ( + ( + `vn`.`worker` `w` + JOIN `vn`.`operator` `o` ON(`o`.`workerFk` = `w`.`id`) + ) + JOIN `vn`.`sector` `s` ON(`o`.`sectorFk` = `s`.`id`) + ) +WHERE `o`.`sectorFk` IS NOT NULL + AND `s`.`code` IN ( + 'H2', + 'H2', + 'PEQUES_H', + 'ALTILLO COMP', + 'ALTILLO ARTI' + ) \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 3ab34e1d5..c4df3e84f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -173,6 +173,10 @@ INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPrepare (1, 'First sector', 1, 1, 'FIRST'), (2, 'Second sector', 2, 0, 'SECOND'); +INSERT INTO `vn`.`operator` (`workerFk`, `numberOfWagons`, `trainFk`, `itemPackingTypeFk`, `warehouseFk`, `sectorFk`, `labelerFk`) + VALUES ('1106', '1', '1', 'H', '1', '1', '1'), + ('1107', '1', '1', 'V', '1', '2', '1'); + INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAddress`) VALUES (1, 'printer1', 'path1', 0, 1 , NULL), diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 8079bd165..63fc65827 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -94,6 +94,9 @@ }, "WorkerTimeControlMail": { "dataSource": "vn" + }, + "Operator": { + "dataSource": "vn" } } diff --git a/modules/worker/back/models/operator.json b/modules/worker/back/models/operator.json new file mode 100644 index 000000000..db8a8c451 --- /dev/null +++ b/modules/worker/back/models/operator.json @@ -0,0 +1,44 @@ +{ + "name": "Operator", + "base": "VnModel", + "options": { + "mysql": { + "table": "operator" + } + }, + "properties": { + "workerFk": { + "id": true, + "type": "number", + "required": true + }, + "numberOfWagons": { + "type": "number" + }, + "trainFk": { + "type": "number", + "required": true + }, + "itemPackingTypeFk": { + "type": "string", + "required": true + }, + "warehouseFk": { + "type": "number", + "required": true + }, + "sectorFk ": { + "type": "number" + }, + "labelerFk ": { + "type": "number" + } + }, + "relations": { + "sector": { + "type": "belongsTo", + "model": "Sector", + "foreignKey": "sectorFk" + } + } +} \ No newline at end of file From 9e42ab52ce9e41fae68b8d53bf25ffc17b04d00d Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 17 Mar 2023 09:32:20 +0100 Subject: [PATCH 30/71] =?UTF-8?q?refs=20#5425=20modificaci=C3=B3n=20usuari?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/helpers/selectors.js | 2 +- modules/entry/front/latest-buys/index.html | 2 +- modules/item/front/basic-data/index.html | 2 +- modules/item/front/index/index.html | 2 +- modules/item/front/locale/es.yml | 2 +- modules/item/front/summary/index.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index d4c68ff00..f20d75310 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -410,7 +410,7 @@ export default { advancedSearchButton: 'vn-item-search-panel button[type=submit]', advancedSmartTableButton: 'vn-item-index vn-button[icon="search"]', advancedSmartTableGrouping: 'vn-item-index vn-textfield[name=grouping]', - weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight per unit"]', + weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight/Piece"]', saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button' }, itemFixedPrice: { diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index 0fe2de94d..727b19220 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -63,7 +63,7 @@ Origin - Weight per unit + Weight/Piece Active diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index 5e6752aea..974aa37d8 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -124,7 +124,7 @@ diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 47e71c2df..6f5cce7c0 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -46,7 +46,7 @@ Buyer - Weight per unit + Weight/Piece Multiplier diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 115a69528..37f774e4e 100644 --- a/modules/item/front/locale/es.yml +++ b/modules/item/front/locale/es.yml @@ -40,7 +40,7 @@ Create: Crear Client card: Ficha del cliente Shipped: F. envío stems: Tallos -Weight per unit: Peso por unidad (gramos) +Weight/Piece: Peso (gramos)/tallo Search items by id, name or barcode: Buscar articulos por identificador, nombre o codigo de barras SalesPerson: Comercial Concept: Concepto diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index cdcc2ae49..46a2baef4 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -110,7 +110,7 @@ - Date: Fri, 17 Mar 2023 11:39:16 +0100 Subject: [PATCH 31/71] =?UTF-8?q?refs=20#5073=20adaptacion=20para=20solo?= =?UTF-8?q?=20el=20a=C3=B1o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/core/components/calendar/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/front/core/components/calendar/index.js b/front/core/components/calendar/index.js index 0e39267a7..f30dac14f 100644 --- a/front/core/components/calendar/index.js +++ b/front/core/components/calendar/index.js @@ -114,12 +114,14 @@ export default class Calendar extends FormInput { let day = date.getDate(); let wday = date.getDay(); let month = date.getMonth(); + let year = date.getFullYear(); const currentDay = Date.vnNew().getDate(); const currentMonth = Date.vnNew().getMonth(); + const currentYear = Date.vnNew().getFullYear(); let classes = { - today: day === currentDay && month === currentMonth, + today: day === currentDay && month === currentMonth && year === currentYear, weekend: wday === 6 || wday === 0, previous: month < this.month, current: month == this.month, From 78d8bbd82ababbb46c38d252ac27b6a45f84cddc Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 20 Mar 2023 10:44:44 +0100 Subject: [PATCH 32/71] refs #5423 tercer decimal en entrada --- modules/item/front/last-entries/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/front/last-entries/index.html b/modules/item/front/last-entries/index.html index 8c883d46c..609cdb7fa 100644 --- a/modules/item/front/last-entries/index.html +++ b/modules/item/front/last-entries/index.html @@ -90,7 +90,7 @@ {{::$ctrl.$t('Package')}}: {{::entry.packageValue | currency: 'EUR':3 | dashIfEmpty}}
{{::$ctrl.$t('Freight')}}: {{::entry.freightValue | currency: 'EUR':3 | dashIfEmpty}}
{{::$ctrl.$t('Comission')}}: {{::entry.comissionValue | currency: 'EUR':3 | dashIfEmpty}}"> - {{::entry.cost | currency: 'EUR':2 | dashIfEmpty}} + {{::entry.cost | currency: 'EUR':3 | dashIfEmpty}}
{{::entry.weight | dashIfEmpty}} From a670795f9d93d2074c636015f4902b8051baeb36 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 20 Mar 2023 13:22:21 +0100 Subject: [PATCH 33/71] refs #5432 mod ng-show, add tooltip and disabled --- modules/ticket/front/sale/index.html | 6 ++++-- modules/ticket/front/sale/locale/es.yml | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 8764417a8..6f0361c35 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -28,8 +28,10 @@ + disabled="!$ctrl.hasSelectedSales()" + vn-tooltip="Select lines to see the options" + ng-click="moreOptions.show($event)"> + Date: Mon, 20 Mar 2023 13:41:32 +0100 Subject: [PATCH 34/71] refs #5432 quitar comentario --- modules/ticket/front/sale/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 6f0361c35..6fc986e8f 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -31,7 +31,6 @@ disabled="!$ctrl.hasSelectedSales()" vn-tooltip="Select lines to see the options" ng-click="moreOptions.show($event)"> - Date: Mon, 20 Mar 2023 23:09:17 +0100 Subject: [PATCH 35/71] refactor(getTransactions): lilium customer transactions --- .vscode/settings.json | 7 ++- .../back/methods/client/getTransactions.js | 55 +++++++++++++++---- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 82815d588..05d23f3bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,10 @@ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, - "search.useIgnoreFiles": false + "search.useIgnoreFiles": false, + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "eslint.format.enable": true, + "[javascript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + } } diff --git a/modules/client/back/methods/client/getTransactions.js b/modules/client/back/methods/client/getTransactions.js index 45183bbdc..4116f3ee1 100644 --- a/modules/client/back/methods/client/getTransactions.js +++ b/modules/client/back/methods/client/getTransactions.js @@ -1,43 +1,78 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { - Self.remoteMethod('getTransactions', { - description: 'Returns last entries', + Self.remoteMethodCtx('transactions', { + description: 'Returns customer transactions', accessType: 'READ', - accepts: [{ - arg: 'filter', - type: 'object', - description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} - }], + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, + { + arg: 'orderFk', + type: 'number', + http: {source: 'query'} + }, + { + arg: 'clientFk', + type: 'number', + http: {source: 'query'} + }, + { + arg: 'amount', + type: 'number', + http: {source: 'query'} + } + ], returns: { type: ['object'], root: true }, http: { - path: `/getTransactions`, + path: `/transactions`, verb: 'GET' } }); - Self.getTransactions = async(filter, options) => { + Self.transactions = async(ctx, filter, options) => { + const args = ctx.args; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const where = buildFilter(args, (param, value) => { + switch (param) { + case 'orderFk': + return {'t.id': value}; + case 'clientFk': + return {'t.clientFk': value}; + case 'amount': + return {'t.amount': (value * 100)}; + } + }); + + filter = mergeFilters(args.filter, {where}); + const conn = Self.dataSource.connector; const stmt = new ParameterizedSQL(` SELECT t.id, t.clientFk, + c.name AS customerName, t.created, t.amount / 100 amount, t.receiptFk IS NOT NULL AS isConfirmed, tt.message responseMessage, te.message errorMessage FROM hedera.tpvTransaction t + JOIN client c ON c.id = t.clientFk JOIN hedera.tpvMerchant m ON m.id = t.merchantFk LEFT JOIN hedera.tpvResponse tt ON tt.id = t.response LEFT JOIN hedera.tpvError te ON te.code = errorCode`); From 46a6a5fc631d6c83cf0a2b3124a9a1c3e05df0a3 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 08:51:30 +0100 Subject: [PATCH 36/71] refs #5203 refactor: se le pasan los argumentos directamente y se corrige la transaccion --- db/dump/fixtures.sql | 3 +- .../back/methods/supplier/newSupplier.js | 34 +++++---------- .../supplier/specs/newSupplier.spec.js | 42 +++++++++++-------- modules/supplier/front/create/index.html | 7 ++-- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c4df3e84f..2145f8429 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -299,7 +299,8 @@ INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt INSERT INTO `vn`.`payDem`(`id`, `payDem`) VALUES (1, 10), - (2, 20); + (2, 20), + (7, 0); INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`) VALUES diff --git a/modules/supplier/back/methods/supplier/newSupplier.js b/modules/supplier/back/methods/supplier/newSupplier.js index ae71380f3..c40e7214f 100644 --- a/modules/supplier/back/methods/supplier/newSupplier.js +++ b/modules/supplier/back/methods/supplier/newSupplier.js @@ -1,11 +1,10 @@ module.exports = Self => { - Self.remoteMethod('newSupplier', { + Self.remoteMethodCtx('newSupplier', { description: 'Creates a new supplier and returns it', accessType: 'WRITE', accepts: [{ - arg: 'params', - type: 'object', - http: {source: 'body'} + arg: 'name', + type: 'string' }], returns: { type: 'string', @@ -17,29 +16,18 @@ module.exports = Self => { } }); - Self.newSupplier = async params => { + Self.newSupplier = async(ctx, options) => { const models = Self.app.models; + const args = ctx.args; const myOptions = {}; - if (typeof(params) == 'string') - params = JSON.parse(params); + if (typeof options == 'object') + Object.assign(myOptions, options); - params.nickname = params.name; + delete args.ctx; + const data = {...args, ...{nickname: args.name}}; + const supplier = await models.Supplier.create(data, myOptions); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const supplier = await models.Supplier.create(params, myOptions); - - if (tx) await tx.commit(); - - return supplier; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } + return supplier; }; }; diff --git a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js index 44252e71b..d4479d00b 100644 --- a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js +++ b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js @@ -1,31 +1,39 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('Supplier newSupplier()', () => { - const newSupp = { - name: 'TestSupplier-1' - }; const administrativeId = 5; + const activeCtx = { + accessToken: {userId: administrativeId}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + const ctx = {req: activeCtx}; - it('should create a new supplier containing only the name', async() => { - pending('https://redmine.verdnatura.es/issues/5203'); - const activeCtx = { - accessToken: {userId: administrativeId}, - }; + beforeEach(() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); + }); - let result = await app.models.Supplier.newSupplier(JSON.stringify(newSupp)); + it('should create a new supplier containing only the name', async() => { + const tx = await models.Supplier.beginTransaction({}); - expect(result.name).toEqual('TestSupplier-1'); - expect(result.id).toEqual(443); + try { + const options = {transaction: tx}; + ctx.args = { + name: 'newSupplier' + }; - const createdSupplier = await app.models.Supplier.findById(result.id); + const result = await models.Supplier.newSupplier(ctx, options); - expect(createdSupplier.id).toEqual(result.id); - expect(createdSupplier.name).toEqual(result.name); - expect(createdSupplier.payDemFk).toEqual(7); - expect(createdSupplier.nickname).toEqual(result.name); + expect(result.name).toEqual('newSupplier'); + } catch (e) { + await tx.rollback(); + throw e; + } }); }); diff --git a/modules/supplier/front/create/index.html b/modules/supplier/front/create/index.html index 446a16cb6..c3efcf6ae 100644 --- a/modules/supplier/front/create/index.html +++ b/modules/supplier/front/create/index.html @@ -1,7 +1,8 @@ @@ -9,8 +10,8 @@ From 3881e435f4f9c50b8fd832193b3e9ad332fe22ab Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 21 Mar 2023 09:55:45 +0100 Subject: [PATCH 37/71] Renamed method --- .../{getTransactions.js => transactions.js} | 0 modules/client/back/models/client-methods.js | 2 +- modules/client/front/web-payment/index.html | 86 ++++++++----------- 3 files changed, 36 insertions(+), 52 deletions(-) rename modules/client/back/methods/client/{getTransactions.js => transactions.js} (100%) diff --git a/modules/client/back/methods/client/getTransactions.js b/modules/client/back/methods/client/transactions.js similarity index 100% rename from modules/client/back/methods/client/getTransactions.js rename to modules/client/back/methods/client/transactions.js diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js index 9241d80cf..fc77fc090 100644 --- a/modules/client/back/models/client-methods.js +++ b/modules/client/back/models/client-methods.js @@ -13,7 +13,7 @@ module.exports = Self => { require('../methods/client/getCard')(Self); require('../methods/client/getDebt')(Self); require('../methods/client/getMana')(Self); - require('../methods/client/getTransactions')(Self); + require('../methods/client/transactions')(Self); require('../methods/client/hasCustomerRole')(Self); require('../methods/client/isValidClient')(Self); require('../methods/client/lastActiveTickets')(Self); diff --git a/modules/client/front/web-payment/index.html b/modules/client/front/web-payment/index.html index 203d4bb60..2ecfc950b 100644 --- a/modules/client/front/web-payment/index.html +++ b/modules/client/front/web-payment/index.html @@ -1,55 +1,39 @@ - + - + - - - - State - Id - Date - Amount - - - - - - - - - - - - {{::transaction.id}} - {{::transaction.created | date:'dd/MM/yyyy HH:mm'}} - {{::transaction.amount | currency: 'EUR':2}} - - - - - - - + + + + State + Id + Date + Amount + + + + + + + + + + + + {{::transaction.id}} + {{::transaction.created | date:'dd/MM/yyyy HH:mm'}} + {{::transaction.amount | currency: 'EUR':2}} + + + + + + + \ No newline at end of file From 12a9ff599bc191bd38d6423b451ddb64ed529941 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 21 Mar 2023 10:05:27 +0100 Subject: [PATCH 38/71] Updated unit test --- .../client/specs/getTransactions.spec.js | 21 ------ .../methods/client/specs/transactions.spec.js | 66 +++++++++++++++++++ .../back/methods/client/transactions.js | 2 +- 3 files changed, 67 insertions(+), 22 deletions(-) delete mode 100644 modules/client/back/methods/client/specs/getTransactions.spec.js create mode 100644 modules/client/back/methods/client/specs/transactions.spec.js diff --git a/modules/client/back/methods/client/specs/getTransactions.spec.js b/modules/client/back/methods/client/specs/getTransactions.spec.js deleted file mode 100644 index 0387eb59a..000000000 --- a/modules/client/back/methods/client/specs/getTransactions.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -const models = require('vn-loopback/server/server').models; - -describe('Client getTransations', () => { - it('should call getTransations() method to receive a list of Web Payments from Bruce Wayne', async() => { - const tx = await models.Client.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const filter = {where: {clientFk: 1101}}; - const result = await models.Client.getTransactions(filter, options); - - expect(result[1].id).toBeTruthy(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/client/back/methods/client/specs/transactions.spec.js b/modules/client/back/methods/client/specs/transactions.spec.js new file mode 100644 index 000000000..b4af40195 --- /dev/null +++ b/modules/client/back/methods/client/specs/transactions.spec.js @@ -0,0 +1,66 @@ +const models = require('vn-loopback/server/server').models; + +describe('Client transactions', () => { + it('should call transactions() method to receive a list of Web Payments from Bruce Wayne', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {}; + const filter = {where: {clientFk: 1101}}; + const result = await models.Client.transactions(ctx, filter, options); + + expect(result[1].id).toBeTruthy(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should call transactions() method filtering by orderFk', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {args: {orderFk: 6}}; + const filter = {}; + const result = await models.Client.transactions(ctx, filter, options); + + const firstRow = result[0]; + + expect(result.length).toEqual(1); + expect(firstRow.id).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should call transactions() method filtering by amount', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {args: {amount: 40}}; + const filter = {}; + const result = await models.Client.transactions(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const transaction = result[randomIndex]; + + expect(transaction.amount).toEqual(40); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/client/back/methods/client/transactions.js b/modules/client/back/methods/client/transactions.js index 4116f3ee1..691910721 100644 --- a/modules/client/back/methods/client/transactions.js +++ b/modules/client/back/methods/client/transactions.js @@ -58,7 +58,7 @@ module.exports = Self => { } }); - filter = mergeFilters(args.filter, {where}); + filter = mergeFilters(filter, {where}); const conn = Self.dataSource.connector; const stmt = new ParameterizedSQL(` From 6d6c2cbfb3828575ff1d9349d99fc28fd8bd622c Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 21 Mar 2023 10:09:03 +0100 Subject: [PATCH 39/71] Default formatter --- .vscode/settings.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 05d23f3bb..159cecdc9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,9 +6,5 @@ "source.fixAll.eslint": true }, "search.useIgnoreFiles": false, - "editor.defaultFormatter": "dbaeumer.vscode-eslint", - "eslint.format.enable": true, - "[javascript]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" - } + "editor.defaultFormatter": "dbaeumer.vscode-eslint" } From 1198ad3b012a35cc4d265c9f5b561371fb0d3caa Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 21 Mar 2023 10:44:00 +0100 Subject: [PATCH 40/71] refs #5056 wagonType backs and test --- db/changes/231201/00-wagon.sql | 10 ++- db/dump/fixtures.sql | 7 +- .../back/methods/wagonType/createWagonType.js | 57 +++++++++++++++++ .../back/methods/wagonType/deleteWagonType.js | 43 +++++++++++++ .../back/methods/wagonType/editWagonType.js | 64 +++++++++++++++++++ .../wagonType/specs/crudWagonType.spec.js | 63 ++++++++++++++++++ modules/wagon/back/models/wagon-type.js | 5 ++ modules/wagon/back/models/wagon.json | 3 + 8 files changed, 246 insertions(+), 6 deletions(-) create mode 100644 modules/wagon/back/methods/wagonType/createWagonType.js create mode 100644 modules/wagon/back/methods/wagonType/deleteWagonType.js create mode 100644 modules/wagon/back/methods/wagonType/editWagonType.js create mode 100644 modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js create mode 100644 modules/wagon/back/models/wagon-type.js diff --git a/db/changes/231201/00-wagon.sql b/db/changes/231201/00-wagon.sql index c7725ab4f..2924fdc99 100644 --- a/db/changes/231201/00-wagon.sql +++ b/db/changes/231201/00-wagon.sql @@ -15,7 +15,7 @@ CREATE TABLE `vn`.`wagonTypeColor` ( CREATE TABLE `vn`.`wagonTypeTray` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `typeFk` int(11) unsigned, - `height` int(11) unsigned, + `height` int(11) unsigned NOT NULL, `colorFk` int(11) unsigned, PRIMARY KEY (`id`), UNIQUE KEY (`typeFk`,`height`), @@ -54,7 +54,8 @@ CREATE TABLE `vn`.`collectionWagonTicket` ( CONSTRAINT `collectionWagonTicket_tray` FOREIGN KEY (`trayFk`) REFERENCES `wagonTypeTray` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; -ALTER TABLE `vn`.`wagon` ADD `typeFk` int(11) unsigned DEFAULT NULL; +ALTER TABLE `vn`.`wagon` ADD `typeFk` int(11) unsigned NOT NULL; +ALTER TABLE `vn`.`wagon` ADD `label` int(11) unsigned NOT NULL; ALTER TABLE `vn`.`wagon` ADD CONSTRAINT `wagon_type` FOREIGN KEY (`typeFk`) REFERENCES `wagonType` (`id`) ON UPDATE CASCADE; INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) @@ -65,4 +66,7 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `pri ('WagonConfig', '*', '*', 'ALLOW', 'ROLE', 'employee'), ('CollectionWagon', '*', '*', 'ALLOW', 'ROLE', 'employee'), ('CollectionWagonTicket', '*', '*', 'ALLOW', 'ROLE', 'employee'), - ('Wagon', '*', '*', 'ALLOW', 'ROLE', 'employee'); + ('Wagon', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('WagonType', 'createWagonType', '*', 'ALLOW', 'ROLE', 'employee'), + ('WagonType', 'deleteWagonType', '*', 'ALLOW', 'ROLE', 'employee'), + ('WagonType', 'editWagonType', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 571769e8c..1c8134ca3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2838,8 +2838,9 @@ INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minH INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) VALUES - (1, 'red', '#ff0000'), - (2, 'green', '#00ff00'), - (3, 'blue', '#0000ff'); + (1, 'white', '#ffffff'), + (2, 'red', '#ff0000'), + (3, 'green', '#00ff00'), + (4, 'blue', '#0000ff'); diff --git a/modules/wagon/back/methods/wagonType/createWagonType.js b/modules/wagon/back/methods/wagonType/createWagonType.js new file mode 100644 index 000000000..fed915b28 --- /dev/null +++ b/modules/wagon/back/methods/wagonType/createWagonType.js @@ -0,0 +1,57 @@ +module.exports = Self => { + Self.remoteMethodCtx('createWagonType', { + description: 'Creates a new wagon type', + accessType: 'WRITE', + accepts: [ + { + arg: 'name', + type: 'String', + required: true + }, + { + arg: 'divisible', + type: 'boolean', + required: true + }, { + arg: 'trays', + type: 'any', + required: true + } + ], + http: { + path: `/createWagonType`, + verb: 'PATCH' + } + }); + + Self.createWagonType = async(ctx, options) => { + const args = ctx.args; + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const newWagonType = await models.WagonType.create({name: args.name, divisible: args.divisible}, myOptions); + args.trays.forEach(async tray => { + await models.WagonTypeTray.create({ + typeFk: newWagonType.id, + height: tray.position, + colorFk: tray.color.id + }, myOptions); + }); + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/wagon/back/methods/wagonType/deleteWagonType.js b/modules/wagon/back/methods/wagonType/deleteWagonType.js new file mode 100644 index 000000000..46b65e32f --- /dev/null +++ b/modules/wagon/back/methods/wagonType/deleteWagonType.js @@ -0,0 +1,43 @@ +module.exports = Self => { + Self.remoteMethodCtx('deleteWagonType', { + description: 'Deletes a wagon type', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'Number', + required: true + } + ], + http: { + path: `/deleteWagonType`, + verb: 'DELETE' + } + }); + + Self.deleteWagonType = async(ctx, options) => { + const args = ctx.args; + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + await models.Wagon.destroyAll({typeFk: args.id}, myOptions); + await models.WagonTypeTray.destroyAll({typeFk: args.id}, myOptions); + await models.WagonType.destroyAll({id: args.id}, myOptions); + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/wagon/back/methods/wagonType/editWagonType.js b/modules/wagon/back/methods/wagonType/editWagonType.js new file mode 100644 index 000000000..bd5ad1f16 --- /dev/null +++ b/modules/wagon/back/methods/wagonType/editWagonType.js @@ -0,0 +1,64 @@ +module.exports = Self => { + Self.remoteMethodCtx('editWagonType', { + description: 'Edits a new wagon type', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'String', + required: true + }, + { + arg: 'name', + type: 'String', + required: true + }, + { + arg: 'divisible', + type: 'boolean', + required: true + }, { + arg: 'trays', + type: 'any', + required: true + } + ], + http: { + path: `/editWagonType`, + verb: 'PATCH' + } + }); + + Self.editWagonType = async(ctx, options) => { + const args = ctx.args; + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const wagonType = await models.WagonType.findById(args.id, null, myOptions); + wagonType.updateAttributes({name: args.name, divisible: args.divisible}, myOptions); + models.WagonTypeTray.destroyAll({typeFk: args.id}, myOptions); + args.trays.forEach(async tray => { + await models.WagonTypeTray.create({ + typeFk: args.id, + height: tray.position, + colorFk: tray.color.id + }, myOptions); + }); + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js b/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js new file mode 100644 index 000000000..92ac61060 --- /dev/null +++ b/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js @@ -0,0 +1,63 @@ +const models = require('vn-loopback/server/server').models; + +describe('WagonType crudWagonType()', () => { + const ctx = { + args: { + name: 'Mock wagon type', + divisible: true, + trays: [{position: 0, color: {id: 1}}, + {position: 50, color: {id: 2}}, + {position: 100, color: {id: 3}}] + } + }; + + it(`should create, edit and delete a new wagon type and its trays`, async() => { + const tx = await models.WagonType.beginTransaction({}); + + try { + const options = {transaction: tx}; + + // create + await models.WagonType.createWagonType(ctx, options); + + const newWagonType = await models.WagonType.findOne({where: {name: ctx.args.name}}, options); + const newWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); + + expect(newWagonType).not.toEqual(null); + expect(newWagonType.name).toEqual(ctx.args.name); + expect(newWagonType.divisible).toEqual(ctx.args.divisible); + expect(newWagonTrays.length).toEqual(ctx.args.trays.length); + + ctx.args = { + id: newWagonType.id, + name: 'Edited wagon type', + divisible: false, + trays: [{position: 0, color: {id: 1}}] + }; + + // edit + await models.WagonType.editWagonType(ctx, options); + + const editedWagonType = await models.WagonType.findById(newWagonType.id, null, options); + const editedWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); + + expect(editedWagonType.name).toEqual(ctx.args.name); + expect(editedWagonType.divisible).toEqual(ctx.args.divisible); + expect(editedWagonTrays.length).toEqual(ctx.args.trays.length); + + // delete + await models.WagonType.deleteWagonType(ctx, options); + + const deletedWagonType = await models.WagonType.findById(newWagonType.id, null, options); + const deletedWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); + + expect(deletedWagonType).toEqual(null); + expect(deletedWagonTrays).toEqual([]); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/wagon/back/models/wagon-type.js b/modules/wagon/back/models/wagon-type.js new file mode 100644 index 000000000..bebf7a9d9 --- /dev/null +++ b/modules/wagon/back/models/wagon-type.js @@ -0,0 +1,5 @@ +module.exports = Self => { + require('../methods/wagonType/createWagonType')(Self); + require('../methods/wagonType/editWagonType')(Self); + require('../methods/wagonType/deleteWagonType')(Self); +}; diff --git a/modules/wagon/back/models/wagon.json b/modules/wagon/back/models/wagon.json index 81b9f23e6..61ee61e61 100644 --- a/modules/wagon/back/models/wagon.json +++ b/modules/wagon/back/models/wagon.json @@ -11,6 +11,9 @@ "id": true, "type": "number" }, + "label": { + "type": "number" + }, "volume": { "type": "number" }, From d1f0ae386540126412fa75148e9a644e3638bb3f Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 11:26:25 +0100 Subject: [PATCH 41/71] refs #4858 fix: filtro corregido --- back/methods/chat/sendCheckingPresence.js | 3 +++ back/methods/chat/sendQueued.js | 19 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 3eaf6b86b..29232490a 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -38,6 +38,9 @@ module.exports = Self => { if (!recipient) throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); + if (process.env.NODE_ENV == 'test') + message = `[Test:Environment to user ${userId}] ` + message; + const chat = await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index 8a0bdee34..ef1a417ab 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -19,12 +19,11 @@ module.exports = Self => { const chats = await models.Chat.find({ where: { status: { - neq: { - and: [ - 'sent', - 'sending' - ] - } + nin: [ + 'sent', + 'sending' + ] + }, attempts: {lt: 3} } @@ -34,16 +33,16 @@ module.exports = Self => { if (chat.checkUserStatus) { try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, 'sent'); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error); + await Self.updateChat(chat, 'error', error); } } else { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, 'sent'); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error); + await Self.updateChat(chat, 'error', error); } } } From 4141a9735600521fc172539aa8d2b1c266249701 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 11:37:26 +0100 Subject: [PATCH 42/71] refs #4858 fix: backTest --- back/methods/chat/spec/sendQueued.spec.js | 4 ++-- db/changes/{230201 => 231201}/00-chatRefactor.sql | 0 db/dump/fixtures.sql | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename db/changes/{230201 => 231201}/00-chatRefactor.sql (100%) 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/230201/00-chatRefactor.sql b/db/changes/231201/00-chatRefactor.sql similarity index 100% rename from db/changes/230201/00-chatRefactor.sql rename to db/changes/231201/00-chatRefactor.sql diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 2145f8429..e6e998d59 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2631,8 +2631,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`) From 1d0024c5382e5512613bae9d93388527f255fb87 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 14:08:34 +0100 Subject: [PATCH 43/71] =?UTF-8?q?refs=20#5013=20feat:=20a=C3=B1adida=20obs?= =?UTF-8?q?ervacion=20para=20cada=20ticket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/231201/00-observationType.sql | 2 ++ print/templates/reports/invoice/invoice.html | 11 +++++++++++ print/templates/reports/invoice/sql/tickets.sql | 9 ++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/changes/231201/00-observationType.sql diff --git a/db/changes/231201/00-observationType.sql b/db/changes/231201/00-observationType.sql new file mode 100644 index 000000000..20e3608e4 --- /dev/null +++ b/db/changes/231201/00-observationType.sql @@ -0,0 +1,2 @@ +INSERT INTO `vn`.`observationType` (`description`, `code`, `hasNewBornMessage`) +VALUES ('Factura', 'invocieOut', '0'); diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index 2d180878a..2c37126fc 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -119,6 +119,16 @@ {{ticketSubtotal(ticket) | currency('EUR', $i18n.locale)}} + +
+
+
{{$t('observations')}}
+
+
{{ticket.description}}
+
+
+
+
@@ -251,6 +261,7 @@ +