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() {