From a32ebc37da812b203be96817f9766c01ae31ce35 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 9 Mar 2022 23:54:23 +0100 Subject: [PATCH 01/23] add supplier autonomous --- db/changes/10430-ash/00-aclAgency.sql | 2 + .../10430-ash/00-aclSupplierAgencyTerms.sql | 3 + .../10430-ash/00-supplierAgencyTerm.sql | 27 ++++++ db/dump/fixtures.sql | 8 ++ loopback/locale/es.json | 3 +- modules/supplier/back/model-config.json | 3 + .../back/models/supplier-agency-term.js | 9 ++ .../back/models/supplier-agency-term.json | 47 ++++++++++ modules/supplier/front/agency-term/index.html | 85 +++++++++++++++++++ modules/supplier/front/agency-term/index.js | 28 ++++++ .../supplier/front/agency-term/index.spec.js | 34 ++++++++ .../supplier/front/agency-term/locale/es.yml | 8 ++ modules/supplier/front/index.js | 1 + modules/supplier/front/routes.json | 8 ++ 14 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 db/changes/10430-ash/00-aclAgency.sql create mode 100644 db/changes/10430-ash/00-aclSupplierAgencyTerms.sql create mode 100644 db/changes/10430-ash/00-supplierAgencyTerm.sql create mode 100644 modules/supplier/back/models/supplier-agency-term.js create mode 100644 modules/supplier/back/models/supplier-agency-term.json create mode 100644 modules/supplier/front/agency-term/index.html create mode 100644 modules/supplier/front/agency-term/index.js create mode 100644 modules/supplier/front/agency-term/index.spec.js create mode 100644 modules/supplier/front/agency-term/locale/es.yml 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", From 189fe2ed41fc6e0dc8b424ca182b6b152baa89d4 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 10 Mar 2022 08:14:50 +0100 Subject: [PATCH 02/23] update acl --- db/changes/10430-ash/00-aclSupplierAgencyTerms.sql | 2 +- modules/supplier/front/agency-term/index.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql index fbeaa4447..a762f0e64 100644 --- a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql +++ b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql @@ -1,3 +1,3 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) VALUES - ('SupplierAgencyTerms', '*', '*', 'ALLOW', 'ROLE', 'administrative'); + ('SupplierAgencyTerm', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index.js index 75eda0223..bfdf58d50 100644 --- a/modules/supplier/front/agency-term/index.js +++ b/modules/supplier/front/agency-term/index.js @@ -2,10 +2,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - constructor($element, $) { - super($element, $); - } - add() { this.$.model.insert({}); } From 16208a5e115fdd976cf2a08c09a112dfbc5d4872 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 10 Mar 2022 10:35:35 +0100 Subject: [PATCH 03/23] especify PK --- modules/supplier/front/agency-term/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index.html index 5e61e311c..d58c55528 100644 --- a/modules/supplier/front/agency-term/index.html +++ b/modules/supplier/front/agency-term/index.html @@ -2,6 +2,7 @@ vn-id="model" url="SupplierAgencyTerms" link="{supplierFk: $ctrl.$params.id}" + primary-key="agencyFk" data="$ctrl.supplierAgencyTerms" auto-load="true"> @@ -10,7 +11,7 @@ data="$ctrl.supplierAgencyTerms" form="form"> -
+ Date: Thu, 10 Mar 2022 10:40:52 +0100 Subject: [PATCH 04/23] delete frontTest --- .../supplier/front/agency-term/index.spec.js | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 modules/supplier/front/agency-term/index.spec.js diff --git a/modules/supplier/front/agency-term/index.spec.js b/modules/supplier/front/agency-term/index.spec.js deleted file mode 100644 index 8b4b8596b..000000000 --- a/modules/supplier/front/agency-term/index.spec.js +++ /dev/null @@ -1,34 +0,0 @@ -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); - }); - }); - }); -}); From ec4112377276d5b1b1ec3486c8ff0a332f21aec3 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 15 Mar 2022 09:36:48 +0100 Subject: [PATCH 05/23] button for insert rows --- .../front/agency-term/create/index.html | 75 +++++++++++++ .../front/agency-term/create/index.js | 34 ++++++ .../front/agency-term/create/index.spec.js | 102 ++++++++++++++++++ .../front/agency-term/{ => index}/index.html | 12 ++- .../front/agency-term/{ => index}/index.js | 4 +- modules/supplier/front/index.js | 3 +- modules/supplier/front/routes.json | 23 +++- modules/zone/back/models/agency.json | 7 ++ 8 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 modules/supplier/front/agency-term/create/index.html create mode 100644 modules/supplier/front/agency-term/create/index.js create mode 100644 modules/supplier/front/agency-term/create/index.spec.js rename modules/supplier/front/agency-term/{ => index}/index.html (92%) rename modules/supplier/front/agency-term/{ => index}/index.js (83%) diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html new file mode 100644 index 000000000..5d0dca4ef --- /dev/null +++ b/modules/supplier/front/agency-term/create/index.html @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/supplier/front/agency-term/create/index.js b/modules/supplier/front/agency-term/create/index.js new file mode 100644 index 000000000..f876f9003 --- /dev/null +++ b/modules/supplier/front/agency-term/create/index.js @@ -0,0 +1,34 @@ +import ngModule from '../../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.filter = { + fields: [ + 'name' + ], + include: [{ + relation: 'supplierAgencyTerm', + where: { + supplierFk: 1 + } + }], + }; + } + + onSubmit() { + this.$.watcher.submit().then(res => { + this.$state.go('supplier.card.address.index'); + }); + } +} + +ngModule.vnComponent('vnSupplierAgencyTermCreate', { + template: require('./index.html'), + controller: Controller, + bindings: { + supplier: '<' + } +}); diff --git a/modules/supplier/front/agency-term/create/index.spec.js b/modules/supplier/front/agency-term/create/index.spec.js new file mode 100644 index 000000000..026de3769 --- /dev/null +++ b/modules/supplier/front/agency-term/create/index.spec.js @@ -0,0 +1,102 @@ +import './index'; +import watcher from 'core/mocks/watcher'; + +describe('Supplier', () => { + describe('Component vnSupplierAddressCreate', () => { + let $scope; + let controller; + let $element; + let $state; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $state = _$state_; + $state.params.id = '1234'; + $element = angular.element(''); + controller = $componentController('vnSupplierAddressCreate', {$element, $scope}); + controller.$.watcher = watcher; + controller.$.watcher.submit = () => { + return { + then: callback => { + callback({data: {id: 124}}); + } + }; + }; + controller.supplier = {id: 1}; + })); + + describe('onSubmit()', () => { + it('should perform a PATCH and then redirect to the main section', () => { + jest.spyOn(controller.$state, 'go'); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index'); + }); + }); + + describe('town() setter', () => { + it(`should set provinceFk property`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [] + }; + + expect(controller.address.provinceFk).toEqual(1); + }); + + it(`should set provinceFk property and fill the postalCode if there's just one`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [{code: '46001'}] + }; + + expect(controller.address.provinceFk).toEqual(1); + expect(controller.address.postalCode).toEqual('46001'); + }); + }); + + describe('postcode() setter', () => { + it(`should set the town and province properties`, () => { + controller.postcode = { + townFk: 1, + code: 46001, + town: { + id: 1, + name: 'New York', + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + } + } + }; + + expect(controller.address.city).toEqual('New York'); + expect(controller.address.provinceFk).toEqual(1); + }); + }); + }); +}); diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index/index.html similarity index 92% rename from modules/supplier/front/agency-term/index.html rename to modules/supplier/front/agency-term/index/index.html index d58c55528..b472aaf91 100644 --- a/modules/supplier/front/agency-term/index.html +++ b/modules/supplier/front/agency-term/index/index.html @@ -15,7 +15,7 @@ - \ No newline at end of file + + + diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index/index.js similarity index 83% rename from modules/supplier/front/agency-term/index.js rename to modules/supplier/front/agency-term/index/index.js index bfdf58d50..416440ef5 100644 --- a/modules/supplier/front/agency-term/index.js +++ b/modules/supplier/front/agency-term/index/index.js @@ -1,4 +1,4 @@ -import ngModule from '../module'; +import ngModule from '../../module'; import Section from 'salix/components/section'; class Controller extends Section { @@ -15,7 +15,7 @@ class Controller extends Section { } } -ngModule.vnComponent('vnSupplierAgencyTerm', { +ngModule.vnComponent('vnSupplierAgencyTermIndex', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index e52db0675..ba2768854 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -18,4 +18,5 @@ import './billing-data'; import './address/index'; import './address/create'; import './address/edit'; -import './agency-term'; +import './agency-term/index'; +import './agency-term/create'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 16376e37c..39445e5a1 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -15,7 +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.agencyTerm.index", "icon": "contact_support"}, {"state": "supplier.card.log", "icon": "history"}, {"state": "supplier.card.consumption", "icon": "show_chart"} ] @@ -90,9 +90,26 @@ { "url": "/agency-term", "state": "supplier.card.agencyTerm", - "component": "vn-supplier-agency-term", + "component": "ui-view", + "abstract": true + }, + { + "url": "/index?q", + "state": "supplier.card.agencyTerm.index", + "component": "vn-supplier-agency-term-index", "description": "Autonomous", - "acl": ["administrative"] + "params": { + "supplier": "$ctrl.supplier" + } + }, + { + "url": "/create", + "state": "supplier.card.agencyTerm.create", + "component": "vn-supplier-agency-term-create", + "description": "New autonomous", + "params": { + "supplier": "$ctrl.supplier" + } }, { "url": "/consumption?q", diff --git a/modules/zone/back/models/agency.json b/modules/zone/back/models/agency.json index edec36f87..699b60e79 100644 --- a/modules/zone/back/models/agency.json +++ b/modules/zone/back/models/agency.json @@ -16,5 +16,12 @@ "type": "string", "required": false } + }, + "relations": { + "supplierAgencyTerm": { + "type": "belongsTo", + "model": "SupplierAgencyTerm", + "foreignKey": "agencyFk" + } } } From 1ecc76067a2dd3d21886476d5fc8e50f713160e4 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 15 Mar 2022 14:50:09 +0100 Subject: [PATCH 06/23] code to correct insert in model --- .../front/agency-term/create/index.html | 4 +-- .../front/agency-term/create/index.js | 29 ++++++++++++------- .../front/agency-term/index/index.html | 8 ----- modules/zone/back/models/agency.json | 2 +- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html index 5d0dca4ef..f224edc0e 100644 --- a/modules/supplier/front/agency-term/create/index.html +++ b/modules/supplier/front/agency-term/create/index.html @@ -10,7 +10,7 @@ auto-load="true" url="Agencies" filter="$ctrl.filter" - data="agencies"> + data="$ctrl.agencies">
@@ -18,7 +18,7 @@ diff --git a/modules/supplier/front/agency-term/create/index.js b/modules/supplier/front/agency-term/create/index.js index f876f9003..efd5f913d 100644 --- a/modules/supplier/front/agency-term/create/index.js +++ b/modules/supplier/front/agency-term/create/index.js @@ -5,22 +5,29 @@ export default class Controller extends Section { constructor($element, $) { super($element, $); - this.filter = { - fields: [ - 'name' - ], - include: [{ - relation: 'supplierAgencyTerm', - where: { - supplierFk: 1 - } - }], + this.supplierAgencyTerm = { + supplierFk: this.$params.id }; + + this.filter = { + include: { + relation: 'supplierAgencyTerm', + scope: { + where: { + supplierFk: 1 + } + } + } + }; + } + + $onInit() { + console.log(this); } onSubmit() { this.$.watcher.submit().then(res => { - this.$state.go('supplier.card.address.index'); + this.$state.go('supplier.card.agencyTerm.index'); }); } } diff --git a/modules/supplier/front/agency-term/index/index.html b/modules/supplier/front/agency-term/index/index.html index b472aaf91..835de5cbf 100644 --- a/modules/supplier/front/agency-term/index/index.html +++ b/modules/supplier/front/agency-term/index/index.html @@ -68,14 +68,6 @@ - - - - Date: Thu, 17 Mar 2022 14:27:55 +0100 Subject: [PATCH 07/23] add new row --- db/dump/fixtures.sql | 8 +--- .../back/methods/supplier/freeAgencies.js | 42 +++++++++++++++++++ .../back/models/supplier-agency-term.json | 7 ++++ modules/supplier/back/models/supplier.js | 1 + .../front/agency-term/create/index.html | 5 +-- .../front/agency-term/create/index.js | 15 ------- .../front/agency-term/index/index.html | 11 +++-- .../supplier/front/agency-term/index/index.js | 12 ++++++ 8 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 modules/supplier/back/methods/supplier/freeAgencies.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index d87dc046a..f798d4284 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2457,12 +2457,6 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); -INSERT INTO `vn`.`agencyTerm` (`agencyFk`, `minimumPackages`, `kmPrice`, `packagePrice`, `routePrice`, `minimumKm`, `minimumM3`, `m3Price`) - VALUES - (1, 0, 0.00, 0.00, NULL, 0, 0.00, 0), - (3, 0, 0.00, 3.05, NULL, 0, 0.00, 0), - (2, 60, 0.00, 0.00, NULL, 0, 5.00, 33); - UPDATE `vn`.`agency` SET `supplierFk`=1 WHERE `id`=1; @@ -2505,4 +2499,4 @@ INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackage (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); + (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); diff --git a/modules/supplier/back/methods/supplier/freeAgencies.js b/modules/supplier/back/methods/supplier/freeAgencies.js new file mode 100644 index 000000000..48c027e4e --- /dev/null +++ b/modules/supplier/back/methods/supplier/freeAgencies.js @@ -0,0 +1,42 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethod('freeAgencies', { + description: 'Returns a list of agencies without a supplier assigned', + accepts: [{ + arg: 'filter', + type: 'object', + description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string` + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/freeAgencies`, + verb: 'GET' + } + }); + + Self.freeAgencies = async(filter, options) => { + const conn = Self.dataSource.connector; + const where = {'sat.supplierFk': null}; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + filter = mergeFilters(filter, {where}); + + let stmt = new ParameterizedSQL( + `SELECT a.name, a.id + FROM agency a + LEFT JOIN supplierAgencyTerm sat ON sat.agencyFk = a.id`, + null, myOptions); + + stmt.merge(conn.makeSuffix(filter)); + + return conn.executeStmt(stmt); + }; +}; diff --git a/modules/supplier/back/models/supplier-agency-term.json b/modules/supplier/back/models/supplier-agency-term.json index dff4c9e8b..0cd7a0891 100644 --- a/modules/supplier/back/models/supplier-agency-term.json +++ b/modules/supplier/back/models/supplier-agency-term.json @@ -36,6 +36,13 @@ "type": "number" } }, + "relations": { + "agency": { + "type": "belongsTo", + "model": "Agency", + "foreignKey": "agencyFk" + } + }, "acls": [ { "accessType": "EXECUTE", diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index f8b096b30..c1be3488f 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -7,6 +7,7 @@ module.exports = Self => { require('../methods/supplier/getSummary')(Self); require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); + require('../methods/supplier/freeAgencies')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html index f224edc0e..e43f6396a 100644 --- a/modules/supplier/front/agency-term/create/index.html +++ b/modules/supplier/front/agency-term/create/index.html @@ -8,14 +8,13 @@ - @@ -14,15 +15,13 @@ - - + Date: Thu, 17 Mar 2022 14:51:49 +0100 Subject: [PATCH 08/23] add frontTest --- .../front/agency-term/create/index.spec.js | 84 ++----------------- .../front/agency-term/index/index.spec.js | 37 ++++++++ 2 files changed, 42 insertions(+), 79 deletions(-) create mode 100644 modules/supplier/front/agency-term/index/index.spec.js diff --git a/modules/supplier/front/agency-term/create/index.spec.js b/modules/supplier/front/agency-term/create/index.spec.js index 026de3769..682e1cc58 100644 --- a/modules/supplier/front/agency-term/create/index.spec.js +++ b/modules/supplier/front/agency-term/create/index.spec.js @@ -6,96 +6,22 @@ describe('Supplier', () => { let $scope; let controller; let $element; - let $state; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$state_) => { $scope = $rootScope.$new(); - $state = _$state_; - $state.params.id = '1234'; - $element = angular.element(''); - controller = $componentController('vnSupplierAddressCreate', {$element, $scope}); - controller.$.watcher = watcher; - controller.$.watcher.submit = () => { - return { - then: callback => { - callback({data: {id: 124}}); - } - }; - }; - controller.supplier = {id: 1}; + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnSupplierAgencyTermCreate', {$element, $scope}); })); describe('onSubmit()', () => { - it('should perform a PATCH and then redirect to the main section', () => { + it(`should redirect to 'supplier.card.agencyTerm.index' state`, () => { jest.spyOn(controller.$state, 'go'); controller.onSubmit(); - expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index'); - }); - }); - - describe('town() setter', () => { - it(`should set provinceFk property`, () => { - controller.town = { - provinceFk: 1, - code: 46001, - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - }, - postcodes: [] - }; - - expect(controller.address.provinceFk).toEqual(1); - }); - - it(`should set provinceFk property and fill the postalCode if there's just one`, () => { - controller.town = { - provinceFk: 1, - code: 46001, - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - }, - postcodes: [{code: '46001'}] - }; - - expect(controller.address.provinceFk).toEqual(1); - expect(controller.address.postalCode).toEqual('46001'); - }); - }); - - describe('postcode() setter', () => { - it(`should set the town and province properties`, () => { - controller.postcode = { - townFk: 1, - code: 46001, - town: { - id: 1, - name: 'New York', - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - } - } - }; - - expect(controller.address.city).toEqual('New York'); - expect(controller.address.provinceFk).toEqual(1); + expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.agencyTerm.index'); }); }); }); diff --git a/modules/supplier/front/agency-term/index/index.spec.js b/modules/supplier/front/agency-term/index/index.spec.js new file mode 100644 index 000000000..3e9ea4c1e --- /dev/null +++ b/modules/supplier/front/agency-term/index/index.spec.js @@ -0,0 +1,37 @@ +import './index'; +import watcher from 'core/mocks/watcher'; +import crudModel from 'core/mocks/crud-model'; + +describe('Supplier', () => { + describe('Component vnSupplierAddressCreate', () => { + let $scope; + let controller; + let $element; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnSupplierAgencyTermIndex', {$element, $scope}); + })); + + describe('onSubmit()', () => { + it('should make HTTP POST request to save values', () => { + jest.spyOn($scope.watcher, 'check'); + jest.spyOn($scope.watcher, 'notifySaved'); + jest.spyOn($scope.watcher, 'updateOriginalData'); + jest.spyOn($scope.model, 'save'); + + controller.onSubmit(); + + expect($scope.model.save).toHaveBeenCalledWith(); + expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect($scope.watcher.check).toHaveBeenCalledWith(); + expect($scope.watcher.notifySaved).toHaveBeenCalledWith(); + }); + }); + }); +}); From c660786e454284e6d9fe7bd0827c32b05baa73e5 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 14:52:06 +0100 Subject: [PATCH 09/23] refactor chaneg name --- .../10430-ash/{00-agencyTerm.sql => 00-agencyTermConfig.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/10430-ash/{00-agencyTerm.sql => 00-agencyTermConfig.sql} (100%) diff --git a/db/changes/10430-ash/00-agencyTerm.sql b/db/changes/10430-ash/00-agencyTermConfig.sql similarity index 100% rename from db/changes/10430-ash/00-agencyTerm.sql rename to db/changes/10430-ash/00-agencyTermConfig.sql From 894f95cb1fcf95c6aae23f0452327edb8fc23271 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 15:05:13 +0100 Subject: [PATCH 10/23] update consulte sql --- modules/route/back/methods/agency-term/filter.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 0bca9ddf7..2b557034d 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -42,20 +42,20 @@ module.exports = Self => { SUM(t.packages) packages, r.m3, r.kmEnd - r.kmStart kmTotal, - CAST(IFNULL(ate.routePrice, - (ate.kmPrice * (GREATEST(r.kmEnd - r.kmStart , ate.minimumKm)) - + GREATEST(r.m3 , ate.minimumM3) * ate.m3Price) - + ate.packagePrice * SUM(t.packages) ) + CAST(IFNULL(sat.routePrice, + (sat.kmPrice * (GREATEST(r.kmEnd - r.kmStart , sat.minimumKm)) + + GREATEST(r.m3 , sat.minimumM3) * sat.m3Price) + + sat.packagePrice * SUM(t.packages) ) AS DECIMAL(10,2)) price, r.invoiceInFk, - a.supplierFk, + sat.supplierFk, s.name supplierName FROM vn.route r LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id LEFT JOIN vn.agency a ON am.agencyFk = a.id LEFT JOIN vn.ticket t ON t.routeFk = r.id - LEFT JOIN vn.agencyTerm ate ON ate.agencyFk = a.id - LEFT JOIN vn.supplier s ON s.id = a.supplierFk + LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id + LEFT JOIN vn.supplier s ON s.id = sat.supplierFk WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL GROUP BY r.id ) a` From f501d20c65b79f2f15ff2fb9faa95fc779f2d0e6 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 18 Mar 2022 12:41:15 +0100 Subject: [PATCH 11/23] update sql --- .../10430-ash/00-supplierAgencyTerm.sql | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/db/changes/10430-ash/00-supplierAgencyTerm.sql b/db/changes/10430-ash/00-supplierAgencyTerm.sql index 351efd143..4a976b83d 100644 --- a/db/changes/10430-ash/00-supplierAgencyTerm.sql +++ b/db/changes/10430-ash/00-supplierAgencyTerm.sql @@ -24,4 +24,25 @@ SELECT `sat`.`minimumM3` AS `minimumM3`, `sat`.`m3Price` AS `m3Price` FROM - `vn`.`supplierAgencyTerm` `sat` + `vn`.`supplierAgencyTerm` `sat`; + +ALTER TABLE vn.agency DROP FOREIGN KEY agency_ibfk_4; +ALTER TABLE vn.agency CHANGE supplierFk supplierFk__ int(11) DEFAULT NULL NULL; + +CREATE OR REPLACE +ALGORITHM = UNDEFINED +DEFINER=`root`@`localhost` +VIEW `vn2008`.`agency` AS +SELECT + `a`.`id` AS `agency_id`, + `a`.`name` AS `name`, + `a`.`warehouseFk` AS `warehouse_id`, + `a`.`isVolumetric` AS `por_volumen`, + `a`.`bankFk` AS `Id_Banco`, + `a`.`warehouseAliasFk` AS `warehouse_alias_id`, + `a`.`isOwn` AS `propios`, + `a`.`labelZone` AS `zone_label`, + `a`.`workCenterFk` AS `workCenterFk`, + `a`.`supplierFk__` AS `supplierFk__` +FROM + `vn`.`agency` `a`; \ No newline at end of file From 920bff30c8ce8c5b2da16d4f4e1a029100741d5f Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 21 Mar 2022 12:02:17 +0100 Subject: [PATCH 12/23] modify filter sql --- modules/route/back/methods/agency-term/filter.js | 2 +- modules/route/back/methods/agency-term/specs/filter.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 2b557034d..4cd79c2a9 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -56,7 +56,7 @@ module.exports = Self => { LEFT JOIN vn.ticket t ON t.routeFk = r.id LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id LEFT JOIN vn.supplier s ON s.id = sat.supplierFk - WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL + WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL GROUP BY r.id ) a` ); diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 69a7f987c..172c84d9b 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -15,7 +15,7 @@ describe('AgencyTerm filter()', () => { const firstAgencyTerm = agencyTerms[0]; expect(firstAgencyTerm.routeFk).toEqual(1); - expect(agencyTerms.length).toEqual(3); + expect(agencyTerms.length).toEqual(5); await tx.rollback(); } catch (e) { From 31a5e191512649b8757f7762076089d8cf00da7f Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 21 Mar 2022 13:19:19 +0100 Subject: [PATCH 13/23] move db changes to correct folder --- db/changes/{10430-ash => 10440-fallas}/00-aclAgency.sql | 0 .../{10430-ash => 10440-fallas}/00-aclSupplierAgencyTerms.sql | 0 db/changes/{10430-ash => 10440-fallas}/00-agencyTermConfig.sql | 0 db/changes/{10430-ash => 10440-fallas}/00-supplierAgencyTerm.sql | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10430-ash => 10440-fallas}/00-aclAgency.sql (100%) rename db/changes/{10430-ash => 10440-fallas}/00-aclSupplierAgencyTerms.sql (100%) rename db/changes/{10430-ash => 10440-fallas}/00-agencyTermConfig.sql (100%) rename db/changes/{10430-ash => 10440-fallas}/00-supplierAgencyTerm.sql (100%) diff --git a/db/changes/10430-ash/00-aclAgency.sql b/db/changes/10440-fallas/00-aclAgency.sql similarity index 100% rename from db/changes/10430-ash/00-aclAgency.sql rename to db/changes/10440-fallas/00-aclAgency.sql diff --git a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql b/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql similarity index 100% rename from db/changes/10430-ash/00-aclSupplierAgencyTerms.sql rename to db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql diff --git a/db/changes/10430-ash/00-agencyTermConfig.sql b/db/changes/10440-fallas/00-agencyTermConfig.sql similarity index 100% rename from db/changes/10430-ash/00-agencyTermConfig.sql rename to db/changes/10440-fallas/00-agencyTermConfig.sql diff --git a/db/changes/10430-ash/00-supplierAgencyTerm.sql b/db/changes/10440-fallas/00-supplierAgencyTerm.sql similarity index 100% rename from db/changes/10430-ash/00-supplierAgencyTerm.sql rename to db/changes/10440-fallas/00-supplierAgencyTerm.sql From 0963b665606cd7272a04d74b549490911f14f457 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Mar 2022 13:06:17 +0100 Subject: [PATCH 14/23] fix(worker_calendar): absence in holiday day --- modules/worker/front/calendar/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 92bad1f0f..9072f5149 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -198,7 +198,7 @@ class Controller extends Section { const event = this.events[stamp]; const calendar = $event.target.closest('vn-calendar').$ctrl; - if (event) { + if (event && event.absenceId) { if (event.type == this.absenceType.code) this.delete(calendar, day, event); else @@ -228,6 +228,7 @@ class Controller extends Section { this.repaintCanceller(() => this.refresh() .then(calendar.repaint()) + .then(() => this.repaint()) .then(() => this.getContractHolidays()) .then(() => this.getYearHolidays()) ); @@ -264,6 +265,7 @@ class Controller extends Section { this.repaintCanceller(() => this.refresh() .then(calendar.repaint()) + .then(() => this.repaint()) .then(() => this.getContractHolidays()) .then(() => this.getYearHolidays()) ); From 254fee50364b7727720c96106def6eea86391bac Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Mar 2022 14:02:48 +0100 Subject: [PATCH 15/23] feat(worker_calendar): repaint, fix front test and add fixtures --- db/dump/fixtures.sql | 12 ++++++++++++ modules/worker/front/calendar/index.js | 4 ++-- modules/worker/front/calendar/index.spec.js | 6 ++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 90ac5d69c..59fd4c235 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2503,3 +2503,15 @@ INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`) INSERT INTO `vn`.`docuwareConfig` (`url`) VALUES ('https://verdnatura.docuware.cloud/docuware/platform'); + +INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`) + VALUES + (1, 'dayOfIT'); + +INSERT INTO `vn`.`calendarHolidaysType` (`id`, `name`, `hexColour`) + VALUES + (1, 'test', 'E9AA01'); + +INSERT INTO `vn`.`calendarHolidays` (`id`, `calendarHolidaysTypeFk`, `dated`, `calendarHolidaysNameFk`, `workCenterFk`) + VALUES + (1, 1, CONCAT(YEAR(CURDATE()), '-12-09'), 1, 1); \ No newline at end of file diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 9072f5149..95e1fc134 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -228,9 +228,9 @@ class Controller extends Section { this.repaintCanceller(() => this.refresh() .then(calendar.repaint()) - .then(() => this.repaint()) .then(() => this.getContractHolidays()) .then(() => this.getYearHolidays()) + .then(() => this.repaint()) ); }); } @@ -265,9 +265,9 @@ class Controller extends Section { this.repaintCanceller(() => this.refresh() .then(calendar.repaint()) - .then(() => this.repaint()) .then(() => this.getContractHolidays()) .then(() => this.getYearHolidays()) + .then(() => this.repaint()) ); }); } diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 3d5775663..1da4066d9 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -191,7 +191,8 @@ describe('Worker', () => { const selectedDay = new Date(); const expectedEvent = { dated: selectedDay, - type: 'holiday' + type: 'holiday', + absenceId: 1 }; const $event = { target: { @@ -214,7 +215,8 @@ describe('Worker', () => { const selectedDay = new Date(); const expectedEvent = { dated: selectedDay, - type: 'leaveOfAbsence' + type: 'leaveOfAbsence', + absenceId: 1 }; const $event = { target: { From ad4c89af5f9b6fdad158b213f0eef4312103c1ef Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Mar 2022 14:12:47 +0100 Subject: [PATCH 16/23] feat(department): add hasToMistake in model --- modules/worker/back/models/department.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/worker/back/models/department.json b/modules/worker/back/models/department.json index 7d6f7a7be..c3f627e93 100644 --- a/modules/worker/back/models/department.json +++ b/modules/worker/back/models/department.json @@ -34,6 +34,9 @@ }, "notificationEmail": { "type": "string" + }, + "hasToMistake": { + "type": "number" } } } From 67a90c356ff7ad0f030cb705e901d899a4ec7382 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Mar 2022 10:58:04 +0100 Subject: [PATCH 17/23] updated FK for production db --- db/changes/10440-fallas/00-workerBusinessType.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/changes/10440-fallas/00-workerBusinessType.sql diff --git a/db/changes/10440-fallas/00-workerBusinessType.sql b/db/changes/10440-fallas/00-workerBusinessType.sql new file mode 100644 index 000000000..489caa6c9 --- /dev/null +++ b/db/changes/10440-fallas/00-workerBusinessType.sql @@ -0,0 +1,3 @@ +ALTER TABLE `postgresql`.`business_labour_payroll` DROP FOREIGN KEY `business_labour_payroll_cod_contrato`; +ALTER TABLE `vn`.`workerBusinessType` MODIFY COLUMN `id` int(11) NOT NULL; +ALTER TABLE `postgresql`.`business_labour_payroll` ADD CONSTRAINT `business_labour_payroll_FK` FOREIGN KEY (cod_contrato) REFERENCES `vn`.`workerBusinessType`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; From 4bdc29e28344cca5a295f0750eded1973be870e0 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Mar 2022 10:59:23 +0100 Subject: [PATCH 18/23] refactor: calculate holidays through db procedures --- .../worker/back/methods/worker/holidays.js | 124 ++++-------------- modules/worker/front/calendar/index.html | 14 +- modules/worker/front/calendar/locale/es.yml | 2 + 3 files changed, 36 insertions(+), 104 deletions(-) diff --git a/modules/worker/back/methods/worker/holidays.js b/modules/worker/back/methods/worker/holidays.js index bcf4d7f51..339b84b7b 100644 --- a/modules/worker/back/methods/worker/holidays.js +++ b/modules/worker/back/methods/worker/holidays.js @@ -1,4 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; module.exports = Self => { Self.remoteMethodCtx('holidays', { @@ -33,7 +34,8 @@ module.exports = Self => { Self.holidays = async(ctx, id, options) => { const models = Self.app.models; const args = ctx.args; - + const conn = Self.dataSource.connector; + const stmts = []; const myOptions = {}; if (typeof options == 'object') @@ -56,42 +58,6 @@ module.exports = Self => { ended.setHours(23, 59, 59, 59); const filter = { - include: [{ - relation: 'holidays', - scope: { - where: {year: args.year} - } - }, - { - relation: 'absences', - scope: { - include: { - relation: 'absenceType', - }, - where: { - dated: {between: [started, ended]} - } - } - }, - { - relation: 'workCenter', - scope: { - include: { - relation: 'holidays', - scope: { - include: [{ - relation: 'detail' - }, - { - relation: 'type' - }], - where: { - dated: {between: [started, ended]} - } - } - } - } - }], where: { and: [ {workerFk: id}, @@ -107,76 +73,32 @@ module.exports = Self => { } }; - if (args.businessFk) - filter.where.and.push({businessFk: args.businessFk}); - const contracts = await models.WorkerLabour.find(filter, myOptions); - let [firstContract] = contracts; - let payedHolidays; + const payedHolidays = firstContract.payedHolidays; - if (firstContract.payedHolidays) - payedHolidays = firstContract.payedHolidays; - else payedHolidays = 0; + let queryIndex; + const year = started.getFullYear(); - let totalHolidays = 0; - let holidaysEnjoyed = 0; - - for (let contract of contracts) { - const contractStarted = contract.started; - contractStarted.setHours(0, 0, 0, 0); - const contractEnded = contract.ended; - if (contractEnded) - contractEnded.setHours(23, 59, 59, 59); - - let startedTime; - if (contractStarted < started) - startedTime = started.getTime(); - else startedTime = contractStarted.getTime(); - - let endedTime; - if (!contractEnded || (contractEnded && contractEnded > ended)) - endedTime = ended.getTime(); - else endedTime = contractEnded.getTime(); - - const dayTimestamp = 1000 * 60 * 60 * 24; - - // Get number of worked days between dates - let workedDays = Math.floor((endedTime - startedTime) / dayTimestamp); - workedDays += 1; // 1 day inclusion - - // Calculates absences - let entitlementRate = 0; - for (let absence of contract.absences()) { - const absenceType = absence.absenceType(); - const isHoliday = absenceType.code === 'holiday'; - const isHalfHoliday = absenceType.code === 'halfHoliday'; - - if (isHoliday) holidaysEnjoyed += 1; - if (isHalfHoliday) holidaysEnjoyed += 0.5; - - entitlementRate += absenceType.holidayEntitlementRate; - } - - workedDays -= entitlementRate; - - // Max holidays for the selected year - const maxHolidays = contract.holidays() && contract.holidays().days; - - if (workedDays < daysInYear()) - totalHolidays += Math.round(2 * maxHolidays * (workedDays) / daysInYear()) / 2; - else totalHolidays = maxHolidays; + if (args.businessFk) { + stmts.push(new ParameterizedSQL('CALL vn.workerCalendar_calculateBusiness(?,?)', [year, args.businessFk])); + queryIndex = stmts.push('SELECT * FROM tmp.workerCalendarCalculateBusiness') - 1; + stmts.push('DROP TEMPORARY TABLE tmp.workerCalendarCalculateBusiness'); + } else { + stmts.push(new ParameterizedSQL('CALL vn.workerCalendar_calculateYear(?,?)', [year, id])); + queryIndex = stmts.push('SELECT * FROM tmp.workerCalendarCalculateYear') - 1; + stmts.push('DROP TEMPORARY TABLE tmp.workerCalendarCalculateYear'); } - function daysInYear() { - const year = started.getFullYear(); + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql, myOptions); + const [holidays] = result[queryIndex]; - return isLeapYear(year) ? 366 : 365; - } - return {totalHolidays, holidaysEnjoyed, payedHolidays}; + const totalHolidays = holidays.days; + const holidaysEnjoyed = holidays.daysEnjoyed; + const totalHours = holidays.hours; + const hoursEnjoyed = holidays.hoursEnjoyed; + + return {totalHolidays, holidaysEnjoyed, totalHours, hoursEnjoyed, payedHolidays}; }; - - function isLeapYear(year) { - return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0); - } }; diff --git a/modules/worker/front/calendar/index.html b/modules/worker/front/calendar/index.html index 7ef586b36..822bf7d83 100644 --- a/modules/worker/front/calendar/index.html +++ b/modules/worker/front/calendar/index.html @@ -25,20 +25,28 @@
{{'Contract' | translate}} #{{$ctrl.businessId}}
- {{'Used' | translate}} {{$ctrl.contractHolidays.holidaysEnjoyed}} + {{'Used' | translate}} {{$ctrl.contractHolidays.holidaysEnjoyed || 0}} {{'of' | translate}} {{$ctrl.contractHolidays.totalHolidays || 0}} {{'days' | translate}}
- {{'Paid holidays' | translate}} {{$ctrl.contractHolidays.payedHolidays}} {{'days' | translate}} + {{'Use' | translate}} {{$ctrl.contractHolidays.hoursEnjoyed || 0}} + {{'of' | translate}} {{$ctrl.contractHolidays.totalHours || 0}} {{'hours' | translate}} +
+
+ {{'Paid holidays' | translate}} {{$ctrl.contractHolidays.payedHolidays || 0}} {{'days' | translate}}
{{'Year' | translate}} {{$ctrl.year}}
- {{'Used' | translate}} {{$ctrl.yearHolidays.holidaysEnjoyed}} + {{'Used' | translate}} {{$ctrl.yearHolidays.holidaysEnjoyed || 0}} {{'of' | translate}} {{$ctrl.yearHolidays.totalHolidays || 0}} {{'days' | translate}}
+
+ {{'Use' | translate}} {{$ctrl.yearHolidays.hoursEnjoyed || 0}} + {{'of' | translate}} {{$ctrl.yearHolidays.totalHours || 0}} {{'hours' | translate}} +
diff --git a/modules/worker/front/calendar/locale/es.yml b/modules/worker/front/calendar/locale/es.yml index 8e9f9cdf8..85b4ddfe0 100644 --- a/modules/worker/front/calendar/locale/es.yml +++ b/modules/worker/front/calendar/locale/es.yml @@ -2,9 +2,11 @@ Calendar: Calendario Contract: Contrato Festive: Festivo Used: Utilizados +Use: Utilizadas Year: Año of: de days: días +hours: horas Choose an absence type from the right menu: Elige un tipo de ausencia desde el menú de la derecha To start adding absences, click an absence type from the right menu and then on the day you want to add an absence: Para empezar a añadir ausencias, haz clic en un tipo de ausencia desde el menu de la derecha y después en el día que quieres añadir la ausencia You can just add absences within the current year: Solo puedes añadir ausencias dentro del año actual From e02ab9dd2d178811f8363f7aa557f2e5993f3e79 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Mar 2022 11:39:19 +0100 Subject: [PATCH 19/23] feat: add fixtures --- db/dump/fixtures.sql | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 90ac5d69c..4557e8449 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1902,14 +1902,29 @@ INSERT INTO `vn`.`workCenterHoliday` (`workCenterFk`, `days`, `year`) ('1', '24.5', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR))), ('5', '23', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR))); -INSERT INTO `postgresql`.`calendar_state` (`calendar_state_id`, `type`, `rgb`, `code`, `holidayEntitlementRate`) +INSERT INTO `postgresql`.`calendar_state` (`calendar_state_id`, `type`, `rgb`, `code`, `holidayEntitlementRate`, `discountRate`) VALUES - (1, 'Holidays', '#FF4444', 'holiday', 0), - (2, 'Leave of absence', '#C71585', 'absence', 0), - (6, 'Half holiday', '#E65F00', 'halfHoliday', 0), - (15, 'Half Paid Leave', '#5151c0', 'halfPaidLeave', 0), - (20, 'Furlough', '#97B92F', 'furlough', 1), - (21, 'Furlough half day', '#778899', 'halfFurlough', 0.5); + (1, 'Holidays', '#FF4444', 'holiday', 0, 0), + (2, 'Leave of absence', '#C71585', 'absence', 0, 1), + (6, 'Half holiday', '#E65F00', 'halfHoliday', 0, 0.5), + (15, 'Half Paid Leave', '#5151c0', 'halfPaidLeave', 0, 1), + (20, 'Furlough', '#97B92F', 'furlough', 1, 1), + (21, 'Furlough half day', '#778899', 'halfFurlough', 0.5, 1); + +ALTER TABLE `postgresql`.`business_labour_payroll` DROP FOREIGN KEY `business_labour_payroll_cod_categoria`; + +INSERT INTO `vn`.`workerBusinessType` (`id`, `name`, `isFullTime`, `isPermanent`, `hasHolidayEntitlement`) + VALUES + (1, 'CONTRATO HOLANDA', 1, 0, 1), + (100, 'INDEFINIDO A TIEMPO COMPLETO', 1, 1, 1), + (109, 'CONVERSION DE TEMPORAL EN INDEFINIDO T.COMPLETO', 1, 1, 1); + +INSERT INTO `postgresql`.`business_labour_payroll` (`business_id`, `cod_tarifa`, `cod_categoria`, `cod_contrato`, `importepactado`) + VALUES + (1, 7, 12, 100, 900.50), + (1106, 7, 12, 100, 1263.03), + (1107, 7, 12, 100, 2000), + (1108, 7, 12, 100, 1500); INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id`, `date`) VALUES From f4d53c404061f0d13d34df572cd239e64b954a30 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 28 Mar 2022 13:35:36 +0200 Subject: [PATCH 20/23] pull request changes required --- db/changes/10440-fallas/00-aclAgency.sql | 2 +- .../00-aclSupplierAgencyTerms.sql | 2 +- .../10440-fallas/00-supplierAgencyTerm.sql | 20 +++++++++---------- .../back/models/supplier-agency-term.js | 2 +- .../back/models/supplier-agency-term.json | 10 +--------- modules/supplier/front/routes.json | 2 +- 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/db/changes/10440-fallas/00-aclAgency.sql b/db/changes/10440-fallas/00-aclAgency.sql index 8073ee69c..9e5bb6382 100644 --- a/db/changes/10440-fallas/00-aclAgency.sql +++ b/db/changes/10440-fallas/00-aclAgency.sql @@ -1,2 +1,2 @@ -INSERT INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId) +INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES(304, 'Agency', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql b/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql index a762f0e64..fa57c1d64 100644 --- a/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql +++ b/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql @@ -1,3 +1,3 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAgencyTerm', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/changes/10440-fallas/00-supplierAgencyTerm.sql b/db/changes/10440-fallas/00-supplierAgencyTerm.sql index 4a976b83d..f8539f607 100644 --- a/db/changes/10440-fallas/00-supplierAgencyTerm.sql +++ b/db/changes/10440-fallas/00-supplierAgencyTerm.sql @@ -1,14 +1,14 @@ -ALTER TABLE vn.agencyTerm ADD supplierFk INT NULL; -ALTER TABLE vn.agencyTerm CHANGE supplierFk supplierFk INT NULL AFTER agencyFk; +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; +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; +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; +RENAME TABLE `vn`.`agencyTerm` TO `vn`.`supplierAgencyTerm`; CREATE OR REPLACE ALGORITHM = UNDEFINED @@ -26,8 +26,8 @@ SELECT FROM `vn`.`supplierAgencyTerm` `sat`; -ALTER TABLE vn.agency DROP FOREIGN KEY agency_ibfk_4; -ALTER TABLE vn.agency CHANGE supplierFk supplierFk__ int(11) DEFAULT NULL NULL; +ALTER TABLE `vn`.`agency` DROP FOREIGN KEY `agency_ibfk_4`; +ALTER TABLE `vn`.`agency` CHANGE `supplierFk` `supplierFk__` int(11) DEFAULT NULL NULL; CREATE OR REPLACE ALGORITHM = UNDEFINED diff --git a/modules/supplier/back/models/supplier-agency-term.js b/modules/supplier/back/models/supplier-agency-term.js index 93cee928b..961413c18 100644 --- a/modules/supplier/back/models/supplier-agency-term.js +++ b/modules/supplier/back/models/supplier-agency-term.js @@ -1,4 +1,4 @@ -let UserError = require('vn-loopback/util/user-error'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { diff --git a/modules/supplier/back/models/supplier-agency-term.json b/modules/supplier/back/models/supplier-agency-term.json index 0cd7a0891..f9c39729a 100644 --- a/modules/supplier/back/models/supplier-agency-term.json +++ b/modules/supplier/back/models/supplier-agency-term.json @@ -42,13 +42,5 @@ "model": "Agency", "foreignKey": "agencyFk" } - }, - "acls": [ - { - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 39445e5a1..35519b89a 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -94,7 +94,7 @@ "abstract": true }, { - "url": "/index?q", + "url": "/index", "state": "supplier.card.agencyTerm.index", "component": "vn-supplier-agency-term-index", "description": "Autonomous", From b72d26f2149e8278bba2874c2f3702a2f759d337 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 28 Mar 2022 13:40:52 +0200 Subject: [PATCH 21/23] fix: update backTest --- modules/route/back/methods/agency-term/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 6bd8cdb7f..d6c00e585 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -72,7 +72,7 @@ describe('AgencyTerm filter()', () => { const results = await models.AgencyTerm.filter(ctx, options); - expect(results.length).toBe(3); + expect(results.length).toBe(5); await tx.rollback(); } catch (e) { From f853696d03ba8b67c8f4b831fd287298d4ad6d0d Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 28 Mar 2022 13:59:39 +0200 Subject: [PATCH 22/23] change fixture name --- db/dump/fixtures.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index dd1b76622..bc40658f2 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2510,7 +2510,7 @@ INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`) INSERT INTO `vn`.`calendarHolidaysType` (`id`, `name`, `hexColour`) VALUES - (1, 'test', 'E9AA01'); + (1, 'National', '#4169E1'); INSERT INTO `vn`.`calendarHolidays` (`id`, `calendarHolidaysTypeFk`, `dated`, `calendarHolidaysNameFk`, `workCenterFk`) VALUES From 133152460ae1bc41f13a3171dbf96c41f16def59 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 28 Mar 2022 14:14:41 +0200 Subject: [PATCH 23/23] fix: translate --- modules/worker/front/calendar/index.html | 4 ++-- modules/worker/front/calendar/locale/es.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/worker/front/calendar/index.html b/modules/worker/front/calendar/index.html index 822bf7d83..cff4d0bc9 100644 --- a/modules/worker/front/calendar/index.html +++ b/modules/worker/front/calendar/index.html @@ -29,7 +29,7 @@ {{'of' | translate}} {{$ctrl.contractHolidays.totalHolidays || 0}} {{'days' | translate}}
- {{'Use' | translate}} {{$ctrl.contractHolidays.hoursEnjoyed || 0}} + {{'Spent' | translate}} {{$ctrl.contractHolidays.hoursEnjoyed || 0}} {{'of' | translate}} {{$ctrl.contractHolidays.totalHours || 0}} {{'hours' | translate}}
@@ -44,7 +44,7 @@ {{'of' | translate}} {{$ctrl.yearHolidays.totalHolidays || 0}} {{'days' | translate}}
- {{'Use' | translate}} {{$ctrl.yearHolidays.hoursEnjoyed || 0}} + {{'Spent' | translate}} {{$ctrl.yearHolidays.hoursEnjoyed || 0}} {{'of' | translate}} {{$ctrl.yearHolidays.totalHours || 0}} {{'hours' | translate}}
diff --git a/modules/worker/front/calendar/locale/es.yml b/modules/worker/front/calendar/locale/es.yml index 85b4ddfe0..bd75458aa 100644 --- a/modules/worker/front/calendar/locale/es.yml +++ b/modules/worker/front/calendar/locale/es.yml @@ -2,7 +2,7 @@ Calendar: Calendario Contract: Contrato Festive: Festivo Used: Utilizados -Use: Utilizadas +Spent: Utilizadas Year: Año of: de days: días