From 578685e05e54017b2a74091960f65ecf533e5dba Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 18 Feb 2022 13:56:18 +0100 Subject: [PATCH 01/11] feat(client): add back route 'updatePortfolio' --- .../back/methods/client/updatePortfolio.js | 20 +++++++++++++++++++ modules/client/back/models/client.js | 1 + modules/client/front/basic-data/index.html | 3 ++- modules/client/front/basic-data/index.js | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 modules/client/back/methods/client/updatePortfolio.js diff --git a/modules/client/back/methods/client/updatePortfolio.js b/modules/client/back/methods/client/updatePortfolio.js new file mode 100644 index 0000000000..8224a8aa49 --- /dev/null +++ b/modules/client/back/methods/client/updatePortfolio.js @@ -0,0 +1,20 @@ +module.exports = function(Self) { + Self.remoteMethodCtx('updatePortfolio', { + description: 'Update salesPeson potfolio weight', + accessType: 'READ', + accepts: [], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/updatePortfolio`, + verb: 'GET' + } + }); + + Self.updatePortfolio = async() => { + query = `CALL bs.vendedores_updatePortfolio()`; + return await Self.rawSql(query); + }; +}; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e842c3ea10..9ec45f58dd 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -29,6 +29,7 @@ module.exports = Self => { require('../methods/client/updateAddress')(Self); require('../methods/client/consumption')(Self); require('../methods/client/createReceipt')(Self); + require('../methods/client/updatePortfolio')(Self); // Validations diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index a76b448f26..72d09ab49f 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -68,7 +68,8 @@ value-field="id" where="{role: 'salesPerson'}" label="Salesperson" - vn-acl="salesAssistant"> + vn-acl="salesAssistant" + on-change="$ctrl.updatePortfolio()"> Date: Wed, 23 Feb 2022 12:57:43 +0100 Subject: [PATCH 02/11] fix: execute updatePortfolio after submit changes --- modules/client/front/basic-data/index.html | 5 ++--- modules/client/front/basic-data/index.js | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index 72d09ab49f..a5c8669790 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -10,7 +10,7 @@ url="ContactChannels" data="contactChannels"> -
+ + vn-acl="salesAssistant"> { + const query = `Clients/updatePortfolio`; + this.$http.get(query); + }); } } From dedecb492e640d81c974261d12329b89a6839abd Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Feb 2022 12:58:01 +0100 Subject: [PATCH 03/11] sql modify --- .../00-vendedores_updatePortfolio.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql diff --git a/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql b/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql new file mode 100644 index 0000000000..f4c8fd7e83 --- /dev/null +++ b/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql @@ -0,0 +1,30 @@ +DROP PROCEDURE IF EXISTS bs.vendedores_updatePortfolio; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vendedores_updatePortfolio`() +BEGIN + /** + * Actualiza el campo portfolioWeight que indica el peso de la cartera del comercial + * + */ + DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01'); + + DELETE v + FROM vendedores v + JOIN vn.`time` t ON t.`year` = v.año AND t.`month` = v.mes + WHERE t.dated BETWEEN vStarted AND CURDATE(); + + INSERT INTO vendedores(Id_Trabajador, año, mes, portfolioWeight) + SELECT c.lastSalesPersonFk + , t.`year` + , t.`month` + , SUM(v.importe) + FROM vn.`time` t + STRAIGHT_JOIN bs.ventas v ON t.dated = v.fecha + JOIN vn.`client` c ON c.id = v.Id_Cliente + WHERE c.lastSalesPersonFk IS NOT NULL + AND v.fecha BETWEEN vStarted AND CURDATE() + GROUP BY c.lastSalesPersonFk, t.`month`, t.`year`; +END$$ +DELIMITER ; From b3263fb97e5803173f7ba586bfd25db5d9e48e62 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Feb 2022 12:58:09 +0100 Subject: [PATCH 04/11] add fixtures --- db/dump/fixtures.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 07eaf23fdd..f3b55a9dc8 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2443,3 +2443,16 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1103, 500, CURDATE(), CURDATE()), (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); + +INSERT INTO `bs`.`vendedores` (`Id_Trabajador`, `año`, `mes`, `portfolioWeight`) + VALUES + (18, YEAR(CURDATE()), MONTH(CURDATE()), 807.23), + (19, YEAR(CURDATE()), MONTH(CURDATE()), 34.40); + +INSERT INTO `bs`.`ventas` (`Id_Movimiento`, `importe`, `fecha`, `tipo_id`, `Id_Cliente`) + VALUES + (1, 501.95, CURDATE(), 2, 1101), + (2, 70.7, CURDATE(), 2, 1101), + (3, 200.78, CURDATE(), 2, 1101), + (4, 33.8, CURDATE(), 1, 1101), + (30, 34.4, CURDATE(), 1, 1108); From ca40eee5ad7e8516a3d7e980af95d47d0a36522d Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 23 Feb 2022 14:53:49 +0100 Subject: [PATCH 05/11] feat: add backTest --- .../client/specs/updatePortfolio.spec.js | 30 +++++++++++++++++++ .../back/methods/order/specs/filter.spec.js | 6 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 modules/client/back/methods/client/specs/updatePortfolio.spec.js diff --git a/modules/client/back/methods/client/specs/updatePortfolio.spec.js b/modules/client/back/methods/client/specs/updatePortfolio.spec.js new file mode 100644 index 0000000000..d2362cde92 --- /dev/null +++ b/modules/client/back/methods/client/specs/updatePortfolio.spec.js @@ -0,0 +1,30 @@ +const models = require('vn-loopback/server/server').models; + +describe('Client updatePortfolio', () => { + const salesPersonId = 18; + const clienId = 1108; + it('should update the portfolioWeight', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const expectedResult = 841.63; + + const client = await models.Client.findById(clienId, null, options); + // await client.updateAttribute('salesPersonFk', 18); + await models.Client.rawSql(`UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clienId}; `); + + await models.Client.updatePortfolio(); + + let [vendedores] = await models.Client.rawSql(`SELECT portfolioWeight FROM bs.vendedores WHERE Id_Trabajador = ${salesPersonId}; `, null, options); + + expect(vendedores.portfolioWeight).toEqual(expectedResult); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 53b666c102..68de7fe04d 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -53,11 +53,11 @@ describe('order filter()', () => { try { const options = {transaction: tx}; - const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}}; + const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 9}}; const result = await models.Order.filter(myCtx, filter, options); - expect(result.length).toEqual(9); - expect(result[0].id).toEqual(7); + expect(result.length).toEqual(4); + expect(result[0].id).toEqual(19); await tx.rollback(); } catch (e) { From 5ea8c5b06c9d7692adc0223181930a1676a7de4b Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 3 Mar 2022 11:38:32 +0100 Subject: [PATCH 06/11] delete vendedores_updatePortfolio.sql --- .../00-vendedores_updatePortfolio.sql | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql diff --git a/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql b/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql deleted file mode 100644 index f4c8fd7e83..0000000000 --- a/db/changes/14030-ashWednesday/00-vendedores_updatePortfolio.sql +++ /dev/null @@ -1,30 +0,0 @@ -DROP PROCEDURE IF EXISTS bs.vendedores_updatePortfolio; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vendedores_updatePortfolio`() -BEGIN - /** - * Actualiza el campo portfolioWeight que indica el peso de la cartera del comercial - * - */ - DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01'); - - DELETE v - FROM vendedores v - JOIN vn.`time` t ON t.`year` = v.año AND t.`month` = v.mes - WHERE t.dated BETWEEN vStarted AND CURDATE(); - - INSERT INTO vendedores(Id_Trabajador, año, mes, portfolioWeight) - SELECT c.lastSalesPersonFk - , t.`year` - , t.`month` - , SUM(v.importe) - FROM vn.`time` t - STRAIGHT_JOIN bs.ventas v ON t.dated = v.fecha - JOIN vn.`client` c ON c.id = v.Id_Cliente - WHERE c.lastSalesPersonFk IS NOT NULL - AND v.fecha BETWEEN vStarted AND CURDATE() - GROUP BY c.lastSalesPersonFk, t.`month`, t.`year`; -END$$ -DELIMITER ; From 4e3fe180ca4d881efeecea4baedd9e91d21dfa60 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 13:25:55 +0100 Subject: [PATCH 07/11] feat(client_descriptor): add supplier quick-link --- front/salix/components/descriptor/index.js | 3 ++- front/salix/components/descriptor/style.scss | 2 +- modules/client/back/methods/client/getCard.js | 6 ++++++ modules/client/back/models/client.json | 8 +++++++- modules/client/front/descriptor/index.html | 8 ++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/front/salix/components/descriptor/index.js b/front/salix/components/descriptor/index.js index 85baa7f02d..470f0409de 100644 --- a/front/salix/components/descriptor/index.js +++ b/front/salix/components/descriptor/index.js @@ -97,7 +97,8 @@ ngModule.vnComponent('vnDescriptor', { btnOne: '?btnOne', btnTwo: '?btnTwo', btnThree: '?btnThree', - btnFour: '?btnFour' + btnFour: '?btnFour', + btnFive: '?btnFive' } }); diff --git a/front/salix/components/descriptor/style.scss b/front/salix/components/descriptor/style.scss index d15c609383..a87b3f4518 100644 --- a/front/salix/components/descriptor/style.scss +++ b/front/salix/components/descriptor/style.scss @@ -104,7 +104,7 @@ vn-descriptor-content { align-items: center; justify-content: center; padding: 0 $spacing-sm; - margin: 0 $spacing-sm; + margin: 0 $spacing-xs; & > vn-icon { font-size: 1.75rem; diff --git a/modules/client/back/methods/client/getCard.js b/modules/client/back/methods/client/getCard.js index c3ce00bf3f..34fba09845 100644 --- a/modules/client/back/methods/client/getCard.js +++ b/modules/client/back/methods/client/getCard.js @@ -64,6 +64,12 @@ module.exports = function(Self) { scope: { fields: ['id', 'name', 'active'] } + }, + { + relation: 'supplier', + scope: { + fields: ['id', 'nif'] + } } ] }, myOptions); diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index d6a98d83c2..6404cfba0b 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -228,7 +228,13 @@ "type": "belongsTo", "model": "Client", "foreignKey": "transferorFk" - } + }, + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "fi", + "primaryKey": "nif" + } }, "scopes": { "isActive": { diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index 6ae1f690eb..e75246ebe6 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -101,6 +101,14 @@ icon="face"> +
+ + +
From 62aeea04bc7973e1c2d66475b2ee8b8b15238213 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Mar 2022 15:15:59 +0100 Subject: [PATCH 08/11] refactor(print): report driver-route remove ticket.import --- print/templates/reports/driver-route/driver-route.html | 4 ---- 1 file changed, 4 deletions(-) diff --git a/print/templates/reports/driver-route/driver-route.html b/print/templates/reports/driver-route/driver-route.html index eed85e1d73..5d840958d3 100644 --- a/print/templates/reports/driver-route/driver-route.html +++ b/print/templates/reports/driver-route/driver-route.html @@ -139,10 +139,6 @@ {{$t('salesPerson')}} {{ticket.salesPersonName}} - - {{$t('import')}} - {{ticket.import | currency('EUR', $i18n.locale)}} -
From c8a512db4e8d79d3325426312f1b35373556790b Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Mar 2022 15:16:36 +0100 Subject: [PATCH 09/11] unnecessary --- modules/worker/back/methods/calendar/absences.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/worker/back/methods/calendar/absences.js b/modules/worker/back/methods/calendar/absences.js index c2ec27dd81..ddf38a6047 100644 --- a/modules/worker/back/methods/calendar/absences.js +++ b/modules/worker/back/methods/calendar/absences.js @@ -17,11 +17,6 @@ module.exports = Self => { arg: 'year', type: 'date', required: true, - }, - { - arg: 'all', - type: 'boolean', - required: false, }], returns: [{ arg: 'absences', From b11a6a7c5c40f6dac2a86a67aa44bff7d1c3ccef Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 8 Mar 2022 15:17:18 +0100 Subject: [PATCH 10/11] feat(route): add ticket-popup and tests --- modules/route/front/index.js | 1 + modules/route/front/index/index.html | 16 ++++ modules/route/front/index/index.js | 5 + modules/route/front/ticket-popup/index.html | 84 +++++++++++++++++ modules/route/front/ticket-popup/index.js | 77 +++++++++++++++ .../route/front/ticket-popup/index.spec.js | 83 ++++++++++++++++ modules/route/front/ticket-popup/style.scss | 5 + modules/route/front/tickets/index.html | 94 ++----------------- modules/route/front/tickets/index.js | 53 ----------- modules/route/front/tickets/index.spec.js | 75 --------------- 10 files changed, 281 insertions(+), 212 deletions(-) create mode 100644 modules/route/front/ticket-popup/index.html create mode 100644 modules/route/front/ticket-popup/index.js create mode 100644 modules/route/front/ticket-popup/index.spec.js create mode 100644 modules/route/front/ticket-popup/style.scss diff --git a/modules/route/front/index.js b/modules/route/front/index.js index 7c2a17483b..10ccb06343 100644 --- a/modules/route/front/index.js +++ b/modules/route/front/index.js @@ -11,3 +11,4 @@ import './create'; import './basic-data'; import './log'; import './tickets'; +import './ticket-popup'; diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index 5a503b149c..b4f45e7b48 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -48,6 +48,11 @@ {{::route.m3 | dashIfEmpty}} {{::route.description | dashIfEmpty}} + + + + + + + + + +
diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index b94acb55a8..69c4ee99ab 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -13,6 +13,11 @@ export default class Controller extends Section { this.$.summary.show(); } + showTicketPopup(route) { + this.routeSelected = route; + this.$.ticketPopup.show(); + } + get checked() { const rows = this.$.model.data || []; const checkedRows = []; diff --git a/modules/route/front/ticket-popup/index.html b/modules/route/front/ticket-popup/index.html new file mode 100644 index 0000000000..2f2971efc5 --- /dev/null +++ b/modules/route/front/ticket-popup/index.html @@ -0,0 +1,84 @@ + + + + + + Tickets to add +
+ +
+
+
+ + + + + + + + + + Ticket + Client + Province + + + Population + + + PC + Address + Warehouse + + + + + + + + + + + {{::ticket.id}} + + + + + {{::ticket.nickname}} + + + {{::ticket.address.province.name}} + {{::ticket.address.city}} + {{::ticket.address.postalCode}} + {{::ticket.address.street}} + + {{::ticket.zone.name}} + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/modules/route/front/ticket-popup/index.js b/modules/route/front/ticket-popup/index.js new file mode 100644 index 0000000000..f2a9d1b556 --- /dev/null +++ b/modules/route/front/ticket-popup/index.js @@ -0,0 +1,77 @@ +import ngModule from '../module'; +import Component from 'core/lib/component'; +import './style.scss'; + +export default class Controller extends Component { + constructor($element, $scope) { + super($element, $scope); + } + + getSelectedTickets(tickets) { + const selectedTickets = []; + + if (tickets) { + for (let i = 0; i < tickets.length; i++) { + if (tickets[i].checked) + selectedTickets.push(tickets[i]); + } + } + return selectedTickets; + } + + updateVolume() { + let url = `Routes/${this.route.id}/updateVolume`; + this.$http.post(url).then(() => { + this.$.model.refresh(); + if (this.parentReload) + this.parentReload(); + }); + } + + setTicketsRoute() { + let tickets = this.getSelectedTickets(this.possibleTickets); + if (tickets.length === 0) return; + + const updates = []; + + for (let ticket of tickets) { + delete ticket.checked; + const update = { + where: {id: ticket.id}, + data: {routeFk: this.route.id} + }; + + updates.push(update); + } + + const data = {creates: [], updates: updates, deletes: []}; + return this.$http.post(`Tickets/crud`, data) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.updateVolume(); + }); + } + + unlinkZone(ticket) { + const params = { + agencyModeId: this.route.agencyModeFk, + zoneId: ticket.zoneFk, + }; + + const query = `Routes/unlink`; + this.$http.post(query, params).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.$.model.refresh(); + }); + } +} + +ngModule.vnComponent('vnRouteTicketPopup', { + template: require('./index.html'), + controller: Controller, + bindings: { + route: '<', + model: ' { + let controller; + let $httpBackend; + let $scope; + + beforeEach(ngModule('route')); + + beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnRouteTicketPopup', {$element, $scope}); + controller.route = {id: 1}; + controller.$.model = { + refresh: () => {}, + remove: () => {} + }; + controller.card = {reload: () => {}}; + })); + + describe('unlink()', () => { + it('should call the route unlink endpoint with the agency and zone ids', () => { + controller.$.model = {refresh: jest.fn()}; + jest.spyOn(controller.vnApp, 'showSuccess'); + + controller.route = { + agencyModeFk: 1 + }; + + const ticket = { + zoneFk: 2, + }; + const params = { + agencyModeId: controller.route.agencyModeFk, + zoneId: ticket.zoneFk, + }; + + $httpBackend.expectPOST(`Routes/unlink`, params).respond('ok'); + controller.unlinkZone(ticket); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.$.model.refresh).toHaveBeenCalledWith(); + }); + }); + + describe('setTicketsRoute()', () => { + it('should perform a POST query to add tickets to the route', () => { + controller.$.model = {refresh: jest.fn()}; + + controller.route = {id: 1101}; + controller.$.model.data = [{id: 1, checked: false}]; + + const existingTicket = controller.$.model.data[0]; + + controller.route = {id: 111}; + + controller.possibleTickets = [ + {id: 2, checked: false}, + {id: 3, checked: true}, + {id: 4, checked: false}, + {id: 5, checked: true}, + ]; + + let expectedResult = [ + existingTicket, + {id: 3}, + {id: 5} + ]; + + $httpBackend.expectPOST(`Routes/${controller.route.id}/updateVolume`).respond(200); + $httpBackend.whenPOST('Tickets/crud').respond(); + controller.setTicketsRoute(); + $httpBackend.flush(); + + expect(controller.$.model.data).toEqual(expectedResult); + // expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith(); + }); + }); +}); diff --git a/modules/route/front/ticket-popup/style.scss b/modules/route/front/ticket-popup/style.scss new file mode 100644 index 0000000000..77fa48f209 --- /dev/null +++ b/modules/route/front/ticket-popup/style.scss @@ -0,0 +1,5 @@ +@import "variables"; + +.dialog{ + padding: $float-spacing +} \ No newline at end of file diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index 970c7574bc..83960d47d5 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -115,83 +115,17 @@ question="Delete ticket from route?" on-accept="$ctrl.removeTicketFromRoute($index)"> - - - - - - Tickets to add -
- -
-
-
- - - - - - - - - - Ticket - Client - Province - - - Population - - - PC - Address - Zone - - - - - - - - - - - {{::ticket.id}} - - - - - {{::ticket.nickname}} - - - {{::ticket.address.province.name}} - {{::ticket.address.city}} - {{::ticket.address.postalCode}} - {{::ticket.address.street}} - - {{::ticket.zone.name}} - - - - - - - - -
+ + + + + + - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index e74cbcd409..b14b28ed6c 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -4,14 +4,6 @@ import './style.scss'; import UserError from 'core/lib/user-error'; class Controller extends Section { - get route() { - return this._route; - } - - set route(value) { - this._route = value; - } - get isChecked() { if (this.tickets) { for (let instance of this.tickets) @@ -37,19 +29,6 @@ class Controller extends Section { }); } - unlinkZone(ticket) { - const params = { - agencyModeId: this.route.agencyModeFk, - zoneId: ticket.zoneFk, - }; - - const query = `Routes/unlink`; - this.$http.post(query, params).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - this.$.possibleTicketsModel.refresh(); - }); - } - getSelectedItems(items) { const selectedItems = []; @@ -117,38 +96,6 @@ class Controller extends Section { }); } - openPossibleTicketsDialog() { - this.$.possibleTicketsModel.refresh(); - this.$.possibleTicketsDialog.show(); - } - - setTicketsRoute() { - let tickets = this.getSelectedItems(this.possibleTickets); - if (tickets.length === 0) return; - - const updates = []; - - for (let ticket of tickets) { - delete ticket.checked; - const update = { - where: {id: ticket.id}, - data: {routeFk: this.route.id} - }; - - updates.push(update); - } - - const data = {creates: [], updates: updates, deletes: []}; - - return this.$http.post(`Tickets/crud`, data) - .then(() => { - this.$.model.data = this.$.model.data.concat(tickets); - this.vnApp.showSuccess(this.$t('Data saved!')); - this.updateVolume(); - this.$.possibleTicketsDialog.hide(); - }); - } - onDrop($event) { const ticketId = $event.dataTransfer.getData('Text'); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index 092445e6f6..82647d9033 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -74,32 +74,6 @@ describe('Route', () => { }); }); - describe('unlink()', () => { - it('should call the route unlink endpoint with the agency and zone ids', () => { - controller.$.possibleTicketsModel = {refresh: jest.fn()}; - jest.spyOn(controller.vnApp, 'showSuccess'); - - controller.route = { - agencyModeFk: 1 - }; - - const ticket = { - zoneFk: 2, - }; - const params = { - agencyModeId: controller.route.agencyModeFk, - zoneId: ticket.zoneFk, - }; - - $httpBackend.expectPOST(`Routes/unlink`, params).respond('ok'); - controller.unlinkZone(ticket); - $httpBackend.flush(); - - expect(controller.vnApp.showSuccess).toHaveBeenCalled(); - expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith(); - }); - }); - describe('getSelectedItems()', () => { it('should return the selected items', () => { let items = [ @@ -208,55 +182,6 @@ describe('Route', () => { }); }); - describe('openPossibleTicketsDialog()', () => { - it('should call both refresh and show methods in posible tickets model and dialog', () => { - controller.$.possibleTicketsModel = {refresh: () => {}}; - jest.spyOn(controller.$.possibleTicketsModel, 'refresh'); - controller.$.possibleTicketsDialog = {show: () => {}}; - jest.spyOn(controller.$.possibleTicketsDialog, 'show'); - - controller.openPossibleTicketsDialog(); - - expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith(); - expect(controller.$.possibleTicketsDialog.show).toHaveBeenCalledWith(); - }); - }); - - describe('setTicketsRoute()', () => { - it('should perform a POST query to add tickets to the route', () => { - controller.$.possibleTicketsDialog = {hide: () => {}}; - jest.spyOn(controller.$.possibleTicketsDialog, 'hide'); - - controller.$params = {id: 1101}; - controller.$.model.data = [{id: 1, checked: false}]; - - const existingTicket = controller.$.model.data[0]; - - controller.route = {id: 111}; - - controller.possibleTickets = [ - {id: 2, checked: false}, - {id: 3, checked: true}, - {id: 4, checked: false}, - {id: 5, checked: true}, - ]; - - let expectedResult = [ - existingTicket, - {id: 3}, - {id: 5} - ]; - - $httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200); - $httpBackend.expectPOST('Tickets/crud').respond(); - controller.setTicketsRoute(); - $httpBackend.flush(); - - expect(controller.$.model.data).toEqual(expectedResult); - expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith(); - }); - }); - describe('onDrop()', () => { it('should call the insert method when dragging a ticket number', () => { jest.spyOn(controller, 'insert'); From 9c4d58fc1a1515af23cc6d8bb33dc6cf25bfddb8 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 9 Mar 2022 08:08:13 +0100 Subject: [PATCH 11/11] refactor(ticket-popup): extends from dialog --- modules/route/front/index/index.html | 10 +- modules/route/front/ticket-popup/index.html | 161 +++++++++--------- modules/route/front/ticket-popup/index.js | 15 +- .../route/front/ticket-popup/index.spec.js | 31 ++-- modules/route/front/tickets/index.html | 11 +- 5 files changed, 112 insertions(+), 116 deletions(-) diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index b4f45e7b48..6d4bb202d0 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -70,11 +70,11 @@ route="$ctrl.routeSelected"> - - - - + + + diff --git a/modules/route/front/ticket-popup/index.html b/modules/route/front/ticket-popup/index.html index 2f2971efc5..33684a4330 100644 --- a/modules/route/front/ticket-popup/index.html +++ b/modules/route/front/ticket-popup/index.html @@ -1,84 +1,79 @@ - - - - - - Tickets to add -
- -
-
-
- - - - - - - - - - Ticket - Client - Province - - - Population - - - PC - Address - Warehouse - - - - - - - - - - - {{::ticket.id}} - - - - - {{::ticket.nickname}} - - - {{::ticket.address.province.name}} - {{::ticket.address.city}} - {{::ticket.address.postalCode}} - {{::ticket.address.street}} - - {{::ticket.zone.name}} - - - - - - - - -
- - - \ No newline at end of file + + + Tickets to add +
+ +
+
+
+ + + + + + + + + + + + Ticket + Client + Province + + + Population + + + PC + Address + Warehouse + + + + + + + + + + + {{::ticket.id}} + + + + + {{::ticket.nickname}} + + + {{::ticket.address.province.name}} + {{::ticket.address.city}} + {{::ticket.address.postalCode}} + {{::ticket.address.street}} + + {{::ticket.zone.name}} + + + + + + + + + + diff --git a/modules/route/front/ticket-popup/index.js b/modules/route/front/ticket-popup/index.js index f2a9d1b556..8fd7b5d715 100644 --- a/modules/route/front/ticket-popup/index.js +++ b/modules/route/front/ticket-popup/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Dialog from 'core/components/dialog'; import './style.scss'; -export default class Controller extends Component { - constructor($element, $scope) { - super($element, $scope); +class Controller extends Dialog { + constructor($element, $, $transclude) { + super($element, $, $transclude); } getSelectedTickets(tickets) { @@ -29,7 +29,7 @@ export default class Controller extends Component { } setTicketsRoute() { - let tickets = this.getSelectedTickets(this.possibleTickets); + const tickets = this.getSelectedTickets(this.possibleTickets); if (tickets.length === 0) return; const updates = []; @@ -49,6 +49,7 @@ export default class Controller extends Component { .then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); this.updateVolume(); + this.hide(); }); } @@ -62,12 +63,14 @@ export default class Controller extends Component { this.$http.post(query, params).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); this.$.model.refresh(); + this.hide(); }); } } +Controller.$inject = ['$element', '$scope', '$transclude']; ngModule.vnComponent('vnRouteTicketPopup', { - template: require('./index.html'), + slotTemplate: require('./index.html'), controller: Controller, bindings: { route: '<', diff --git a/modules/route/front/ticket-popup/index.spec.js b/modules/route/front/ticket-popup/index.spec.js index 0ab9393e39..b4313024b5 100644 --- a/modules/route/front/ticket-popup/index.spec.js +++ b/modules/route/front/ticket-popup/index.spec.js @@ -12,7 +12,12 @@ describe('Route', () => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); const $element = angular.element(''); - controller = $componentController('vnRouteTicketPopup', {$element, $scope}); + const $transclude = { + $$boundTransclude: { + $$slots: [] + } + }; + controller = $componentController('vnRouteTicketPopup', {$element, $scope, $transclude}); controller.route = {id: 1}; controller.$.model = { refresh: () => {}, @@ -25,6 +30,7 @@ describe('Route', () => { it('should call the route unlink endpoint with the agency and zone ids', () => { controller.$.model = {refresh: jest.fn()}; jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller, 'hide'); controller.route = { agencyModeFk: 1 @@ -43,6 +49,7 @@ describe('Route', () => { $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.hide).toHaveBeenCalled(); expect(controller.$.model.refresh).toHaveBeenCalledWith(); }); }); @@ -50,11 +57,8 @@ describe('Route', () => { describe('setTicketsRoute()', () => { it('should perform a POST query to add tickets to the route', () => { controller.$.model = {refresh: jest.fn()}; - - controller.route = {id: 1101}; - controller.$.model.data = [{id: 1, checked: false}]; - - const existingTicket = controller.$.model.data[0]; + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller, 'hide'); controller.route = {id: 111}; @@ -65,19 +69,14 @@ describe('Route', () => { {id: 5, checked: true}, ]; - let expectedResult = [ - existingTicket, - {id: 3}, - {id: 5} - ]; - - $httpBackend.expectPOST(`Routes/${controller.route.id}/updateVolume`).respond(200); - $httpBackend.whenPOST('Tickets/crud').respond(); + $httpBackend.whenPOST(`Routes/${controller.route.id}/updateVolume`).respond(200); + $httpBackend.expectPOST('Tickets/crud').respond(); controller.setTicketsRoute(); $httpBackend.flush(); - expect(controller.$.model.data).toEqual(expectedResult); - // expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.hide).toHaveBeenCalled(); + expect(controller.$.model.refresh).toHaveBeenCalledWith(); }); }); }); diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index 83960d47d5..e029692190 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -116,12 +116,11 @@ on-accept="$ctrl.removeTicketFromRoute($index)"> - - - - + +