diff --git a/db/changes/10270-wiseMan/00-ACL.sql b/db/changes/10270-wiseMan/00-ACL.sql new file mode 100644 index 0000000000..e6374d5a2b --- /dev/null +++ b/db/changes/10270-wiseMan/00-ACL.sql @@ -0,0 +1 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); \ No newline at end of file diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index 237934f8c1..364bdaae51 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -45,6 +45,11 @@ "type": "belongsTo", "model": "Supplier", "foreignKey": "supplierFk" + }, + "bankEntity": { + "type": "belongsTo", + "model": "BankEntity", + "foreignKey": "bankEntityFk" } } } \ No newline at end of file diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html new file mode 100644 index 0000000000..864b362286 --- /dev/null +++ b/modules/supplier/front/account/index.html @@ -0,0 +1,75 @@ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js new file mode 100644 index 0000000000..069601a207 --- /dev/null +++ b/modules/supplier/front/account/index.js @@ -0,0 +1,49 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + constructor($element, $) { + super($element, $); + this.include = { + relation: 'bankEntity', + scope: { + fields: ['countryFk', 'id', 'name', 'bic'] + } + }; + } + + add() { + this.$.model.insert({ + supplierFk: this.$params.id + }); + } + + onSubmit() { + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + this.card.reload(); + }); + } + + showBankEntity(event) { + if (event.defaultPrevented) return; + event.preventDefault(); + this.$.bankEntity.show(); + } + + onBankEntityAccept() { + const query = `SupplierAccounts/${this.$params.id}/createBankEntity`; + return this.$http.patch(query, this.newBankEntity) + .then(res => this.supplierAccount.bankEntityFk = res.data.id); + } +} + +ngModule.vnComponent('vnSupplierAccount', { + template: require('./index.html'), + controller: Controller, + require: { + card: '^vnSupplierCard' + } +}); diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js new file mode 100644 index 0000000000..34a9ce143d --- /dev/null +++ b/modules/supplier/front/account/index.spec.js @@ -0,0 +1,34 @@ +import './index.js'; +import crudModel from 'core/mocks/crud-model'; + +describe('Item', () => { + describe('Component vnItemTags', () => { + let $scope; + let controller; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; + const $element = angular.element(''); + controller = $componentController('vnItemTags', {$element, $scope}); + })); + + describe('getHighestPriority', () => { + it('should return the highest priority value + 1 from the array', () => { + let result = controller.getHighestPriority(); + + expect(result).toEqual(3); + }); + + it('should return 1 when there is no priority defined', () => { + $scope.model.data = []; + let result = controller.getHighestPriority(); + + expect(result).toEqual(1); + }); + }); + }); +}); diff --git a/modules/supplier/front/account/locale/es.yml b/modules/supplier/front/account/locale/es.yml new file mode 100644 index 0000000000..7443ad4e35 --- /dev/null +++ b/modules/supplier/front/account/locale/es.yml @@ -0,0 +1,2 @@ +Bank entity: Entidad bancaria +swift: Swift BIC \ No newline at end of file diff --git a/modules/supplier/front/bankentity/index.html b/modules/supplier/front/bankentity/index.html new file mode 100644 index 0000000000..ed1691f27f --- /dev/null +++ b/modules/supplier/front/bankentity/index.html @@ -0,0 +1,40 @@ + + +

Please, ensure you put the correct data!

+ + + + + + + + + + +
+ + + + +
diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js new file mode 100644 index 0000000000..20be668dad --- /dev/null +++ b/modules/supplier/front/bankentity/index.js @@ -0,0 +1,42 @@ +import ngModule from '../module'; +import Component from 'core/lib/component'; +import './style.scss'; + +class Controller extends Component { + open() { + this.$.bankentityDialog.show(); + } + + onOpen() { + this.location = {}; + this.$.bankentity.focus(); + } + + onCountryResponse(response) { + this.location.countryFk = response.id; + } + + onAccept() { + try { + if (!this.location.countryFk) + throw new Error(`The country can't be empty`); + + this.$http.patch(`bankentities`, this.location).then(() => { + this.vnApp.showMessage(this.$t('The bankentity has been created. You can save the data now')); + this.emit('response', {$response: this.location}); + }); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + return false; + } + return true; + } +} + +ngModule.vnComponent('vnNewBankentity', { + template: require('./index.html'), + controller: Controller, + bindings: { + data: '<', + } +}); diff --git a/modules/supplier/front/bankentity/index.spec.js b/modules/supplier/front/bankentity/index.spec.js new file mode 100644 index 0000000000..bb5591f357 --- /dev/null +++ b/modules/supplier/front/bankentity/index.spec.js @@ -0,0 +1,34 @@ +import './index'; + +describe('Supplier', () => { + describe('Component vnNewBankentity', () => { + let controller; + let $httpBackend; + let $scope; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => { + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnNewBankentity', {$element, $scope}); + controller.client = {id: 101}; + })); + + describe('onAccept()', () => { + it('should perform a POST query and show a success snackbar', () => { + let params = {countryFk: 1}; + controller.location = {countryFk: 1}; + + jest.spyOn(controller.vnApp, 'showMessage'); + $httpBackend.expect('PATCH', `bankentity`, params).respond(200, params); + + controller.onAccept(); + $httpBackend.flush(); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bankentity has been created. You can save the data now'); + }); + }); + }); +}); diff --git a/modules/supplier/front/bankentity/locale/es.yml b/modules/supplier/front/bankentity/locale/es.yml new file mode 100644 index 0000000000..782690e885 --- /dev/null +++ b/modules/supplier/front/bankentity/locale/es.yml @@ -0,0 +1,11 @@ +New postcode: Nuevo código postal +New city: Nueva ciudad +New province: Nueva provincia +Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos! +The postcode can't be empty: El código postal no puede quedar vacío +The town can't be empty: La población no puede quedar vacía +The province can't be empty: La provincia no puede quedar vacía +The country can't be empty: El país no puede quedar vacío +The postcode has been created. You can save the data now: Se ha creado el código postal. Ahora puedes guardar los datos +The city has been created: Se ha creado la ciudad +The province has been created: Se ha creado la provincia \ No newline at end of file diff --git a/modules/supplier/front/bankentity/style.scss b/modules/supplier/front/bankentity/style.scss new file mode 100644 index 0000000000..adad7ab019 --- /dev/null +++ b/modules/supplier/front/bankentity/style.scss @@ -0,0 +1,9 @@ +@import "variables"; + +vn-new-bankentity { + vn-dialog { + p { + color: $color-alert + } + } +} \ No newline at end of file diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index 9a9334c416..80c49a8b45 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -8,6 +8,7 @@ import './search-panel'; import './summary'; import './basic-data'; import './fiscal-data'; +import './account'; import './contact'; import './log'; import './consumption'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 54d203c8cd..f76af9d979 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -9,6 +9,7 @@ {"state": "supplier.index", "icon": "icon-supplier"} ], "card": [ + {"state": "supplier.card.account", "icon": "face"}, {"state": "supplier.card.basicData", "icon": "settings"}, {"state": "supplier.card.fiscalData", "icon": "account_balance"}, {"state": "supplier.card.billingData", "icon": "icon-payment"}, @@ -96,6 +97,15 @@ "supplier": "$ctrl.supplier" }, "acl": ["administrative"] + },{ + "url": "/account", + "state": "supplier.card.account", + "component": "vn-supplier-account", + "description": "Account", + "params": { + "supplier": "$ctrl.supplier" + }, + "acl": ["administrative"] } ] } \ No newline at end of file