diff --git a/db/changes/10430-ash/00-aclAgency.sql b/db/changes/10430-ash/00-aclAgency.sql new file mode 100644 index 000000000..8073ee69c --- /dev/null +++ b/db/changes/10430-ash/00-aclAgency.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId) + VALUES(304, 'Agency', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql new file mode 100644 index 000000000..fbeaa4447 --- /dev/null +++ b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + ('SupplierAgencyTerms', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/changes/10430-ash/00-supplierAgencyTerm.sql b/db/changes/10430-ash/00-supplierAgencyTerm.sql new file mode 100644 index 000000000..351efd143 --- /dev/null +++ b/db/changes/10430-ash/00-supplierAgencyTerm.sql @@ -0,0 +1,27 @@ +ALTER TABLE vn.agencyTerm ADD supplierFk INT NULL; +ALTER TABLE vn.agencyTerm CHANGE supplierFk supplierFk INT NULL AFTER agencyFk; + +UPDATE vn.agencyTerm `at` + JOIN vn.agency a ON a.id = `at`.agencyFk +SET `at`.supplierFk = a.supplierFk; + +ALTER TABLE vn.agencyTerm ADD CONSTRAINT agencyTerm_FK FOREIGN KEY (agencyFk) REFERENCES vn.agency(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.agencyTerm ADD CONSTRAINT agencyTerm_FK_1 FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +RENAME TABLE vn.agencyTerm TO vn.supplierAgencyTerm; + +CREATE OR REPLACE +ALGORITHM = UNDEFINED +DEFINER=`root`@`localhost` +VIEW `vn`.`agencyTerm` AS +SELECT + `sat`.`agencyFk` AS `agencyFk`, + `sat`.`minimumPackages` AS `minimumPackages`, + `sat`.`kmPrice` AS `kmPrice`, + `sat`.`packagePrice` AS `packagePrice`, + `sat`.`routePrice` AS `routePrice`, + `sat`.`minimumKm` AS `minimumKm`, + `sat`.`minimumM3` AS `minimumM3`, + `sat`.`m3Price` AS `m3Price` +FROM + `vn`.`supplierAgencyTerm` `sat` diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index edb937e5f..50a12a094 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2472,3 +2472,11 @@ INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`) INSERT INTO `vn`.`docuwareConfig` (`url`) VALUES ('https://verdnatura.docuware.cloud/docuware/platform'); + +INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackages`, `kmPrice`, `packagePrice`, `routePrice`, `minimumKm`, `minimumM3`, `m3Price`) + VALUES + (1, 1, 0, 0.00, 0.00, NULL, 0, 0.00, 23), + (2, 1, 60, 0.00, 0.00, NULL, 0, 5.00, 33), + (3, 2, 0, 15.00, 0.00, NULL, 0, 0.00, 0), + (4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0), + (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 856ee57d8..aa86e8ab6 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -219,5 +219,6 @@ "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", "Can't transfer claimed sales": "No puedes transferir lineas reclamadas", "You don't have privileges to create pay back": "No tienes permisos para crear un abono", - "The item is required": "El artículo es requerido" + "The item is required": "El artículo es requerido", + "The agency is already assigned to another autonomous": "La agencia ya está asignada a otro autónomo" } \ No newline at end of file diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index 7febc17b4..7c1bba1ec 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -11,6 +11,9 @@ "SupplierAccount": { "dataSource": "vn" }, + "SupplierAgencyTerm": { + "dataSource": "vn" + }, "SupplierLog": { "dataSource": "vn" }, diff --git a/modules/supplier/back/models/supplier-agency-term.js b/modules/supplier/back/models/supplier-agency-term.js new file mode 100644 index 000000000..93cee928b --- /dev/null +++ b/modules/supplier/back/models/supplier-agency-term.js @@ -0,0 +1,9 @@ +let UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`The agency is already assigned to another autonomous`); + return err; + }); +}; diff --git a/modules/supplier/back/models/supplier-agency-term.json b/modules/supplier/back/models/supplier-agency-term.json new file mode 100644 index 000000000..dff4c9e8b --- /dev/null +++ b/modules/supplier/back/models/supplier-agency-term.json @@ -0,0 +1,47 @@ +{ + "name": "SupplierAgencyTerm", + "base": "VnModel", + "options": { + "mysql": { + "table": "supplierAgencyTerm" + } + }, + "properties": { + "agencyFk": { + "type": "number", + "id": true + }, + "supplierFk": { + "type": "number" + }, + "minimumPackages": { + "type": "number" + }, + "kmPrice": { + "type": "number" + }, + "packagePrice": { + "type": "number" + }, + "routePrice": { + "type": "number" + }, + "minimumKm": { + "type": "number" + }, + "minimumM3": { + "type": "number" + }, + "m3Price": { + "type": "number" + } + }, + "acls": [ + { + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index.html new file mode 100644 index 000000000..5e61e311c --- /dev/null +++ b/modules/supplier/front/agency-term/index.html @@ -0,0 +1,85 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index.js new file mode 100644 index 000000000..75eda0223 --- /dev/null +++ b/modules/supplier/front/agency-term/index.js @@ -0,0 +1,28 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + constructor($element, $) { + super($element, $); + } + + add() { + this.$.model.insert({}); + } + + onSubmit() { + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); + } +} + +ngModule.vnComponent('vnSupplierAgencyTerm', { + template: require('./index.html'), + controller: Controller, + bindings: { + supplier: '<' + } +}); diff --git a/modules/supplier/front/agency-term/index.spec.js b/modules/supplier/front/agency-term/index.spec.js new file mode 100644 index 000000000..8b4b8596b --- /dev/null +++ b/modules/supplier/front/agency-term/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; + const $element = angular.element(''); + controller = $componentController('vnItemTags', {$element, $scope}); + })); + + describe('getHighestPriority', () => { + it('should return the highest priority value + 1 from the array', () => { + $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; + 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/agency-term/locale/es.yml b/modules/supplier/front/agency-term/locale/es.yml new file mode 100644 index 000000000..f4ba7d87d --- /dev/null +++ b/modules/supplier/front/agency-term/locale/es.yml @@ -0,0 +1,8 @@ +Minimum M3: M3 minimos +Package Price: Precio bulto +Km Price: Precio Km +M3 Price: Precio M3 +Route Price: Precio ruta +Minimum Km: Km minimos +Remove row: Eliminar fila +Add row: Añadir fila \ No newline at end of file diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index dc131ef4a..e52db0675 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -18,3 +18,4 @@ import './billing-data'; import './address/index'; import './address/create'; import './address/edit'; +import './agency-term'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 3d3814f5d..16376e37c 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -15,6 +15,7 @@ {"state": "supplier.card.address.index", "icon": "icon-delivery"}, {"state": "supplier.card.account", "icon": "icon-account"}, {"state": "supplier.card.contact", "icon": "contact_phone"}, + {"state": "supplier.card.agencyTerm", "icon": "contact_support"}, {"state": "supplier.card.log", "icon": "history"}, {"state": "supplier.card.consumption", "icon": "show_chart"} ] @@ -86,6 +87,13 @@ "supplier": "$ctrl.supplier" } }, + { + "url": "/agency-term", + "state": "supplier.card.agencyTerm", + "component": "vn-supplier-agency-term", + "description": "Autonomous", + "acl": ["administrative"] + }, { "url": "/consumption?q", "state": "supplier.card.consumption",