From 616a28500ae0da61c88e1ee63af75e328953709a Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 25 Jul 2023 09:40:22 +0200 Subject: [PATCH 01/23] refs #5834 icon added --- front/salix/components/bank-entity/index.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/front/salix/components/bank-entity/index.html b/front/salix/components/bank-entity/index.html index 211b77317..65f95fcc0 100644 --- a/front/salix/components/bank-entity/index.html +++ b/front/salix/components/bank-entity/index.html @@ -32,6 +32,11 @@ value-field="id" label="Country"> + + Date: Fri, 3 Nov 2023 09:15:41 +0100 Subject: [PATCH 02/23] check bank entity refs 5834 --- back/models/bank-entity.js | 16 ++++++++++++++++ front/salix/components/bank-entity/index.html | 3 ++- front/salix/components/bank-entity/index.js | 2 +- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 4 +++- modules/client/front/billing-data/index.js | 3 --- modules/worker/front/create/index.js | 5 +++-- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/back/models/bank-entity.js b/back/models/bank-entity.js index c89e0b364..16a6e9924 100644 --- a/back/models/bank-entity.js +++ b/back/models/bank-entity.js @@ -10,4 +10,20 @@ module.exports = Self => { Self.validatesUniquenessOf('bic', { message: 'This BIC already exist.' }); + + Self.validateAsync('bic', checkBic, { + message: 'Bank entity id must be specified' + }); + async function checkBic(err, done) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; + + if (code == 'es' && !this.id) + err(); + done(); + } }; diff --git a/front/salix/components/bank-entity/index.html b/front/salix/components/bank-entity/index.html index 65f95fcc0..209994ae7 100644 --- a/front/salix/components/bank-entity/index.html +++ b/front/salix/components/bank-entity/index.html @@ -41,7 +41,8 @@ vn-one ng-show="country.selection.code === 'ES'" label="Entity code" - ng-model="$ctrl.data.id"> + ng-model="$ctrl.data.id" + required="true"> diff --git a/front/salix/components/bank-entity/index.js b/front/salix/components/bank-entity/index.js index 261018017..43653f148 100644 --- a/front/salix/components/bank-entity/index.js +++ b/front/salix/components/bank-entity/index.js @@ -10,7 +10,7 @@ class Controller extends Dialog { if (!this.data.countryFk) throw new Error(`The country can't be empty`); - return this.$http.post(`bankEntities`, this.data) + return this.$http.post(`BankEntities`, this.data) .then(res => this.data.id = res.data.id) .then(() => super.responseHandler(response)) .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 26650175d..593353ae2 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -196,6 +196,7 @@ "Negative basis of tickets: 23": "Negative basis of tickets: 23", "Booking completed": "Booking complete", "The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation", - "You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets" + "You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets", + "Bank entity must be specified": "Bank entity must be specified" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 3cc9a9627..1b43c31a6 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -325,5 +325,7 @@ "Booking completed": "Reserva completada", "The ticket is in preparation": "El ticket [{{ticketId}}]({{{ticketUrl}}}) del comercial {{salesPersonId}} está en preparación", "The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mímina", - "quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mímina" + "quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mímina", + "Bank entity must be specified": "La entidad bancaria es obligatoria" } + diff --git a/modules/client/front/billing-data/index.js b/modules/client/front/billing-data/index.js index 7056fa566..fe46eabae 100644 --- a/modules/client/front/billing-data/index.js +++ b/modules/client/front/billing-data/index.js @@ -51,15 +51,12 @@ export default class Controller extends Section { autofillBic() { if (!this.client || !this.client.iban) return; - let bankEntityId = parseInt(this.client.iban.substr(4, 4)); let filter = {where: {id: bankEntityId}}; if (this.ibanCountry != 'ES') return; - this.$http.get(`BankEntities`, {filter}).then(response => { const hasData = response.data && response.data[0]; - if (hasData) this.client.bankEntityFk = response.data[0].id; else if (!hasData) diff --git a/modules/worker/front/create/index.js b/modules/worker/front/create/index.js index e6d65221f..9a993ae60 100644 --- a/modules/worker/front/create/index.js +++ b/modules/worker/front/create/index.js @@ -30,7 +30,8 @@ export default class Controller extends Section { } autofillBic() { - if (!this.worker || !this.worker.iban) return; + AutoFillBicComponent.controller.prototype.autofillBic(this.client); + /* if (!this.worker || !this.worker.iban) return; let bankEntityId = parseInt(this.worker.iban.substr(4, 4)); let filter = {where: {id: bankEntityId}}; @@ -42,7 +43,7 @@ export default class Controller extends Section { this.worker.bankEntityFk = response.data[0].id; else if (!hasData) this.worker.bankEntityFk = null; - }); + }); */ } generateCodeUser() { From 0536486b8c9d2a145fda867383efa55ea5891d30 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 3 Nov 2023 09:16:59 +0100 Subject: [PATCH 03/23] ref #5834 fix locale --- loopback/locale/es.json | 1 - 1 file changed, 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 1b43c31a6..4b1d991ec 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -321,7 +321,6 @@ "Select a different client": "Seleccione un cliente distinto", "Fill all the fields": "Rellene todos los campos", "The response is not a PDF": "La respuesta no es un PDF", - "Ticket without Route": "Ticket sin ruta", "Booking completed": "Reserva completada", "The ticket is in preparation": "El ticket [{{ticketId}}]({{{ticketUrl}}}) del comercial {{salesPersonId}} está en preparación", "The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mímina", From fe4c529bfe8490d0f27756bc6064b4317b4d0cdf Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 12 Jan 2024 13:05:00 +0100 Subject: [PATCH 04/23] refs #5834 perf: remove front code --- front/salix/components/bank-entity/index.html | 8 +------- front/salix/components/bank-entity/index.js | 2 +- modules/client/front/billing-data/index.js | 3 +++ modules/worker/front/create/index.js | 5 ++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/front/salix/components/bank-entity/index.html b/front/salix/components/bank-entity/index.html index 209994ae7..211b77317 100644 --- a/front/salix/components/bank-entity/index.html +++ b/front/salix/components/bank-entity/index.html @@ -32,17 +32,11 @@ value-field="id" label="Country"> - - + ng-model="$ctrl.data.id"> diff --git a/front/salix/components/bank-entity/index.js b/front/salix/components/bank-entity/index.js index 43653f148..261018017 100644 --- a/front/salix/components/bank-entity/index.js +++ b/front/salix/components/bank-entity/index.js @@ -10,7 +10,7 @@ class Controller extends Dialog { if (!this.data.countryFk) throw new Error(`The country can't be empty`); - return this.$http.post(`BankEntities`, this.data) + return this.$http.post(`bankEntities`, this.data) .then(res => this.data.id = res.data.id) .then(() => super.responseHandler(response)) .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); diff --git a/modules/client/front/billing-data/index.js b/modules/client/front/billing-data/index.js index fe46eabae..7056fa566 100644 --- a/modules/client/front/billing-data/index.js +++ b/modules/client/front/billing-data/index.js @@ -51,12 +51,15 @@ export default class Controller extends Section { autofillBic() { if (!this.client || !this.client.iban) return; + let bankEntityId = parseInt(this.client.iban.substr(4, 4)); let filter = {where: {id: bankEntityId}}; if (this.ibanCountry != 'ES') return; + this.$http.get(`BankEntities`, {filter}).then(response => { const hasData = response.data && response.data[0]; + if (hasData) this.client.bankEntityFk = response.data[0].id; else if (!hasData) diff --git a/modules/worker/front/create/index.js b/modules/worker/front/create/index.js index 9a993ae60..e6d65221f 100644 --- a/modules/worker/front/create/index.js +++ b/modules/worker/front/create/index.js @@ -30,8 +30,7 @@ export default class Controller extends Section { } autofillBic() { - AutoFillBicComponent.controller.prototype.autofillBic(this.client); - /* if (!this.worker || !this.worker.iban) return; + if (!this.worker || !this.worker.iban) return; let bankEntityId = parseInt(this.worker.iban.substr(4, 4)); let filter = {where: {id: bankEntityId}}; @@ -43,7 +42,7 @@ export default class Controller extends Section { this.worker.bankEntityFk = response.data[0].id; else if (!hasData) this.worker.bankEntityFk = null; - }); */ + }); } generateCodeUser() { From b4bb9a48495652429270f38cc121c0a802112dbb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 31 Jan 2024 10:46:16 +0100 Subject: [PATCH 05/23] refs #5834 feat: new validation --- back/models/bank-entity.js | 6 +++++- loopback/locale/es.json | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/back/models/bank-entity.js b/back/models/bank-entity.js index 16a6e9924..ac352f93c 100644 --- a/back/models/bank-entity.js +++ b/back/models/bank-entity.js @@ -8,7 +8,11 @@ module.exports = Self => { }); Self.validatesUniquenessOf('bic', { - message: 'This BIC already exist.' + message: 'This BIC already exist' + }); + + Self.validatesPresenceOf('countryFk', { + message: 'CountryFK cannot be empty' }); Self.validateAsync('bic', checkBic, { diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4a452a6d7..3d25d6ab5 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -72,7 +72,7 @@ "The secret can't be blank": "La contraseña no puede estar en blanco", "We weren't able to send this SMS": "No hemos podido enviar el SMS", "This client can't be invoiced": "Este cliente no puede ser facturado", - "You must provide the correction information to generate a corrective invoice": "Debes informar la información de corrección para generar una factura rectificativa", + "You must provide the correction information to generate a corrective invoice": "Debes informar la información de corrección para generar una factura rectificativa", "This ticket can't be invoiced": "Este ticket no puede ser facturado", "You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado", "This ticket can not be modified": "Este ticket no puede ser modificado", @@ -180,7 +180,8 @@ "New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día *{{shipped}}*, con una cantidad de *{{quantity}}* y un precio de *{{price}} €*", "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día *{{shipped}}*, con una cantidad de *{{quantity}}*", "Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío", - "This BIC already exist.": "Este BIC ya existe.", + "CountryFK cannot be empty": "El país no puede estar vacío", + "This BIC already exist": "Este BIC ya existe", "That item doesn't exists": "Ese artículo no existe", "There's a new urgent ticket:": "Hay un nuevo ticket urgente:", "Invalid account": "Cuenta inválida", @@ -337,6 +338,5 @@ "You already have the mailAlias": "Ya tienes este alias de correo", "The alias cant be modified": "Este alias de correo no puede ser modificado", "No tickets to invoice": "No hay tickets para facturar", - "Bank entity must be specified": "La entidad bancaria es obligatoria" + "Bank entity must be specified": "La entidad bancaria es obligatoria" } - From a67a347a9ef185ed809468d958c215aa00d4b4ee Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 6 Feb 2024 21:51:15 +0100 Subject: [PATCH 06/23] ci: refs#6706 CI fixes --- .dockerignore | 6 ++++-- Jenkinsfile | 23 ++++++++++++----------- back/tests.js | 41 ++++++++++++++++++++++++++++++----------- docker-compose.yml | 10 ++++++---- front/Dockerfile | 2 +- gulpfile.js | 2 +- package.json | 3 ++- pnpm-lock.yaml | 3 +++ webpack.config.js | 4 ++-- 9 files changed, 61 insertions(+), 33 deletions(-) diff --git a/.dockerignore b/.dockerignore index afe81bb0f..1a47908ab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ node_modules print/node_modules -front/node_modules -services \ No newline at end of file +front +db +e2e +storage diff --git a/Jenkinsfile b/Jenkinsfile index 56e33f4ae..4bacaa6d2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,9 +86,6 @@ pipeline { } } stage('Stack') { - environment { - TZ = 'Europe/Madrid' - } parallel { stage('Back') { stages { @@ -104,14 +101,10 @@ pipeline { } post { always { - script { - try { - junit 'junitresults.xml' - junit 'junit.xml' - } catch (e) { - echo e.toString() - } - } + junit( + testResults: 'junitresults.xml', + allowEmptyResults: true + ) } } } @@ -144,6 +137,14 @@ pipeline { steps { sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10' } + post { + always { + junit( + testResults: 'junit.xml', + allowEmptyResults: true + ) + } + } } stage('Build') { when { diff --git a/back/tests.js b/back/tests.js index 0fb4c76ea..1848132f8 100644 --- a/back/tests.js +++ b/back/tests.js @@ -1,19 +1,36 @@ /* eslint-disable no-console */ const path = require('path'); +const getopts = require('getopts'); const Myt = require('@verdnatura/myt/myt'); const Run = require('@verdnatura/myt/myt-run'); const helper = require('./tests-helper'); +const opts = getopts(process.argv.slice(2), { + string: [ + 'network' + ], + boolean: [ + 'ci', + 'junit' + ] +}); + let server; -const isCI = process.argv[2] === 'ci'; const PARALLEL = false; const TIMEOUT = 900000; -process.on('SIGINT', teardown); process.on('exit', teardown); process.on('uncaughtException', onError); process.on('unhandledRejection', onError); +const exitSignals = [ + 'SIGINT', + 'SIGUSR1', + 'SIGUSR2' +]; +for (const signal of exitSignals) + process.on(signal, () => process.exit()); + async function setup() { console.log('Building and running DB container.'); @@ -21,9 +38,9 @@ async function setup() { await myt.init({ workspace: path.join(__dirname, '..'), random: true, - ci: isCI, + ci: opts.ci, tmpfs: process.platform == 'linux', - network: isCI ? 'jenkins' : null + network: opts.network || null }); server = await myt.run(Run); await myt.deinit(); @@ -38,18 +55,19 @@ async function setup() { async function teardown() { if (!server) return; + const oldServer = server; + server = null; if (!PARALLEL) await helper.deinit(); console.log('Stopping and removing DB container.'); - await server.rm(); - server = null; + await oldServer.rm(); } async function onError(err) { - await teardown(); console.error(err); + process.exit(1); } async function test() { @@ -79,8 +97,8 @@ async function test() { const SpecReporter = require('jasmine-spec-reporter').SpecReporter; runner.addReporter(new SpecReporter({ spec: { - displaySuccessful: isCI, - displayPending: isCI + displaySuccessful: opts.ci, + displayPending: opts.ci }, summary: { displayPending: false, @@ -88,11 +106,12 @@ async function test() { })); } - if (isCI) { + if (opts.junit) { const JunitReporter = require('jasmine-reporters'); runner.addReporter(new JunitReporter.JUnitXmlReporter()); - runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT; } + if (opts.ci) + runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT; // runner.loadConfigFile('back/jasmine.json'); runner.loadConfig(config); diff --git a/docker-compose.yml b/docker-compose.yml index dda4187f2..8391a5e23 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,9 @@ services: front: image: registry.verdnatura.es/salix-front:${VERSION:?} build: - context: . - dockerfile: front/Dockerfile + context: front + environment: + - TZ ports: - 80 deploy: @@ -18,11 +19,12 @@ services: back: image: registry.verdnatura.es/salix-back:${VERSION:?} build: . - ports: - - 3000 environment: - NODE_ENV - DEBUG + - TZ + ports: + - 3000 configs: - source: datasources target: /etc/salix/datasources.json diff --git a/front/Dockerfile b/front/Dockerfile index d0ee26904..c507d863c 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -10,7 +10,7 @@ RUN apt-get update \ && ln -sf /dev/stderr /var/log/nginx/error.log WORKDIR /etc/nginx -COPY front/nginx.conf sites-available/salix +COPY nginx.conf sites-available/salix RUN rm sites-enabled/default && ln -s ../sites-available/salix sites-enabled/salix COPY dist /salix/dist diff --git a/gulpfile.js b/gulpfile.js index a4caa6196..1c6fe2a2d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -17,7 +17,7 @@ if (argv.NODE_ENV) let langs = ['es', 'en']; let srcDir = './front'; let modulesDir = './modules'; -let buildDir = 'dist'; +let buildDir = 'front/dist'; let backSources = [ '!node_modules', diff --git a/package.json b/package.json index 04c0e6d04..ff8eca428 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "eslint-plugin-jasmine": "^2.10.1", "fancy-log": "^1.3.2", "file-loader": "^6.2.0", + "getopts": "^2.3.0", "gulp": "^4.0.2", "gulp-concat": "^2.6.1", "gulp-env": "^0.4.0", @@ -107,7 +108,7 @@ "scripts": { "dbtest": "nodemon -q db/tests.js -w db/tests", "test:back": "nodemon -q back/tests.js --config back/nodemonConfig.json", - "test:back:ci": "node back/tests.js ci", + "test:back:ci": "node back/tests.js --ci --junit --network jenkins", "test:e2e": "node e2e/helpers/tests.js", "test:front": "jest --watch", "back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2df0ae49c..69528e3e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -163,6 +163,9 @@ devDependencies: file-loader: specifier: ^6.2.0 version: 6.2.0(webpack@5.90.1) + getopts: + specifier: ^2.3.0 + version: 2.3.0 gulp: specifier: ^4.0.2 version: 4.0.2 diff --git a/webpack.config.js b/webpack.config.js index a102b838e..7296a62d1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,7 +11,7 @@ let baseConfig = { entry: {salix: 'salix'}, mode, output: { - path: path.join(__dirname, 'dist'), + path: path.join(__dirname, 'front/dist'), publicPath: '/' }, module: { @@ -139,7 +139,7 @@ let devConfig = { host: '0.0.0.0', port: 5000, publicPath: '/', - contentBase: 'dist', + contentBase: 'front/dist', quiet: false, noInfo: false, hot: true, From 46dee65e6886a5343d520fa6b314710c4440a113 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 6 Feb 2024 22:22:25 +0100 Subject: [PATCH 07/23] ci: refs#6706 Myt updated --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ff8eca428..73fa5fc7a 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.3", + "@verdnatura/myt": "^1.6.5", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69528e3e2..83904cf41 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,8 +128,8 @@ devDependencies: specifier: ^7.7.7 version: 7.23.7(@babel/core@7.23.9) '@verdnatura/myt': - specifier: ^1.6.3 - version: 1.6.3 + specifier: ^1.6.5 + version: 1.6.5 angular-mocks: specifier: ^1.7.9 version: 1.8.3 @@ -2633,8 +2633,8 @@ packages: dev: false optional: true - /@verdnatura/myt@1.6.3: - resolution: {integrity: sha512-VRoTB5sEPL8a7VaX9l2afpaPNT6pBa+If1tP9tpaJ4enFQbNITlApcC0GK6XYmWMkJQjl2lgdN4/u0UCiNb2MQ==} + /@verdnatura/myt@1.6.5: + resolution: {integrity: sha512-0h7FvhSewd2W9EOymc59YymZJOBfCXmY5CWNFhol1yBfWSOOF9JAEE9DKRMbKaMqd/5Dy9LriS5PYOfeqm3HjA==} hasBin: true dependencies: '@sqltools/formatter': 1.2.5 From aff8ee28ea0dd67a862407b2e1abae6af71383c7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 7 Feb 2024 10:16:47 +0100 Subject: [PATCH 08/23] fix: refs #6272 back & create test --- .../00-aclUpdateFiscalData.sql | 3 + loopback/locale/en.json | 5 +- loopback/locale/es.json | 7 +- .../supplier/specs/updateFiscalData.spec.js | 202 +++++++++++------- .../back/methods/supplier/updateFiscalData.js | 91 ++++---- 5 files changed, 186 insertions(+), 122 deletions(-) create mode 100644 db/versions/10872-pinkLilium/00-aclUpdateFiscalData.sql diff --git a/db/versions/10872-pinkLilium/00-aclUpdateFiscalData.sql b/db/versions/10872-pinkLilium/00-aclUpdateFiscalData.sql new file mode 100644 index 000000000..24f5346a8 --- /dev/null +++ b/db/versions/10872-pinkLilium/00-aclUpdateFiscalData.sql @@ -0,0 +1,3 @@ +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES ('Supplier', 'updateAllFiscalData', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('Supplier', 'updateFiscalData', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); \ No newline at end of file diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 7e010e1b5..419775d1b 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -206,6 +206,5 @@ "Incorrect pin": "Incorrect pin.", "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", "Name should be uppercase": "Name should be uppercase", - "Fecha fuera de rango": "Fecha fuera de rango", - "There is no zone for these parameters 34": "There is no zone for these parameters 34" -} + "You cannot update these fields": "You cannot update these fields" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 1dd70b633..dac839085 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -338,6 +338,7 @@ "The alias cant be modified": "Este alias de correo no puede ser modificado", "No tickets to invoice": "No hay tickets para facturar", "Name should be uppercase": "El nombre debe ir en mayúscula", - "Bank entity must be specified": "La entidad bancaria es obligatoria", - "An email is necessary": "Es necesario un email" -} + "Bank entity must be specified": "La entidad bancaria es obligatoria", + "An email is necessary": "Es necesario un email", + "You cannot update these fields": "No puedes actualizar estos campos" +} \ No newline at end of file diff --git a/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js b/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js index 56030a894..7cb95f840 100644 --- a/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js +++ b/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js @@ -1,92 +1,142 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -describe('Supplier updateFiscalData', () => { +describe('Supplier updateFiscalData()', () => { const supplierId = 1; const administrativeId = 5; - const employeeId = 1; - const defaultData = { - name: 'PLANTS SL', - nif: '06089160W', - account: '4100000001', - sageTaxTypeFk: 4, - sageWithholdingFk: 1, - sageTransactionTypeFk: 1, - postCode: '15214', - city: 'PONTEVEDRA', - provinceFk: 1, - countryFk: 1, - }; + const buyerId = 35; - it('should return an error if the user is not administrative', async() => { - const ctx = {req: {accessToken: {userId: employeeId}}}; - ctx.args = {}; + const name = 'NEW PLANTS'; + const city = 'PONTEVEDRA'; + const nif = 'A68446004'; + const account = '4000000005'; + const sageTaxTypeFk = 5; + const sageWithholdingFk = 2; + const sageTransactionTypeFk = 2; + const postCode = '46460'; + const phone = 456129367; + const street = ' Fake address 12 3 flat'; + const provinceFk = 2; + const countryFk = 1; + const supplierActivityFk = 'animals'; + const healthRegister = '400664487H'; - let error; - await app.models.Supplier.updateFiscalData(ctx, supplierId) - .catch(e => { - error = e; - }); + let ctx; + let options; + let tx; - expect(error.message).toBeDefined(); - }); - - it('should check that the supplier fiscal data is untainted', async() => { - const supplier = await app.models.Supplier.findById(supplierId); - - expect(supplier.name).toEqual(defaultData.name); - expect(supplier.nif).toEqual(defaultData.nif); - expect(supplier.account).toEqual(defaultData.account); - expect(supplier.sageTaxTypeFk).toEqual(defaultData.sageTaxTypeFk); - expect(supplier.sageWithholdingFk).toEqual(defaultData.sageWithholdingFk); - expect(supplier.sageTransactionTypeFk).toEqual(defaultData.sageTransactionTypeFk); - expect(supplier.postCode).toEqual(defaultData.postCode); - expect(supplier.city).toEqual(defaultData.city); - expect(supplier.provinceFk).toEqual(defaultData.provinceFk); - expect(supplier.countryFk).toEqual(defaultData.countryFk); - }); - - it('should update the supplier fiscal data and return the count if changes made', async() => { - const activeCtx = { - accessToken: {userId: administrativeId}, + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: buyerId}, + headers: {origin: 'http://localhost'}, + __: value => value + }, + args: {} }; - const ctx = {req: activeCtx}; + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx + active: ctx.req }); - ctx.args = { - name: 'WEAPON DEALER', - nif: 'A68446004', - account: '4000000005', - sageTaxTypeFk: 5, - sageWithholdingFk: 2, - sageTransactionTypeFk: 2, - postCode: '46460', - city: 'VALENCIA', - provinceFk: 2, - countryFk: 1, - supplierActivityFk: 'animals', - healthRegister: '400664487H' - }; + options = {transaction: tx}; + tx = await models.Sale.beginTransaction({}); + options.transaction = tx; + }); - const result = await app.models.Supplier.updateFiscalData(ctx, supplierId); + afterEach(async() => { + await tx.rollback(); + }); - expect(result.name).toEqual('WEAPON DEALER'); - expect(result.nif).toEqual('A68446004'); - expect(result.account).toEqual('4000000005'); - expect(result.sageTaxTypeFk).toEqual(5); - expect(result.sageWithholdingFk).toEqual(2); - expect(result.sageTransactionTypeFk).toEqual(2); - expect(result.postCode).toEqual('46460'); - expect(result.city).toEqual('VALENCIA'); - expect(result.provinceFk).toEqual(2); - expect(result.countryFk).toEqual(1); - expect(result.supplierActivityFk).toEqual('animals'); - expect(result.healthRegister).toEqual('400664487H'); + it('should throw an error if it is a buyer and tries to update forbidden fiscal data', async() => { + try { + await models.Supplier.updateFiscalData(ctx, + supplierId, + name, + nif, + account, + undefined, + sageTaxTypeFk, + undefined, + sageTransactionTypeFk, + undefined, + undefined, + undefined, + provinceFk, + countryFk, + supplierActivityFk, + healthRegister, + undefined, + undefined, + options); + } catch (e) { + expect(e.message).toEqual('You cannot update these fields'); + } + }); - // Restores - ctx.args = defaultData; - await app.models.Supplier.updateFiscalData(ctx, supplierId); + it('should update the granted fiscal data if it is a buyer', async() => { + const supplier = await models.Supplier.updateFiscalData(ctx, + supplierId, + undefined, + undefined, + account, + phone, + undefined, + undefined, + undefined, + postCode, + street, + city, + provinceFk, + undefined, + undefined, + undefined, + undefined, + undefined, + options); + + expect(supplier.account).toEqual(account); + expect(supplier.phone).toEqual(phone); + expect(supplier.postCode).toEqual(postCode); + expect(supplier.account).toEqual(account); + expect(supplier.city).toEqual(city); + expect(supplier.provinceFk).toEqual(provinceFk); + }); + + it('should update all fiscalData if it is an administative', async() => { + const supplier = await models.Supplier.updateFiscalData(ctx, + supplierId, + name, + nif, + account, + phone, + sageTaxTypeFk, + sageWithholdingFk, + sageTransactionTypeFk, + postCode, + street, + city, + provinceFk, + countryFk, + supplierActivityFk, + healthRegister, + undefined, + undefined, + options); + + expect(supplier.name).toEqual(name); + expect(supplier.nif).toEqual(nif); + expect(supplier.account).toEqual(account); + expect(supplier.phone).toEqual(phone); + expect(supplier.sageTaxTypeFk).toEqual(sageTaxTypeFk); + expect(supplier.sageWithholdingFk).toEqual(sageWithholdingFk); + expect(supplier.sageTransactionTypeFk).toEqual(sageTransactionTypeFk); + expect(supplier.postCode).toEqual(postCode); + expect(supplier.street).toEqual(street); + expect(supplier.city).toEqual(city); + expect(supplier.provinceFk).toEqual(provinceFk); + expect(supplier.countryFk).toEqual(countryFk); + expect(supplier.supplierActivityFk).toEqual(supplierActivityFk); + expect(supplier.healthRegister).toEqual(healthRegister); }); }); diff --git a/modules/supplier/back/methods/supplier/updateFiscalData.js b/modules/supplier/back/methods/supplier/updateFiscalData.js index 271ed8769..c0b860983 100644 --- a/modules/supplier/back/methods/supplier/updateFiscalData.js +++ b/modules/supplier/back/methods/supplier/updateFiscalData.js @@ -1,75 +1,59 @@ +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethod('updateFiscalData', { + Self.remoteMethodCtx('updateFiscalData', { description: 'Updates fiscal data of a supplier', accessType: 'WRITE', accepts: [{ - arg: 'ctx', - type: 'Object', - http: {source: 'context'} - }, - { arg: 'id', type: 'Number', description: 'The supplier id', http: {source: 'path'} - }, - { + }, { arg: 'name', type: 'string' - }, - { + }, { arg: 'nif', type: 'string' - }, - { + }, { arg: 'account', type: 'any' - }, - { + }, { + arg: 'phone', + type: 'string' + }, { arg: 'sageTaxTypeFk', type: 'any' - }, - { + }, { arg: 'sageWithholdingFk', type: 'any' - }, - { + }, { arg: 'sageTransactionTypeFk', type: 'any' - }, - { + }, { arg: 'postCode', type: 'any' - }, - { + }, { arg: 'street', type: 'any' - }, - { + }, { arg: 'city', type: 'string' - }, - { + }, { arg: 'provinceFk', type: 'any' - }, - { + }, { arg: 'countryFk', type: 'any' - }, - { + }, { arg: 'supplierActivityFk', type: 'string' - }, - { + }, { arg: 'healthRegister', type: 'string' - }, - { + }, { arg: 'isVies', type: 'boolean' - }, - { + }, { arg: 'isTrucker', type: 'boolean' }], @@ -84,15 +68,42 @@ module.exports = Self => { } }); - Self.updateFiscalData = async(ctx, supplierId) => { + Self.updateFiscalData = async(ctx, supplierId, name, nif, account, phone, sageTaxTypeFk, sageWithholdingFk, sageTransactionTypeFk, postCode, street, city, provinceFk, countryFk, supplierActivityFk, healthRegister, isVies, isTrucker, options) => { const models = Self.app.models; - const args = ctx.args; + const {args} = ctx; + const myOptions = {}; const supplier = await models.Supplier.findById(supplierId); - // Remove unwanted properties + if (typeof options == 'object') Object.assign(myOptions, options); + delete args.ctx; delete args.id; - return supplier.updateAttributes(args); + const updateAllFiscalData = await models.ACL.checkAccessAcl(ctx, 'Supplier', 'updateAllFiscalData', 'WRITE'); + if (!updateAllFiscalData) { + for (const arg in args) { + if (args[arg] && !['street', 'postCode', 'city', 'provinceFk', 'phone'].includes(arg)) + throw new UserError('You cannot update these fields'); + } + } + + return supplier.updateAttributes({ + name, + nif, + account, + phone, + sageTaxTypeFk, + sageWithholdingFk, + sageTransactionTypeFk, + postCode, + street, + city, + provinceFk, + countryFk, + supplierActivityFk, + healthRegister, + isVies, + isTrucker + }, myOptions); }; }; From bdfbb8f6f7b05e1cec605a7591addd221a429931 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Feb 2024 12:54:37 +0100 Subject: [PATCH 09/23] build: refs#6706 gulp install fixed, myt updated --- gulpfile.js | 44 +++++++++++++++++++++++++++++++++----------- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 1c6fe2a2d..255b1ee05 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ require('require-yaml'); const gulp = require('gulp'); const PluginError = require('plugin-error'); @@ -67,19 +68,40 @@ back.description = `Starts backend and database service`; const defaultTask = gulp.parallel(front, back); defaultTask.description = `Starts all application services`; -function install() { - const install = require('gulp-install'); - const print = require('gulp-print'); +async function install() { + const spawn = require('child_process').spawn; - let npmArgs = []; - if (argv.ci) npmArgs = ['--no-audit', '--prefer-offline']; + console.log('-> Installing global packages...'); + await pnpmInstall(); - let packageFiles = ['front/package.json', 'print/package.json']; - return gulp.src(packageFiles) - .pipe(print(filepath => { - return `Installing packages in ${filepath}`; - })) - .pipe(install({npm: npmArgs})); + const modules = ['front', 'print']; + for (const module of modules) { + console.log(`-> Installing '${module}' packages...`); + await pnpmInstall(module); + } + + async function pnpmInstall(prefix) { + let args = ['install', '--prefer-offline']; + if (prefix) args = args.concat(['--prefix', prefix]); + + const options = { + stdio: [ + process.stdin, + process.stdout, + process.stderr + ] + }; + + await new Promise((resolve, reject) => { + const child = spawn('pnpm', args, options); + child.on('exit', code => { + if (code !== 0) + reject(new Error(`pnpm exit code ${code}`)); + else + resolve(code); + }); + }); + } } install.description = `Installs node dependencies in all directories`; diff --git a/package.json b/package.json index 73fa5fc7a..197c1094d 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.5", + "@verdnatura/myt": "^1.6.6", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 83904cf41..19f57caf9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,8 +128,8 @@ devDependencies: specifier: ^7.7.7 version: 7.23.7(@babel/core@7.23.9) '@verdnatura/myt': - specifier: ^1.6.5 - version: 1.6.5 + specifier: ^1.6.6 + version: 1.6.6 angular-mocks: specifier: ^1.7.9 version: 1.8.3 @@ -2633,8 +2633,8 @@ packages: dev: false optional: true - /@verdnatura/myt@1.6.5: - resolution: {integrity: sha512-0h7FvhSewd2W9EOymc59YymZJOBfCXmY5CWNFhol1yBfWSOOF9JAEE9DKRMbKaMqd/5Dy9LriS5PYOfeqm3HjA==} + /@verdnatura/myt@1.6.6: + resolution: {integrity: sha512-5KHi9w1baEQ6Oe/pAR8pl0oD5yyJJuPirE+ZhygreUGGURfig4VekjhlGE3WEbWquDiIAMi89J1VQ+1Ba0+jQw==} hasBin: true dependencies: '@sqltools/formatter': 1.2.5 From eda85eda76337d1d1699bda12ef73d3fa97ead2f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Feb 2024 13:24:50 +0100 Subject: [PATCH 10/23] ci: refs#6706 Jenkinsfile fixes --- Jenkinsfile | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4bacaa6d2..034bda012 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,9 +5,15 @@ def FROM_GIT def RUN_TESTS def RUN_BUILD +def BRANCH_ENV = [ + test: 'test', + master: 'production' +] + node { stage('Setup') { - env.NODE_ENV = 'dev' + env.BACK_REPLICAS = 1 + env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev' PROTECTED_BRANCH = [ 'dev', @@ -23,24 +29,26 @@ node { echo "NODE_NAME: ${env.NODE_NAME}" echo "WORKSPACE: ${env.WORKSPACE}" - configFileProvider([ - configFile(fileId: 'salix.properties', - variable: 'PROPS_FILE') - ]) { - def props = readProperties file: PROPS_FILE - props.each {key, value -> env."${key}" = value } - props.each {key, value -> echo "${key}: ${value}" } - } - - if (PROTECTED_BRANCH) { + if (FROM_GIT) { configFileProvider([ - configFile(fileId: "salix.branch.${env.BRANCH_NAME}", - variable: 'BRANCH_PROPS_FILE') + configFile(fileId: 'salix.properties', + variable: 'PROPS_FILE') ]) { - def props = readProperties file: BRANCH_PROPS_FILE + def props = readProperties file: PROPS_FILE props.each {key, value -> env."${key}" = value } props.each {key, value -> echo "${key}: ${value}" } } + + if (PROTECTED_BRANCH) { + configFileProvider([ + configFile(fileId: "salix.branch.${env.BRANCH_NAME}", + variable: 'BRANCH_PROPS_FILE') + ]) { + def props = readProperties file: BRANCH_PROPS_FILE + props.each {key, value -> env."${key}" = value } + props.each {key, value -> echo "${key}: ${value}" } + } + } } } } From c4907d1a33ad9d9d2998512f4b430f10c26c3a15 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Feb 2024 13:56:21 +0100 Subject: [PATCH 11/23] ci: refs#6706 Jenkinsfile fixes --- Jenkinsfile | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 034bda012..2c04bcf16 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,26 +29,24 @@ node { echo "NODE_NAME: ${env.NODE_NAME}" echo "WORKSPACE: ${env.WORKSPACE}" - if (FROM_GIT) { + configFileProvider([ + configFile(fileId: 'salix.properties', + variable: 'PROPS_FILE') + ]) { + def props = readProperties file: PROPS_FILE + props.each {key, value -> env."${key}" = value } + props.each {key, value -> echo "${key}: ${value}" } + } + + if (PROTECTED_BRANCH) { configFileProvider([ - configFile(fileId: 'salix.properties', - variable: 'PROPS_FILE') + configFile(fileId: "salix.branch.${env.BRANCH_NAME}", + variable: 'BRANCH_PROPS_FILE') ]) { - def props = readProperties file: PROPS_FILE + def props = readProperties file: BRANCH_PROPS_FILE props.each {key, value -> env."${key}" = value } props.each {key, value -> echo "${key}: ${value}" } } - - if (PROTECTED_BRANCH) { - configFileProvider([ - configFile(fileId: "salix.branch.${env.BRANCH_NAME}", - variable: 'BRANCH_PROPS_FILE') - ]) { - def props = readProperties file: BRANCH_PROPS_FILE - props.each {key, value -> env."${key}" = value } - props.each {key, value -> echo "${key}: ${value}" } - } - } } } } From dee70198241fdad2d46e9d992404cb14584d1985 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 8 Feb 2024 10:50:56 +0100 Subject: [PATCH 12/23] refs #6443 migrate vn2008.cc_to_iban to util.accountNumberToIban --- .../util/functions/accountNumberToIban.sql | 58 +++++++++++++++++++ db/routines/vn2008/functions/cc_to_iban.sql | 49 ---------------- .../10873-greenPaniculata/00-firstScript.sql | 1 + 3 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 db/routines/util/functions/accountNumberToIban.sql delete mode 100644 db/routines/vn2008/functions/cc_to_iban.sql create mode 100644 db/versions/10873-greenPaniculata/00-firstScript.sql diff --git a/db/routines/util/functions/accountNumberToIban.sql b/db/routines/util/functions/accountNumberToIban.sql new file mode 100644 index 000000000..2b38efe72 --- /dev/null +++ b/db/routines/util/functions/accountNumberToIban.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`( + vAccount VARCHAR(20) +) + RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN +/** +* Calcula y genera el código IBAN correspondiente +* a un número de cuenta bancaria español. +* +* @param vAccount Número de cuenta bancaria +* @return vIban Código IBAN de 4 caracteres. +*/ + DECLARE vIban VARCHAR(4); + + SELECT + CONCAT('ES', + RIGHT( + CONCAT(0, + 98-MOD( + CONCAT( + MOD( + CONCAT( + MOD( + CONCAT( + MOD( + SUBSTRING(vAccount, 1, 8), + 97 + ), + SUBSTRING(vAccount,9,8) + ), + 97 + ), + SUBSTRING( + CONCAT(vAccount, 142800), + 17, + 8 + ) + ), + 97 + ), + SUBSTRING( + CONCAT(vAccount, 142800), + 25, + 2 + ) + ), + 97 + ) + ), + 2 + ) + ) INTO vIban; + + RETURN vIban; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn2008/functions/cc_to_iban.sql b/db/routines/vn2008/functions/cc_to_iban.sql deleted file mode 100644 index c4515a9cc..000000000 --- a/db/routines/vn2008/functions/cc_to_iban.sql +++ /dev/null @@ -1,49 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`cc_to_iban`(cc VARCHAR(20)) - RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci - DETERMINISTIC -BEGIN - DECLARE iban VARCHAR(4); - select - CONCAT('ES', - RIGHT( - concat(0, - 98- - mod( - concat( - mod( - concat( - mod( - concat( - mod( - substring(cc,1,8), - 97), - substring(cc,9,8) - ), - 97), - substring( - concat( - cc, - 142800 - ), - 17, - 8 - ) - ), - 97), - substring( - concat( - cc, - 142800 - ), - 25, - 2 - ) - ), - 97) - ) - ,2) - )into iban; -RETURN iban; -END$$ -DELIMITER ; diff --git a/db/versions/10873-greenPaniculata/00-firstScript.sql b/db/versions/10873-greenPaniculata/00-firstScript.sql new file mode 100644 index 000000000..59ab23944 --- /dev/null +++ b/db/versions/10873-greenPaniculata/00-firstScript.sql @@ -0,0 +1 @@ +REVOKE EXECUTE ON FUNCTION vn2008.cc_to_iban FROM hr, financial; From 2e009b6f25884b7d3337c03e663b2f5174d4314e Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 8 Feb 2024 12:04:34 +0100 Subject: [PATCH 13/23] refactor: refs #6609 sectorType description to code --- db/dump/fixtures.before.sql | 4 ++-- db/routines/vn/procedures/collectionPlacement_get.sql | 4 ++-- db/routines/vn/procedures/productionControl.sql | 2 +- db/routines/vn/procedures/productionSectorList.sql | 2 +- db/routines/vn/views/itemShelvingStock.sql | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ae7612b46..be9fe05ff 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -184,8 +184,8 @@ INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0), (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0); -INSERT INTO `vn`.`sectorType` (id,description) - VALUES (1,'First type'); +INSERT INTO `vn`.`sectorType` (`id`, `code`) + VALUES (1,'normal'); INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`) VALUES diff --git a/db/routines/vn/procedures/collectionPlacement_get.sql b/db/routines/vn/procedures/collectionPlacement_get.sql index db452ec2a..3641ba705 100644 --- a/db/routines/vn/procedures/collectionPlacement_get.sql +++ b/db/routines/vn/procedures/collectionPlacement_get.sql @@ -70,9 +70,9 @@ BEGIN ish.created, ish.visible, IFNULL( - IF(st.description = 'previousByPacking', ish.packing, g.`grouping`), + IF(st.code = 'previousByPacking', ish.packing, g.`grouping`), 1) `grouping`, - st.description = 'previousPrepared' isPreviousPrepared, + st.code = 'previousPrepared' isPreviousPrepared, iss.id itemShelvingSaleFk, ts.ticketFk, iss.id, diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index 3f3663865..b42645d1e 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -207,7 +207,7 @@ proc: BEGIN ENGINE = MEMORY SELECT ish.itemFk, p.sectorFk, - st.description = 'previousPrepared' isPreviousPrepared, + st.code = 'previousPrepared' isPreviousPrepared, sc.itemPackingTypeFk FROM itemShelving ish JOIN shelving sh ON sh.code = ish.shelvingFk diff --git a/db/routines/vn/procedures/productionSectorList.sql b/db/routines/vn/procedures/productionSectorList.sql index ea047b376..5447f10d0 100644 --- a/db/routines/vn/procedures/productionSectorList.sql +++ b/db/routines/vn/procedures/productionSectorList.sql @@ -85,7 +85,7 @@ BEGIN JOIN client c ON c.id = t.clientFk JOIN tmp.productionBuffer pb ON pb.ticketFk = t.id JOIN packagingConfig pc - WHERE IF(st.description = 'previousByPacking', + WHERE IF(st.code = 'previousByPacking', i.`size` > pc.previousPreparationMinimumSize AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), TRUE) diff --git a/db/routines/vn/views/itemShelvingStock.sql b/db/routines/vn/views/itemShelvingStock.sql index 15afe72a2..e0825eae5 100644 --- a/db/routines/vn/views/itemShelvingStock.sql +++ b/db/routines/vn/views/itemShelvingStock.sql @@ -15,7 +15,7 @@ AS SELECT `ish`.`itemFk` AS `itemFk`, `sh`.`parkingFk` AS `parkingFk`, `ish`.`id` AS `itemShelvingFk`, `ish`.`created` AS `created`, - `st`.`description` = 'previousPrepared' AS `isPreviousPrepared` + `st`.`code` = 'previousPrepared' AS `isPreviousPrepared` FROM ( ( ( From 3f400f92e5e1cb3427a95da7b96baeb098115d6c Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 8 Feb 2024 12:08:19 +0100 Subject: [PATCH 14/23] refactor: refs #6609 sectorType description to code --- db/versions/10874-yellowRose/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/10874-yellowRose/00-firstScript.sql diff --git a/db/versions/10874-yellowRose/00-firstScript.sql b/db/versions/10874-yellowRose/00-firstScript.sql new file mode 100644 index 000000000..835ff8515 --- /dev/null +++ b/db/versions/10874-yellowRose/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.sectorType CHANGE description code varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; From 6a94a48a9d357b6a358d74f5498d0d03f8b9a2fc Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 8 Feb 2024 12:18:37 +0100 Subject: [PATCH 15/23] refactor: refs #6609 sectorType description to code --- .../10874-yellowRose/00-firstScript.sql | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/db/versions/10874-yellowRose/00-firstScript.sql b/db/versions/10874-yellowRose/00-firstScript.sql index 835ff8515..6d5b1ee86 100644 --- a/db/versions/10874-yellowRose/00-firstScript.sql +++ b/db/versions/10874-yellowRose/00-firstScript.sql @@ -1 +1,38 @@ ALTER TABLE vn.sectorType CHANGE description code varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; + +-- Si no pongo lo de bajo da error en la view vn.itemShelvingAvailable +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingStock` +AS SELECT `ish`.`itemFk` AS `itemFk`, + sum(`ish`.`visible`) AS `visible`, + min(`ish`.`packing`) AS `packing`, + min(`ish`.`grouping`) AS `grouping`, + `s`.`description` AS `sector`, + sum(`ish`.`visible`) AS `visibleOriginal`, + 0 AS `removed`, + `p`.`sectorFk` AS `sectorFk`, + `s`.`warehouseFk` AS `warehouseFk`, + `ish`.`shelvingFk` AS `shelvingFk`, + `p`.`code` AS `parkingCode`, + `sh`.`parkingFk` AS `parkingFk`, + `ish`.`id` AS `itemShelvingFk`, + `ish`.`created` AS `created`, + `st`.`code` = 'previousPrepared' AS `isPreviousPrepared` +FROM ( + ( + ( + ( + `vn`.`itemShelving` `ish` + LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) + ) + LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) + ) + LEFT JOIN `vn`.`sector` `s` ON(`s`.`id` = `p`.`sectorFk`) + ) + LEFT JOIN `vn`.`sectorType` `st` ON(`st`.`id` = `s`.`typeFk`) + ) +WHERE `ish`.`visible` <> 0 + AND `p`.`sectorFk` <> 0 +GROUP BY `ish`.`itemFk`, + `p`.`sectorFk`; \ No newline at end of file From 30069ded15802c0ea505736e3fba4ff73bfbf706 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 8 Feb 2024 16:01:34 +0100 Subject: [PATCH 16/23] fix: refs #6806 fix date filter --- modules/item/front/last-entries/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/item/front/last-entries/index.js b/modules/item/front/last-entries/index.js index 31616f8a7..a5f1f4d9d 100644 --- a/modules/item/front/last-entries/index.js +++ b/modules/item/front/last-entries/index.js @@ -16,7 +16,7 @@ class Controller extends Section { this.filter = { where: { itemFk: this.$params.id, - shipped: { + landed: { between: [from, to] } } @@ -36,7 +36,7 @@ class Controller extends Section { const to = new Date(this._dateTo); to.setHours(23, 59, 59, 59); - this.filter.where.shipped = { + this.filter.where.landed = { between: [from, to] }; this.$.model.refresh(); @@ -53,7 +53,7 @@ class Controller extends Section { const to = new Date(value); to.setHours(23, 59, 59, 59); - this.filter.where.shipped = { + this.filter.where.landed = { between: [from, to] }; this.$.model.refresh(); From 08728d3162dec76398ebcb7b5a029c30aa030cf3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 9 Feb 2024 07:51:51 +0100 Subject: [PATCH 17/23] refs #6651 feat:add urlImage --- db/routines/vn/procedures/itemShelving_get.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelving_get.sql b/db/routines/vn/procedures/itemShelving_get.sql index 98f865994..c6968e093 100644 --- a/db/routines/vn/procedures/itemShelving_get.sql +++ b/db/routines/vn/procedures/itemShelving_get.sql @@ -15,11 +15,13 @@ BEGIN p.code, ish.id, s.priority, - ish.isChecked + ish.isChecked, + CONCAT('http:', ic.url, '/catalog/200x200/', i.image) urlImage FROM itemShelving ish JOIN item i ON i.id = ish.itemFk JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci LEFT JOIN parking p ON s.parkingFk = p.id + JOIN hedera.imageConfig ic WHERE ish.shelvingFk COLLATE utf8_unicode_ci = vSelf; END$$ DELIMITER ; From f18191d6e9222bb147331a687b5e613fa685d859 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 9 Feb 2024 09:23:00 +0100 Subject: [PATCH 18/23] refactor: refs#6706 root dir clean, minimist dep removed --- Dockerfile => back/Dockerfile | 0 docker-compose.yml | 3 ++- e2e/helpers/tests.js | 14 +++++++++----- fileMock.js => front/jest-mock.js | 0 jest-front.js => front/jest-setup.js | 28 ++++++++++++++-------------- gulpfile.js | 4 ---- jest.front.config.js | 4 ++-- package.json | 1 - pnpm-lock.yaml | 3 --- 9 files changed, 27 insertions(+), 30 deletions(-) rename Dockerfile => back/Dockerfile (100%) rename fileMock.js => front/jest-mock.js (100%) rename jest-front.js => front/jest-setup.js (59%) diff --git a/Dockerfile b/back/Dockerfile similarity index 100% rename from Dockerfile rename to back/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 8391a5e23..43a528a8b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,10 +19,11 @@ services: back: image: registry.verdnatura.es/salix-back:${VERSION:?} build: . + dockerfile: back/Dockerfile environment: + - TZ - NODE_ENV - DEBUG - - TZ ports: - 3000 configs: diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js index a4a059622..7dd299e0b 100644 --- a/e2e/helpers/tests.js +++ b/e2e/helpers/tests.js @@ -1,7 +1,9 @@ +/* eslint-disable no-console */ require('@babel/register')({presets: ['@babel/env']}); require('core-js/stable'); require('regenerator-runtime/runtime'); require('vn-loopback/server/boot/date')(); +const getopts = require('getopts'); const path = require('path'); const Myt = require('@verdnatura/myt/myt'); @@ -18,12 +20,16 @@ process.on('warning', warning => { }); async function test() { - if (process.argv[2] === 'show') - process.env.E2E_SHOW = true; + const opts = getopts(process.argv.slice(2), { + boolean: ['show'] + }); + process.env.E2E_SHOW = opts.show; + console.log('Building and running DB container.'); const myt = new Myt(); await myt.init({workspace: path.join(__dirname, '../..')}); await myt.run(Run); + await myt.deinit(); const Jasmine = require('jasmine'); const jasmine = new Jasmine(); @@ -70,12 +76,10 @@ async function test() { jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; await jasmine.execute(); - - await myt.deinit(); } async function backendStatus() { - log('Awaiting backend connection...'); + log('Awaiting backend connection.'); const milliseconds = 1000; const maxAttempts = 10; diff --git a/fileMock.js b/front/jest-mock.js similarity index 100% rename from fileMock.js rename to front/jest-mock.js diff --git a/jest-front.js b/front/jest-setup.js similarity index 59% rename from jest-front.js rename to front/jest-setup.js index eabda9110..eebd99bbd 100644 --- a/jest-front.js +++ b/front/jest-setup.js @@ -1,19 +1,19 @@ import 'angular'; import 'angular-mocks'; -import core from './front/core/module.js'; -import './front/salix/components/app/app.js'; -import './modules/zone/front/module.js'; -import './modules/claim/front/module.js'; -import './modules/client/front/module.js'; -import './modules/invoiceOut/front/module.js'; -import './modules/invoiceIn/front/module.js'; -import './modules/item/front/module.js'; -import './modules/order/front/module.js'; -import './modules/route/front/module.js'; -import './modules/ticket/front/module.js'; -import './modules/travel/front/module.js'; -import './modules/worker/front/module.js'; -import './modules/shelving/front/module.js'; +import core from './core/module.js'; +import './salix/components/app/app.js'; +import '../modules/zone/front/module.js'; +import '../modules/claim/front/module.js'; +import '../modules/client/front/module.js'; +import '../modules/invoiceOut/front/module.js'; +import '../modules/invoiceIn/front/module.js'; +import '../modules/item/front/module.js'; +import '../modules/order/front/module.js'; +import '../modules/route/front/module.js'; +import '../modules/ticket/front/module.js'; +import '../modules/travel/front/module.js'; +import '../modules/worker/front/module.js'; +import '../modules/shelving/front/module.js'; import 'vn-loopback/server/boot/date'; // Set NODE_ENV diff --git a/gulpfile.js b/gulpfile.js index 255b1ee05..054a65c1c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,7 +2,6 @@ require('require-yaml'); const gulp = require('gulp'); const PluginError = require('plugin-error'); -const argv = require('minimist')(process.argv.slice(2)); const log = require('fancy-log'); const Myt = require('@verdnatura/myt/myt'); const Run = require('@verdnatura/myt/myt-run'); @@ -12,9 +11,6 @@ const Start = require('@verdnatura/myt/myt-start'); let isWindows = /^win/.test(process.platform); -if (argv.NODE_ENV) - process.env.NODE_ENV = argv.NODE_ENV; - let langs = ['es', 'en']; let srcDir = './front'; let modulesDir = './modules'; diff --git a/jest.front.config.js b/jest.front.config.js index 3289df8bb..a843832ea 100644 --- a/jest.front.config.js +++ b/jest.front.config.js @@ -10,7 +10,7 @@ module.exports = { }, testEnvironment: 'jsdom', setupFilesAfterEnv: [ - './jest-front.js' + './front/jest-setup.js' ], testMatch: [ '**/front/**/*.spec.js', @@ -37,7 +37,7 @@ module.exports = { ], moduleNameMapper: { '\\.(css|scss)$': 'identity-obj-proxy', - '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/fileMock.js', + '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/front/jest-mock.js', }, testURL: 'http://localhost', verbose: false, diff --git a/package.json b/package.json index 197c1094d..9ae8b276b 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,6 @@ "js-yaml": "^4.1.0", "json-loader": "^0.5.7", "merge-stream": "^1.0.1", - "minimist": "^1.2.5", "node-sass": "^9.0.0", "nodemon": "^2.0.16", "plugin-error": "^1.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 19f57caf9..221008dd9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -232,9 +232,6 @@ devDependencies: merge-stream: specifier: ^1.0.1 version: 1.0.1 - minimist: - specifier: ^1.2.5 - version: 1.2.8 node-sass: specifier: ^9.0.0 version: 9.0.0 From 26d4dbbe347f4ea5218c5f26d64326e876d21289 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 9 Feb 2024 09:26:46 +0100 Subject: [PATCH 19/23] fix: refs#6706 docker-compose.yml fixes --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 43a528a8b..5bb168093 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,8 +18,9 @@ services: memory: 1G back: image: registry.verdnatura.es/salix-back:${VERSION:?} - build: . - dockerfile: back/Dockerfile + build: + context: . + dockerfile: back/Dockerfile environment: - TZ - NODE_ENV From dcefc9d3822b6cb2f088614f91e1c184c6c5f775 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 9 Feb 2024 11:14:30 +0100 Subject: [PATCH 20/23] refs #6651 feat:add urlImage --- db/routines/vn/procedures/itemShelving_get.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelving_get.sql b/db/routines/vn/procedures/itemShelving_get.sql index c6968e093..1be762f09 100644 --- a/db/routines/vn/procedures/itemShelving_get.sql +++ b/db/routines/vn/procedures/itemShelving_get.sql @@ -16,7 +16,7 @@ BEGIN ish.id, s.priority, ish.isChecked, - CONCAT('http:', ic.url, '/catalog/200x200/', i.image) urlImage + ic.url FROM itemShelving ish JOIN item i ON i.id = ish.itemFk JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci From 3e57bf2b341527d7cb047dfa0f7301009e209a5c Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 9 Feb 2024 11:49:29 +0100 Subject: [PATCH 21/23] refs #6791 remake negativeBases --- modules/invoiceOut/back/methods/invoiceOut/negativeBases.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 96c789316..46ec1cfa6 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -66,6 +66,7 @@ module.exports = Self => { cou.country, c.id clientId, c.socialName clientSocialName, + u.nickname workerSocialName, SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount, negativeBase.taxableBase, negativeBase.ticketFk, @@ -78,8 +79,10 @@ module.exports = Self => { JOIN vn.company co ON co.id = t.companyFk JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.client c ON c.id = t.clientFk + JOIN vn.country cou ON cou.id = c.countryFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + JOIN account.user u ON u.id = w.id LEFT JOIN ( SELECT ticketFk, taxableBase FROM tmp.ticketAmount From 1597f17230ac995cb83c71661ef6575c028b3ecd Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 9 Feb 2024 12:47:17 +0100 Subject: [PATCH 22/23] refs #6791 remove intro --- modules/invoiceOut/back/methods/invoiceOut/negativeBases.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js index 46ec1cfa6..dc9496b4a 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js +++ b/modules/invoiceOut/back/methods/invoiceOut/negativeBases.js @@ -79,7 +79,6 @@ module.exports = Self => { JOIN vn.company co ON co.id = t.companyFk JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.client c ON c.id = t.clientFk - JOIN vn.country cou ON cou.id = c.countryFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk JOIN account.user u ON u.id = w.id From 362d825202e5ad3dc4a7ef9f4dd72246166c37dd Mon Sep 17 00:00:00 2001 From: ivanm Date: Fri, 9 Feb 2024 13:38:09 +0100 Subject: [PATCH 23/23] fix: refs #6443 #6444 #6445 ChangeRevokeToGrant --- .../util/functions/accountNumberToIban.sql | 42 ++++++------- .../10866-whiteRaphis/00-firstScript.sql | 1 - .../10873-greenPaniculata/00-firstScript.sql | 61 ++++++++++++++++++- .../10879-maroonCymbidium/00-firstScript.sql | 34 +++++++++++ 4 files changed, 115 insertions(+), 23 deletions(-) delete mode 100644 db/versions/10866-whiteRaphis/00-firstScript.sql create mode 100644 db/versions/10879-maroonCymbidium/00-firstScript.sql diff --git a/db/routines/util/functions/accountNumberToIban.sql b/db/routines/util/functions/accountNumberToIban.sql index 2b38efe72..49d3c917e 100644 --- a/db/routines/util/functions/accountNumberToIban.sql +++ b/db/routines/util/functions/accountNumberToIban.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`( - vAccount VARCHAR(20) + vAccount VARCHAR(20) ) RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci DETERMINISTIC @@ -18,41 +18,41 @@ BEGIN CONCAT('ES', RIGHT( CONCAT(0, - 98-MOD( - CONCAT( - MOD( - CONCAT( - MOD( - CONCAT( - MOD( - SUBSTRING(vAccount, 1, 8), - 97 - ), - SUBSTRING(vAccount,9,8) + 98-MOD( + CONCAT( + MOD( + CONCAT( + MOD( + CONCAT( + MOD( + SUBSTRING(vAccount, 1, 8), + 97 + ), + SUBSTRING(vAccount,9,8) ), - 97 - ), + 97 + ), SUBSTRING( CONCAT(vAccount, 142800), 17, 8 ) ), - 97 - ), + 97 + ), SUBSTRING( CONCAT(vAccount, 142800), 25, 2 ) ), - 97 - ) + 97 + ) ), - 2 - ) + 2 + ) ) INTO vIban; - RETURN vIban; + RETURN vIban; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/versions/10866-whiteRaphis/00-firstScript.sql b/db/versions/10866-whiteRaphis/00-firstScript.sql deleted file mode 100644 index bfbcb5dc9..000000000 --- a/db/versions/10866-whiteRaphis/00-firstScript.sql +++ /dev/null @@ -1 +0,0 @@ -REVOKE EXECUTE ON FUNCTION vn2008.red FROM hrBoss, salesPerson; diff --git a/db/versions/10873-greenPaniculata/00-firstScript.sql b/db/versions/10873-greenPaniculata/00-firstScript.sql index 59ab23944..3125eb7aa 100644 --- a/db/versions/10873-greenPaniculata/00-firstScript.sql +++ b/db/versions/10873-greenPaniculata/00-firstScript.sql @@ -1 +1,60 @@ -REVOKE EXECUTE ON FUNCTION vn2008.cc_to_iban FROM hr, financial; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`( + vAccount VARCHAR(20) +) + RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN +/** +* Calcula y genera el código IBAN correspondiente +* a un número de cuenta bancaria español. +* +* @param vAccount Número de cuenta bancaria +* @return vIban Código IBAN de 4 caracteres. +*/ + DECLARE vIban VARCHAR(4); + + SELECT + CONCAT('ES', + RIGHT( + CONCAT(0, + 98-MOD( + CONCAT( + MOD( + CONCAT( + MOD( + CONCAT( + MOD( + SUBSTRING(vAccount, 1, 8), + 97 + ), + SUBSTRING(vAccount,9,8) + ), + 97 + ), + SUBSTRING( + CONCAT(vAccount, 142800), + 17, + 8 + ) + ), + 97 + ), + SUBSTRING( + CONCAT(vAccount, 142800), + 25, + 2 + ) + ), + 97 + ) + ), + 2 + ) + ) INTO vIban; + + RETURN vIban; +END$$ +DELIMITER ; + +GRANT EXECUTE ON FUNCTION util.accountNumberToIban TO hr, financial; diff --git a/db/versions/10879-maroonCymbidium/00-firstScript.sql b/db/versions/10879-maroonCymbidium/00-firstScript.sql new file mode 100644 index 000000000..7efc4d6ab --- /dev/null +++ b/db/versions/10879-maroonCymbidium/00-firstScript.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`( + vSelf INT, + vStems INT +) + RETURNS double + DETERMINISTIC +BEGIN +/** +* Calcula un valor neto estimado en función de +* datos históricos de facturas intrastat. +* +* @param vSelf Id de intrastat +* @param vStems Número de unidades +* @return vNet +*/ + DECLARE vNet DOUBLE; + + SELECT ROUND(vStems / (SUM(average) / COUNT(average)), 2) INTO vNet + FROM ( + SELECT *, stems / net average + FROM invoiceInIntrastat + WHERE intrastatFk = vSelf + AND net + AND stems > 0 + ORDER BY dated DESC + LIMIT 20 + ) sub; + + RETURN vNet/2; +END$$ +DELIMITER ; + +GRANT EXECUTE ON FUNCTION vn.intrastat_estimateNet TO administrative; \ No newline at end of file