diff --git a/back/methods/chat/getServiceAuth.js b/back/methods/chat/getServiceAuth.js new file mode 100644 index 000000000..827092109 --- /dev/null +++ b/back/methods/chat/getServiceAuth.js @@ -0,0 +1,55 @@ +const axios = require('axios'); +const tokenLifespan = 10; +module.exports = Self => { + Self.remoteMethodCtx('getServiceAuth', { + description: 'Authenticates with the service and request a new token', + accessType: 'READ', + accepts: [], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getServiceAuth`, + verb: 'GET' + } + }); + + Self.getServiceAuth = async() => { + if (!this.login) + this.login = await requestToken(); + + if (!this.login) return; + + if (Date.now() > this.login.expires) + this.login = await requestToken(); + + return this.login; + }; + + /** + * Requests a new Rocketchat token + */ + async function requestToken() { + const models = Self.app.models; + const chatConfig = await models.ChatConfig.findOne(); + + const {data} = await axios.post(`${chatConfig.api}/login`, { + user: chatConfig.user, + password: chatConfig.password + }); + + const requestData = data.data; + if (requestData) { + return { + host: chatConfig.host, + api: chatConfig.api, + auth: { + userId: requestData.userId, + token: requestData.authToken + }, + expires: Date.now() + (1000 * 60 * tokenLifespan) + }; + } + } +}; diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index 209dfb035..67e0dbb87 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -1,4 +1,4 @@ -const got = require('got'); +const axios = require('axios'); module.exports = Self => { Self.remoteMethodCtx('send', { description: 'Send a RocketChat message', @@ -30,122 +30,35 @@ module.exports = Self => { const sender = await models.Account.findById(accessToken.userId); const recipient = to.replace('@', ''); - if (sender.name != recipient) { - let {body} = await sendMessage(sender, to, message); - if (body) - body = JSON.parse(body); - else - body = false; - - return body; - } - - return false; + if (sender.name != recipient) + return sendMessage(sender, to, message); }; async function sendMessage(sender, channel, message) { - const config = await getConfig(); - const avatar = `${config.host}/avatar/${sender.name}`; - const uri = `${config.api}/chat.postMessage`; - - return sendAuth(uri, { - 'channel': channel, - 'avatar': avatar, - 'alias': sender.nickname, - 'text': message - }).catch(async error => { - if (error.statusCode === 401) { - this.auth = null; - - return sendMessage(sender, channel, message); - } - - throw new Error(error.message); - }); - } - - /** - * Returns a rocketchat token - * @return {Object} userId and authToken - */ - async function getAuthToken() { - if (!this.auth || this.auth && !this.auth.authToken) { - const config = await getConfig(); - const uri = `${config.api}/login`; - let {body} = await send(uri, { - user: config.user, - password: config.password - }); - - if (body) { - body = JSON.parse(body); - this.auth = body.data; - } - } - - return this.auth; - } - - /** - * Returns a rocketchat config - * @return {Object} Auth config - */ - async function getConfig() { - if (!this.chatConfig) { - const models = Self.app.models; - - this.chatConfig = await models.ChatConfig.findOne(); - } - - return this.chatConfig; - } - - /** - * Send unauthenticated request - * @param {*} uri - Request uri - * @param {*} params - Request params - * @param {*} options - Request options - * - * @return {Object} Request response - */ - async function send(uri, params, options = {}) { if (process.env.NODE_ENV !== 'production') { return new Promise(resolve => { return resolve({ - body: JSON.stringify( - {statusCode: 200, message: 'Fake notification sent'} - ) + statusCode: 200, + message: 'Fake notification sent' }); }); } - const defaultOptions = { - form: params - }; + const login = await Self.getServiceAuth(); + const avatar = `${login.host}/avatar/${sender.name}`; - if (options) Object.assign(defaultOptions, options); - - return got.post(uri, defaultOptions); - } - - /** - * Send authenticated request - * @param {*} uri - Request uri - * @param {*} body - Request params - * - * @return {Object} Request response - */ - async function sendAuth(uri, body) { - const login = await getAuthToken(); const options = { - headers: {} + headers: { + 'X-Auth-Token': login.auth.token, + 'X-User-Id': login.auth.userId + }, }; - if (login) { - options.headers['X-Auth-Token'] = login.authToken; - options.headers['X-User-Id'] = login.userId; - } - - return send(uri, body, options); + return axios.post(`${login.api}/chat.postMessage`, { + 'channel': channel, + 'avatar': avatar, + 'alias': sender.nickname, + 'text': message + }, options); } }; diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index fcde20130..429ecdab0 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -1,21 +1,23 @@ +const axios = require('axios'); + module.exports = Self => { Self.remoteMethodCtx('sendCheckingPresence', { - description: 'Sends a RocketChat message to a working worker or department channel', + description: 'Sends a RocketChat message to a connected user or department channel', accessType: 'WRITE', accepts: [{ - arg: 'workerId', - type: 'Number', + arg: 'recipientId', + type: 'number', required: true, - description: 'The worker id of the destinatary' + description: 'The recipient user id' }, { arg: 'message', - type: 'String', + type: 'string', required: true, description: 'The message' }], returns: { - type: 'Object', + type: 'object', root: true }, http: { @@ -33,30 +35,61 @@ module.exports = Self => { Object.assign(myOptions, options); const models = Self.app.models; - const account = await models.Account.findById(recipientId, null, myOptions); const userId = ctx.req.accessToken.userId; + const recipient = await models.Account.findById(recipientId, null, myOptions); + // Prevent sending messages to yourself if (recipientId == userId) return false; - if (!account) + if (!recipient) throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); - const query = `SELECT worker_isWorking(?) isWorking`; - const [result] = await Self.rawSql(query, [recipientId], myOptions); + const {data} = await Self.getUserStatus(recipient.name); + if (data) { + if (data.status === 'offline') { + // Send message to department room + const workerDepartment = await models.WorkerDepartment.findById(recipientId, { + include: { + relation: 'department' + } + }, myOptions); + const department = workerDepartment && workerDepartment.department(); + const channelName = department && department.chatName; - if (!result.isWorking) { - const workerDepartment = await models.WorkerDepartment.findById(recipientId, { - include: { - relation: 'department' - } - }, myOptions); - const department = workerDepartment && workerDepartment.department(); - const channelName = department && department.chatName; + if (channelName) + return Self.send(ctx, `#${channelName}`, `@${recipient.name} ➔ ${message}`); + } else + return Self.send(ctx, `@${recipient.name}`, message); + } + }; - if (channelName) - return Self.send(ctx, `#${channelName}`, `@${account.name} ➔ ${message}`); + /** + * Returns the current user status on Rocketchat + * + * @param {string} username - The recipient user name + * @return {Promise} - The request promise + */ + Self.getUserStatus = async function getUserStatus(username) { + if (process.env.NODE_ENV !== 'production') { + return new Promise(resolve => { + return resolve({ + data: { + status: 'online' + } + }); + }); } - return Self.send(ctx, `@${account.name}`, message); + const login = await Self.getServiceAuth(); + + const options = { + params: {username}, + headers: { + 'X-Auth-Token': login.auth.token, + 'X-User-Id': login.auth.userId + }, + }; + + return axios.get(`${login.api}/users.getStatus`, options); }; }; diff --git a/back/methods/chat/spec/sendCheckingPresence.spec.js b/back/methods/chat/spec/sendCheckingPresence.spec.js index e9c61fd21..2c48ef02c 100644 --- a/back/methods/chat/spec/sendCheckingPresence.spec.js +++ b/back/methods/chat/spec/sendCheckingPresence.spec.js @@ -1,46 +1,62 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('Chat sendCheckingPresence()', () => { const today = new Date(); today.setHours(6, 0); const ctx = {req: {accessToken: {userId: 1}}}; - const chatModel = app.models.Chat; + const chatModel = models.Chat; const departmentId = 23; const workerId = 1107; - it(`should call send() method with the worker name if he's currently working then return a response`, async() => { + it(`should call to send() method with "@HankPym" as recipient argument`, async() => { spyOn(chatModel, 'send').and.callThrough(); - - const timeEntry = await app.models.WorkerTimeControl.create({ - userFk: workerId, - timed: today, - manual: false, - direction: 'in' - }); + spyOn(chatModel, 'getUserStatus').and.returnValue( + new Promise(resolve => { + return resolve({ + data: { + status: 'online' + } + }); + }) + ); const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something'); expect(response.statusCode).toEqual(200); expect(response.message).toEqual('Fake notification sent'); expect(chatModel.send).toHaveBeenCalledWith(ctx, '@HankPym', 'I changed something'); - - // restores - await app.models.WorkerTimeControl.destroyById(timeEntry.id); }); - it(`should call to send() method with the worker department channel if he's not currently working then return a response`, async() => { + it(`should call to send() method with "#cooler" as recipient argument`, async() => { spyOn(chatModel, 'send').and.callThrough(); + spyOn(chatModel, 'getUserStatus').and.returnValue( + new Promise(resolve => { + return resolve({ + data: { + status: 'offline' + } + }); + }) + ); - const department = await app.models.Department.findById(departmentId); - await department.updateAttribute('chatName', 'cooler'); + const tx = await models.Claim.beginTransaction({}); - const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something'); + try { + const options = {transaction: tx}; - expect(response.statusCode).toEqual(200); - expect(response.message).toEqual('Fake notification sent'); - expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something'); + const department = await models.Department.findById(departmentId, null, options); + await department.updateAttribute('chatName', 'cooler'); - // restores - await department.updateAttribute('chatName', null); + const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something'); + + expect(response.statusCode).toEqual(200); + expect(response.message).toEqual('Fake notification sent'); + expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); }); diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js new file mode 100644 index 000000000..c6712bb65 --- /dev/null +++ b/back/methods/docuware/checkFile.js @@ -0,0 +1,93 @@ +const got = require('got'); + +module.exports = Self => { + Self.remoteMethodCtx('checkFile', { + description: 'Check if exist docuware file', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + description: 'The id', + http: {source: 'path'} + }, + { + arg: 'fileCabinet', + type: 'string', + required: true, + description: 'The fileCabinet name' + }, + { + arg: 'dialog', + type: 'string', + required: true, + description: 'The dialog name' + } + ], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/:id/checkFile`, + verb: 'POST' + } + }); + + Self.checkFile = async function(ctx, id, fileCabinet, dialog) { + const myUserId = ctx.req.accessToken.userId; + if (!myUserId) + return false; + + const models = Self.app.models; + const docuwareConfig = await models.DocuwareConfig.findOne(); + const docuwareInfo = await models.Docuware.findOne({ + where: { + code: fileCabinet, + dialogName: dialog + } + }); + + const docuwareUrl = docuwareConfig.url; + const cookie = docuwareConfig.token; + const fileCabinetName = docuwareInfo.fileCabinetName; + const find = docuwareInfo.find; + const options = { + 'headers': { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Cookie': cookie + } + }; + const searchFilter = { + condition: [ + { + DBName: find, + Value: [id] + } + ] + }; + + try { + // get fileCabinetId + const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options); + const fileCabinetJson = JSON.parse(fileCabinetResponse.body).FileCabinet; + const fileCabinetId = fileCabinetJson.find(dialogs => dialogs.Name === fileCabinetName).Id; + + // get dialog + const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options); + const dialogJson = JSON.parse(dialogResponse.body).Dialog; + const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id; + + // get docuwareID + Object.assign(options, {'body': JSON.stringify(searchFilter)}); + const response = await got.post( + `${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, options); + JSON.parse(response.body).Items[0].Id; + + return true; + } catch (error) { + return false; + } + }; +}; diff --git a/back/methods/docuware/download.js b/back/methods/docuware/download.js new file mode 100644 index 000000000..489a07e34 --- /dev/null +++ b/back/methods/docuware/download.js @@ -0,0 +1,120 @@ +/* eslint max-len: ["error", { "code": 180 }]*/ +const got = require('got'); +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('download', { + description: 'Download an docuware PDF', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + description: 'The id', + http: {source: 'path'} + }, + { + arg: 'fileCabinet', + type: 'string', + description: 'The id', + http: {source: 'path'} + }, + { + arg: 'dialog', + type: 'string', + description: 'The id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'string', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'string', + http: {target: 'header'} + } + ], + http: { + path: `/:id/download/:fileCabinet/:dialog`, + verb: 'GET' + } + }); + + Self.download = async function(ctx, id, fileCabinet, dialog) { + const myUserId = ctx.req.accessToken.userId; + if (!myUserId) + throw new UserError(`You don't have enough privileges`); + + const models = Self.app.models; + const docuwareConfig = await models.DocuwareConfig.findOne(); + const docuwareInfo = await models.Docuware.findOne({ + where: { + code: fileCabinet, + dialogName: dialog + } + }); + + const docuwareUrl = docuwareConfig.url; + const cookie = docuwareConfig.token; + const fileCabinetName = docuwareInfo.fileCabinetName; + const find = docuwareInfo.find; + const options = { + 'headers': { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Cookie': cookie + } + }; + const searchFilter = { + condition: [ + { + DBName: find, + Value: [id] + } + ] + }; + + try { + // get fileCabinetId + const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options); + const fileCabinetJson = JSON.parse(fileCabinetResponse.body).FileCabinet; + const fileCabinetId = fileCabinetJson.find(dialogs => dialogs.Name === fileCabinetName).Id; + + // get dialog + const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options); + const dialogJson = JSON.parse(dialogResponse.body).Dialog; + const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id; + + // get docuwareID + Object.assign(options, {'body': JSON.stringify(searchFilter)}); + const response = await got.post(`${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, options); + const docuwareId = JSON.parse(response.body).Items[0].Id; + + // download & save file + const fileName = `filename="${id}.pdf"`; + const contentType = 'application/pdf'; + const downloadUri = `${docuwareUrl}/FileCabinets/${fileCabinetId}/Documents/${docuwareId}/FileDownload?targetFileType=Auto&keepAnnotations=false`; + const downloadOptions = { + 'headers': { + 'Cookie': cookie + } + }; + + const stream = got.stream(downloadUri, downloadOptions); + + return [stream, contentType, fileName]; + } catch (error) { + if (error.code === 'ENOENT') + throw new UserError('The DOCUWARE PDF document does not exists'); + + throw error; + } + }; +}; diff --git a/back/methods/docuware/specs/checkFile.spec.js b/back/methods/docuware/specs/checkFile.spec.js new file mode 100644 index 000000000..2ebde0df4 --- /dev/null +++ b/back/methods/docuware/specs/checkFile.spec.js @@ -0,0 +1,64 @@ +const models = require('vn-loopback/server/server').models; +const got = require('got'); + +describe('docuware download()', () => { + const ticketId = 1; + const userId = 9; + const ctx = { + req: { + + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + } + }; + + const fileCabinetName = 'deliveryClientTest'; + const dialogDisplayName = 'find'; + const dialogName = 'findTest'; + + const gotGetResponse = { + body: JSON.stringify( + { + FileCabinet: [ + {Id: 12, Name: fileCabinetName} + ], + Dialog: [ + {Id: 34, DisplayName: dialogDisplayName} + ] + }) + }; + + it('should return exist file in docuware', async() => { + const gotPostResponse = { + body: JSON.stringify( + { + Items: [ + {Id: 56} + ], + }) + }; + + spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse))); + spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse))); + + const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName); + + expect(result).toEqual(true); + }); + + it('should return not exist file in docuware', async() => { + const gotPostResponse = { + body: JSON.stringify( + { + Items: [], + }) + }; + + spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse))); + spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse))); + + const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName); + + expect(result).toEqual(false); + }); +}); diff --git a/back/methods/docuware/specs/download.spec.js b/back/methods/docuware/specs/download.spec.js new file mode 100644 index 000000000..436063fd8 --- /dev/null +++ b/back/methods/docuware/specs/download.spec.js @@ -0,0 +1,50 @@ +const models = require('vn-loopback/server/server').models; +const got = require('got'); +const stream = require('stream'); + +describe('docuware download()', () => { + const userId = 9; + const ticketId = 1; + const ctx = { + req: { + + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + } + }; + + it('should return the downloaded file name', async() => { + const fileCabinetName = 'deliveryClientTest'; + const dialogDisplayName = 'find'; + const dialogName = 'findTest'; + const gotGetResponse = { + body: JSON.stringify( + { + FileCabinet: [ + {Id: 12, Name: fileCabinetName} + ], + Dialog: [ + {Id: 34, DisplayName: dialogDisplayName} + ] + }) + }; + + const gotPostResponse = { + body: JSON.stringify( + { + Items: [ + {Id: 56} + ], + }) + }; + + spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse))); + spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse))); + spyOn(got, 'stream').and.returnValue(new stream.PassThrough({objectMode: true})); + + const result = await models.Docuware.download(ctx, ticketId, fileCabinetName, dialogName); + + expect(result[1]).toEqual('application/pdf'); + expect(result[2]).toEqual(`filename="${ticketId}.pdf"`); + }); +}); diff --git a/back/model-config.json b/back/model-config.json index 8ad15a16a..4c79d565b 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -44,6 +44,12 @@ "DmsType": { "dataSource": "vn" }, + "Docuware": { + "dataSource": "vn" + }, + "DocuwareConfig": { + "dataSource": "vn" + }, "EmailUser": { "dataSource": "vn" }, diff --git a/back/models/chat.js b/back/models/chat.js index 5487569c1..7d8468aae 100644 --- a/back/models/chat.js +++ b/back/models/chat.js @@ -1,4 +1,5 @@ module.exports = Self => { + require('../methods/chat/getServiceAuth')(Self); require('../methods/chat/send')(Self); require('../methods/chat/sendCheckingPresence')(Self); require('../methods/chat/notifyIssues')(Self); diff --git a/back/models/docuware-config.json b/back/models/docuware-config.json new file mode 100644 index 000000000..8ca76d8ba --- /dev/null +++ b/back/models/docuware-config.json @@ -0,0 +1,32 @@ +{ + "name": "DocuwareConfig", + "description": "Docuware config", + "base": "VnModel", + "options": { + "mysql": { + "table": "docuwareConfig" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "url": { + "type": "string" + }, + "token": { + "type": "string" + } + }, + "acls": [ + { + "property": "*", + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/back/models/docuware.js b/back/models/docuware.js new file mode 100644 index 000000000..8fd8065ed --- /dev/null +++ b/back/models/docuware.js @@ -0,0 +1,4 @@ +module.exports = Self => { + require('../methods/docuware/download')(Self); + require('../methods/docuware/checkFile')(Self); +}; diff --git a/back/models/docuware.json b/back/models/docuware.json new file mode 100644 index 000000000..fb2ed919e --- /dev/null +++ b/back/models/docuware.json @@ -0,0 +1,38 @@ +{ + "name": "Docuware", + "description": "Docuware sections", + "base": "VnModel", + "options": { + "mysql": { + "table": "docuware" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "code": { + "type": "string" + }, + "fileCabinetName": { + "type": "string" + }, + "dialogName": { + "type": "string" + }, + "find": { + "type": "string" + } + }, + "acls": [ + { + "property": "*", + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/db/changes/10420-valentines/00-aclDocuware.sql b/db/changes/10420-valentines/00-aclDocuware.sql new file mode 100644 index 000000000..21ed66c4c --- /dev/null +++ b/db/changes/10420-valentines/00-aclDocuware.sql @@ -0,0 +1,3 @@ +INSERT INTO salix.ACL +(model, property, accessType, permission, principalType, principalId) +VALUES('Docuware', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10420-valentines/00-docuware.sql b/db/changes/10420-valentines/00-docuware.sql new file mode 100644 index 000000000..7cabd135f --- /dev/null +++ b/db/changes/10420-valentines/00-docuware.sql @@ -0,0 +1,11 @@ +CREATE TABLE `vn`.`docuware` ( + `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `code` varchar(50) NULL, + `fileCabinetName` varchar(50) NULL, + `dialogName` varchar(255) DEFAULT NULL, + `find` varchar(50) DEFAULT NULL +); + +INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`) + VALUES + ('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N'); \ No newline at end of file diff --git a/db/changes/10420-valentines/00-docuwareConfig.sql b/db/changes/10420-valentines/00-docuwareConfig.sql new file mode 100644 index 000000000..1ba19af6d --- /dev/null +++ b/db/changes/10420-valentines/00-docuwareConfig.sql @@ -0,0 +1,9 @@ +CREATE TABLE `vn`.`docuwareConfig` ( + `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `url` varchar(75) NULL, + `token` varchar(1000) DEFAULT NULL +); + +INSERT INTO `vn`.`docuwareConfig` (`url`) + VALUES + ('https://verdnatura.docuware.cloud/docuware/platform'); \ No newline at end of file diff --git a/db/changes/10411-january/00-ticket_getMovable.sql b/db/changes/10420-valentines/00-ticket_getMovable.sql similarity index 77% rename from db/changes/10411-january/00-ticket_getMovable.sql rename to db/changes/10420-valentines/00-ticket_getMovable.sql index 5f5b0a93a..eb5c722c4 100644 --- a/db/changes/10411-january/00-ticket_getMovable.sql +++ b/db/changes/10420-valentines/00-ticket_getMovable.sql @@ -6,20 +6,23 @@ CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticket_getMovable`(vTicketFk INT, vDat BEGIN /** * Cálcula el stock movible para los artículos de un ticket + * vDatedNew debe ser menor que vDatedOld, en los otros casos se + * asume que siempre es posible * * @param vTicketFk -> Ticket * @param vDatedNew -> Nueva fecha * @return Sales con Movible */ DECLARE vDatedOld DATETIME; - + SET vDatedNew = DATE_ADD(vDatedNew, INTERVAL 1 DAY); + SELECT t.shipped INTO vDatedOld FROM ticket t WHERE t.id = vTicketFk; - CALL itemStock(vWarehouseFk, DATE_SUB(vDatedNew, INTERVAL 1 DAY), NULL); - CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(vDatedOld, vDatedNew), NULL); - + CALL itemStock(vWarehouseFk, vDatedNew, NULL); + CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(DATE_SUB(vDatedOld, INTERVAL 1 DAY), vDatedNew), NULL); + SELECT s.id, s.itemFk, s.quantity, diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 07eaf23fd..20298677a 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2443,3 +2443,11 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1103, 500, CURDATE(), CURDATE()), (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); + +INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`) + VALUES + ('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word'); + +INSERT INTO `vn`.`docuwareConfig` (`url`) + VALUES + ('https://verdnatura.docuware.cloud/docuware/platform'); \ No newline at end of file diff --git a/modules/account/back/models/role-config.js b/modules/account/back/models/role-config.js index c6b32a4c5..6051f2060 100644 --- a/modules/account/back/models/role-config.js +++ b/modules/account/back/models/role-config.js @@ -1,6 +1,10 @@ module.exports = Self => { Self.getSynchronizer = async function() { + let NODE_ENV = process.env.NODE_ENV; + if (!NODE_ENV || NODE_ENV == 'development') + return null; + return await Self.findOne({ fields: ['id', 'rolePrefix', 'userPrefix', 'userHost'] }); diff --git a/modules/claim/back/methods/claim/specs/createFromSales.spec.js b/modules/claim/back/methods/claim/specs/createFromSales.spec.js index 097dcc0d9..9151c361e 100644 --- a/modules/claim/back/methods/claim/specs/createFromSales.spec.js +++ b/modules/claim/back/methods/claim/specs/createFromSales.spec.js @@ -57,7 +57,7 @@ describe('Claim createFromSales()', () => { const todayMinusEightDays = new Date(); todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8); - const ticket = await models.Ticket.findById(ticketId, options); + const ticket = await models.Ticket.findById(ticketId, null, options); await ticket.updateAttribute('landed', todayMinusEightDays, options); const claim = await models.Claim.createFromSales(ctx, ticketId, newSale, options); @@ -88,7 +88,7 @@ describe('Claim createFromSales()', () => { const todayMinusEightDays = new Date(); todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8); - const ticket = await models.Ticket.findById(ticketId, options); + const ticket = await models.Ticket.findById(ticketId, null, options); await ticket.updateAttribute('landed', todayMinusEightDays, options); await models.Claim.createFromSales(ctx, ticketId, newSale, options); diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js index 121d427ce..54fe802e3 100644 --- a/modules/client/back/methods/client/specs/sendSms.spec.js +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -1,7 +1,8 @@ const models = require('vn-loopback/server/server').models; const soap = require('soap'); -describe('client sendSms()', () => { +// #3673 sendSms tests excluded +xdescribe('client sendSms()', () => { it('should now send a message and log it', async() => { spyOn(soap, 'createClientAsync').and.returnValue('a so fake client'); const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/updateFiscalData.spec.js b/modules/client/back/methods/client/specs/updateFiscalData.spec.js index 75273a39f..7c0bc0599 100644 --- a/modules/client/back/methods/client/specs/updateFiscalData.spec.js +++ b/modules/client/back/methods/client/specs/updateFiscalData.spec.js @@ -35,7 +35,7 @@ describe('Client updateFiscalData', () => { try { const options = {transaction: tx}; - const client = await models.Client.findById(clientId, options); + const client = await models.Client.findById(clientId, null, options); await client.updateAttribute('isTaxDataChecked', false, options); const ctx = {req: {accessToken: {userId: salesAssistantId}}}; diff --git a/modules/client/back/methods/sms/send.spec.js b/modules/client/back/methods/sms/send.spec.js index 7ca78b214..a81c24e96 100644 --- a/modules/client/back/methods/sms/send.spec.js +++ b/modules/client/back/methods/sms/send.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); -describe('sms send()', () => { +// #3673 sendSms tests excluded +xdescribe('sms send()', () => { it('should not return status error', async() => { const ctx = {req: {accessToken: {userId: 1}}}; const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body'); diff --git a/modules/invoiceOut/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html index 3b30f891c..859486ab1 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.html +++ b/modules/invoiceOut/front/descriptor-menu/index.html @@ -10,7 +10,6 @@ name="showInvoicePdf" translate> Show invoice... - Send invoice... - - - -
- -
{{detail.buyer}}
-
+
+ +
{{detail.buyer}}
+ + + + +
+ @@ -21,7 +29,7 @@
+ ui-sref="item.waste.detail({buyer: waste.buyer, family: waste.family})"> {{::waste.family}} {{::(waste.percentage / 100) | percentage: 2}} {{::waste.dwindle | currency: 'EUR'}} @@ -29,6 +37,6 @@ -
- - + +
+ \ No newline at end of file diff --git a/modules/item/front/waste/index/index.js b/modules/item/front/waste/index/index.js index 15e6b063f..b11f54b08 100644 --- a/modules/item/front/waste/index/index.js +++ b/modules/item/front/waste/index/index.js @@ -2,7 +2,34 @@ import ngModule from '../../module'; import Section from 'salix/components/section'; import './style.scss'; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.getWasteConfig(); + } + + getWasteConfig() { + return this.wasteConfig = JSON.parse(localStorage.getItem('wasteConfig')) || {}; + } + + setWasteConfig() { + localStorage.setItem('wasteConfig', JSON.stringify(this.wasteConfig)); + } + + toggleHidePanel(detail) { + if (!this.wasteConfig[detail.buyer]) { + this.wasteConfig[detail.buyer] = { + hidden: true + }; + } else + this.wasteConfig[detail.buyer].hidden = !this.wasteConfig[detail.buyer].hidden; + + this.setWasteConfig(); + } +} + ngModule.vnComponent('vnItemWasteIndex', { template: require('./index.html'), - controller: Section + controller: Controller }); diff --git a/modules/item/front/waste/index/index.spec.js b/modules/item/front/waste/index/index.spec.js new file mode 100644 index 000000000..fd7332f68 --- /dev/null +++ b/modules/item/front/waste/index/index.spec.js @@ -0,0 +1,53 @@ +import './index.js'; +import crudModel from 'core/mocks/crud-model'; + +describe('Item', () => { + describe('Component vnItemWasteIndex', () => { + let $scope; + let controller; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + const $element = angular.element(''); + controller = $componentController('vnItemWasteIndex', {$element, $scope}); + })); + + describe('getWasteConfig / setWasteConfig', () => { + it('should return the local storage wasteConfig', () => { + const result = controller.getWasteConfig(); + + expect(result).toEqual({}); + }); + + it('should set and return the local storage wasteConfig', () => { + controller.wasteConfig = {salesPerson: {hidden: true}}; + controller.setWasteConfig(); + + const result = controller.getWasteConfig(); + + expect(result).toEqual(controller.wasteConfig); + }); + }); + + describe('toggleHidePanel()', () => { + it('should make details hidden by default', () => { + controller.wasteConfig = {}; + + controller.toggleHidePanel({buyer: 'salesPerson'}); + + expect(controller.wasteConfig.salesPerson.hidden).toEqual(true); + }); + + it('should toggle hidden false', () => { + controller.wasteConfig = {salesPerson: {hidden: true}}; + + controller.toggleHidePanel({buyer: 'salesPerson'}); + + expect(controller.wasteConfig.salesPerson.hidden).toEqual(false); + }); + }); + }); +}); diff --git a/modules/item/front/waste/index/style.scss b/modules/item/front/waste/index/style.scss index faac46139..8b44cb6f1 100644 --- a/modules/item/front/waste/index/style.scss +++ b/modules/item/front/waste/index/style.scss @@ -1,21 +1,24 @@ @import "variables"; +@import "effects"; vn-item-waste-index, vn-item-waste-detail { .header { - margin-bottom: 16px; - text-transform: uppercase; - font-size: 1.25rem; - line-height: 1; - padding: 7px; - padding-bottom: 7px; - padding-bottom: 4px; - font-weight: lighter; - background-color: $color-bg; - border-bottom: 1px solid #f7931e; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; + padding: 12px 0 5px 0; + color: gray; + font-size: 1.2rem; + border-bottom: $border; + margin-bottom: 10px; + + & > vn-none > vn-icon { + @extend %clickable-light; + color: $color-button; + font-size: 1.4rem; + } + + vn-none > .arrow { + transition: transform 200ms; + } } vn-table vn-th.waste-family, @@ -23,4 +26,12 @@ vn-item-waste-detail { max-width: 64px; width: 64px } + .hidden { + display: none; + + } + .header > vn-none > .arrow.hidden { + display: block; + transform: rotate(180deg); + } } \ No newline at end of file diff --git a/modules/item/front/waste/locale/es.yml b/modules/item/front/waste/locale/es.yml index 9f08e3a72..b9cd33dec 100644 --- a/modules/item/front/waste/locale/es.yml +++ b/modules/item/front/waste/locale/es.yml @@ -1,3 +1,4 @@ Family: Familia Percentage: Porcentaje -Dwindle: Mermas \ No newline at end of file +Dwindle: Mermas +Minimize/Maximize: Minimizar/Maximizar \ No newline at end of file diff --git a/modules/route/back/methods/route/getSuggestedTickets.js b/modules/route/back/methods/route/getSuggestedTickets.js index c1d6b67fe..f0333e66b 100644 --- a/modules/route/back/methods/route/getSuggestedTickets.js +++ b/modules/route/back/methods/route/getSuggestedTickets.js @@ -25,6 +25,7 @@ module.exports = Self => { Object.assign(myOptions, options); const route = await Self.app.models.Route.findById(id, null, myOptions); + const zoneAgencyModes = await Self.app.models.ZoneAgencyMode.find({ where: { agencyModeFk: route.agencyModeFk @@ -52,6 +53,12 @@ module.exports = Self => { fields: ['id', 'name'] } }, + { + relation: 'zone', + scope: { + fields: ['id', 'name'] + } + }, { relation: 'address', scope: { diff --git a/modules/route/back/methods/route/specs/unlink.spec.js b/modules/route/back/methods/route/specs/unlink.spec.js new file mode 100644 index 000000000..808cedccc --- /dev/null +++ b/modules/route/back/methods/route/specs/unlink.spec.js @@ -0,0 +1,33 @@ +const models = require('vn-loopback/server/server').models; + +describe('route unlink()', () => { + it('should show no tickets since the link between zone and route for the give agencymode was removed', async() => { + const tx = await models.ZoneAgencyMode.beginTransaction({}); + const agencyModeId = 1; + const zoneId = 1; + routeId = 1; + + try { + const options = {transaction: tx}; + + let zoneAgencyModes = await models.ZoneAgencyMode.find(null, options); + let tickets = await models.Route.getSuggestedTickets(routeId, options); + + expect(zoneAgencyModes.length).toEqual(4); + expect(tickets.length).toEqual(3); + + await models.Route.unlink(agencyModeId, zoneId, options); + + zoneAgencyModes = await models.ZoneAgencyMode.find(null, options); + tickets = await models.Route.getSuggestedTickets(routeId, options); + + expect(zoneAgencyModes.length).toEqual(3); + expect(tickets.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/route/back/methods/route/unlink.js b/modules/route/back/methods/route/unlink.js new file mode 100644 index 000000000..5a847e337 --- /dev/null +++ b/modules/route/back/methods/route/unlink.js @@ -0,0 +1,42 @@ +module.exports = Self => { + Self.remoteMethod('unlink', { + description: 'Removes the matching entries from zoneAgencyMode', + accessType: 'WRITE', + accepts: [ + { + arg: 'agencyModeId', + type: 'number', + required: true, + description: 'The agencyMode id', + }, + { + arg: 'zoneId', + type: 'number', + required: true, + description: 'The zone id', + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/unlink`, + verb: 'POST' + } + }); + + Self.unlink = async(agencyModeId, zoneId, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const where = { + agencyModeFk: agencyModeId, + zoneFk: zoneId + }; + + await Self.app.models.ZoneAgencyMode.destroyAll(where, myOptions); + }; +}; diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index 1cfe0927e..c82d1722e 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/route/insertTicket')(Self); require('../methods/route/clone')(Self); require('../methods/route/getSuggestedTickets')(Self); + require('../methods/route/unlink')(Self); Self.validate('kmStart', validateDistance, { message: 'Distance must be lesser than 1000' diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index 7d515b67c..970c7574b 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -150,7 +150,7 @@ PC Address - Warehouse + Zone @@ -174,7 +174,15 @@ {{::ticket.address.city}} {{::ticket.address.postalCode}} {{::ticket.address.street}} - {{::ticket.warehouse.name}} + + {{::ticket.zone.name}} + + + @@ -196,3 +204,11 @@ + + + + \ No newline at end of file diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index fd763e32f..e74cbcd40 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -37,6 +37,19 @@ class Controller extends Section { }); } + unlinkZone(ticket) { + const params = { + agencyModeId: this.route.agencyModeFk, + zoneId: ticket.zoneFk, + }; + + const query = `Routes/unlink`; + this.$http.post(query, params).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.$.possibleTicketsModel.refresh(); + }); + } + getSelectedItems(items) { const selectedItems = []; diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index fbbe94360..092445e6f 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -1,3 +1,4 @@ +/* eslint max-len: ["error", { "code": 150 }]*/ import './index'; describe('Route', () => { @@ -73,6 +74,32 @@ describe('Route', () => { }); }); + describe('unlink()', () => { + it('should call the route unlink endpoint with the agency and zone ids', () => { + controller.$.possibleTicketsModel = {refresh: jest.fn()}; + jest.spyOn(controller.vnApp, 'showSuccess'); + + controller.route = { + agencyModeFk: 1 + }; + + const ticket = { + zoneFk: 2, + }; + const params = { + agencyModeId: controller.route.agencyModeFk, + zoneId: ticket.zoneFk, + }; + + $httpBackend.expectPOST(`Routes/unlink`, params).respond('ok'); + controller.unlinkZone(ticket); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith(); + }); + }); + describe('getSelectedItems()', () => { it('should return the selected items', () => { let items = [ diff --git a/modules/route/front/tickets/locale/es.yml b/modules/route/front/tickets/locale/es.yml index c38d4115c..6d63b4b6e 100644 --- a/modules/route/front/tickets/locale/es.yml +++ b/modules/route/front/tickets/locale/es.yml @@ -11,4 +11,5 @@ The selected ticket is not suitable for this route: El ticket seleccionado no es PC: CP The route's vehicle doesn't have a delivery point: El vehículo de la ruta no tiene un punto de entrega The route doesn't have a vehicle: La ruta no tiene un vehículo -Population: Población \ No newline at end of file +Population: Población +Unlink selected zone?: Desvincular zona seleccionada? diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index e9aa5030a..d8c785baa 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -86,8 +86,8 @@ describe('sale priceDifference()', () => { const firstItem = result.items[0]; const secondtItem = result.items[1]; - expect(firstItem.movable).toEqual(440); - expect(secondtItem.movable).toEqual(1980); + expect(firstItem.movable).toEqual(410); + expect(secondtItem.movable).toEqual(1870); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index 8ec4ca487..46ae23702 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -1,7 +1,8 @@ const models = require('vn-loopback/server/server').models; const soap = require('soap'); -describe('ticket sendSms()', () => { +// #3673 sendSms tests excluded +xdescribe('ticket sendSms()', () => { it('should send a message and log it', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 092c9e746..6be455fc9 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -18,7 +18,14 @@ - {{("000000"+sale.itemFk).slice(-6)}} + + + {{::sale.itemFk | zeroFill:6}} + +
{{::sale.item.name}} @@ -83,5 +90,9 @@
- + + diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index ae5642cf3..d613fb5de 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -20,14 +20,22 @@ - Show as PDF + as PDF +
+ as PDF + - Show as CSV + as CSV
diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 9d4381f7c..841dfa409 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -84,6 +84,7 @@ class Controller extends Section { .then(() => { this.canStowaway(); this.isTicketEditable(); + this.hasDocuware(); }); } @@ -122,6 +123,15 @@ class Controller extends Section { }); } + hasDocuware() { + const params = { + fileCabinet: 'deliveryClient', + dialog: 'findTicket' + }; + this.$http.post(`Docuwares/${this.id}/checkFile`, params) + .then(res => this.hasDocuwareFile = res.data); + } + showCsvDeliveryNote() { this.vnReport.showCsv('delivery-note', { recipientId: this.ticket.client.id, diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 288c7508b..0a80d0884 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -206,7 +206,8 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { it('should make a query and show a success snackbar', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.whenGET(`Tickets/16`).respond(); + $httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond(); + $httpBackend.whenGET(`Tickets/${ticket.id}`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond(); controller.createPdfInvoice(); $httpBackend.flush(); @@ -275,4 +276,12 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { }); }); }); + + describe('hasDocuware()', () => { + it('should call hasDocuware method', () => { + $httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond(); + controller.hasDocuware(); + $httpBackend.flush(); + }); + }); }); diff --git a/modules/ticket/front/descriptor-menu/locale/es.yml b/modules/ticket/front/descriptor-menu/locale/es.yml index 1f4ee710c..4a61556db 100644 --- a/modules/ticket/front/descriptor-menu/locale/es.yml +++ b/modules/ticket/front/descriptor-menu/locale/es.yml @@ -1,7 +1,7 @@ Show Delivery Note...: Ver albarán... Send Delivery Note...: Enviar albarán... -Show as PDF: Ver como PDF -Show as CSV: Ver como CSV +as PDF: como PDF +as CSV: como CSV Send PDF: Enviar PDF Send CSV: Enviar CSV Send CSV Delivery Note: Enviar albarán en CSV diff --git a/modules/zone/back/models/agency.json b/modules/zone/back/models/agency.json index 9269b3db6..edec36f87 100644 --- a/modules/zone/back/models/agency.json +++ b/modules/zone/back/models/agency.json @@ -9,11 +9,11 @@ "properties": { "id": { "id": true, - "type": "Number", + "type": "number", "forceId": false }, "name": { - "type": "String", + "type": "string", "required": false } } diff --git a/modules/zone/back/models/zone.json b/modules/zone/back/models/zone.json index ad43bd6f6..5d5970173 100644 --- a/modules/zone/back/models/zone.json +++ b/modules/zone/back/models/zone.json @@ -13,10 +13,10 @@ "properties": { "id": { "id": true, - "type": "Number" + "type": "number" }, "name": { - "type": "String", + "type": "string", "required": true }, "hour": { @@ -24,22 +24,22 @@ "required": true }, "travelingDays": { - "type": "Number" + "type": "number" }, "price": { - "type": "Number" + "type": "number" }, "bonus": { - "type": "Number" + "type": "number" }, "isVolumetric": { - "type": "Boolean" + "type": "boolean" }, "inflation": { - "type": "Number" + "type": "number" }, "itemMaxSize": { - "type": "Number" + "type": "number" } }, "relations": { diff --git a/print/templates/reports/invoice/sql/intrastat.sql b/print/templates/reports/invoice/sql/intrastat.sql index e391056ec..6bf72c158 100644 --- a/print/templates/reports/invoice/sql/intrastat.sql +++ b/print/templates/reports/invoice/sql/intrastat.sql @@ -2,9 +2,13 @@ SELECT ir.id AS code, ir.description AS description, CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems, - CAST(SUM( weight) AS DECIMAL(10,2)) as netKg, + CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) netKg, CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal - FROM vn.sale s + FROM vn.sale s + LEFT JOIN (SELECT ic.itemFk, ic.cm3, ic.cm3delivery + FROM vn.itemCost ic + WHERE ic.cm3 + GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id LEFT JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk