From b906a8e91d74fc05d883a3a6a8e1a6bb81309102 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 17 Jun 2021 11:52:12 +0200 Subject: [PATCH 1/4] added ticket.nickname to basicdata --- .../01-ticket_componentMakeUpdate.sql | 103 ++++++++++++++++++ .../back/methods/ticket/componentUpdate.js | 8 +- .../front/basic-data/step-one/index.html | 8 ++ .../ticket/front/basic-data/step-two/index.js | 1 + 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql diff --git a/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql b/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql new file mode 100644 index 000000000..ac3e85f08 --- /dev/null +++ b/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql @@ -0,0 +1,103 @@ +DROP PROCEDURE IF EXISTS `vn`.`ticket_componentMakeUpdate`; + +DELIMITER $$ +$$ + +CREATE + DEFINER = root@`%` PROCEDURE `vn`.`ticket_componentMakeUpdate`(IN vTicketFk INT, IN vClientFk INT, + IN vNickname VARCHAR(50), IN vAgencyModeFk INT, + IN vAddressFk INT, IN vZoneFk INT, IN vWarehouseFk TINYINT, + IN vCompanyFk SMALLINT, IN vShipped DATETIME, + IN vLanded DATE, IN vIsDeleted TINYINT(1), + IN vHasToBeUnrouted TINYINT(1), IN vOption INT) +BEGIN +/** + * Modifica en el ticket los campos que se le pasan por parĂ¡metro + * y cambia sus componentes + * + * @param vTicketFk Id del ticket a modificar + * @param vClientFk nuevo cliente + * @param vNickname nuevo alias + * @param vAgencyModeFk nueva agencia + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo almacen + * @param vCompanyFk nueva empresa + * @param vShipped nueva fecha del envio de mercancia + * @param vLanded nueva fecha de recepcion de mercancia + * @param vIsDeleted si se borra el ticket + * @param vHasToBeUnrouted si se le elimina la ruta al ticket + * @param vOption opcion para el case del proc ticketComponentUpdateSale + */ + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); + + START TRANSACTION; + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + CALL zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.nickname = vNickname, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.zoneFk = vZoneFk, + t.zonePrice = vPrice, + t.zoneBonus = vBonus, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + IF vOption <> 8 THEN + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent + SELECT * FROM tmp.ticketComponentPreview; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + END IF; + COMMIT; + + DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; +END$$ +DELIMITER ; + diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 44e85c093..b66179eb8 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -19,6 +19,11 @@ module.exports = Self => { description: 'The client id', required: true }, + { + arg: 'nickname', + type: 'string', + description: 'The client nickname' + }, { arg: 'agencyModeFk', type: 'number', @@ -145,10 +150,11 @@ module.exports = Self => { // Force to unroute ticket const hasToBeUnrouted = true; - const query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; const res = await Self.rawSql(query, [ args.id, args.clientFk, + args.nickname, args.agencyModeFk, args.addressFk, args.zoneFk, diff --git a/modules/ticket/front/basic-data/step-one/index.html b/modules/ticket/front/basic-data/step-one/index.html index 98d92e7e2..b7ba6c9d0 100644 --- a/modules/ticket/front/basic-data/step-one/index.html +++ b/modules/ticket/front/basic-data/step-one/index.html @@ -6,6 +6,14 @@
+ + + + Date: Fri, 18 Jun 2021 15:54:33 +0200 Subject: [PATCH 2/4] address nickname now gets updated when client or address updates --- .../front/basic-data/step-one/index.html | 30 +++++++++---------- .../ticket/front/basic-data/step-one/index.js | 9 ++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/modules/ticket/front/basic-data/step-one/index.html b/modules/ticket/front/basic-data/step-one/index.html index b7ba6c9d0..24ec509a2 100644 --- a/modules/ticket/front/basic-data/step-one/index.html +++ b/modules/ticket/front/basic-data/step-one/index.html @@ -6,14 +6,6 @@ - - - - + + + + - - + ng-model="$ctrl.ticket.nickname"> + { + this.ticket.nickname = res.data.nickname; + }); + } + async onStepChange() { if (this.isFormInvalid()) { return this.vnApp.showError( From a50eebfed46db0e753ed94a4399febc76060e377 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 18 Jun 2021 16:07:13 +0200 Subject: [PATCH 3/4] Replaced salesPerson by packages column --- modules/client/front/summary/index.html | 20 ++++++++----------- modules/client/front/summary/index.js | 26 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index 956f9d198..4f54c9efa 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -1,11 +1,12 @@ + order="shipped DESC">
@@ -292,7 +293,7 @@ Id Client - Salesperson + Packages Date State Total @@ -312,13 +313,8 @@ {{::ticket.nickname}} - - - {{::ticket.userName | dashIfEmpty}} - + + {{::ticket.packages}} @@ -336,7 +332,7 @@ - {{::ticket.state}} + {{::ticket.ticketState.state.name}} diff --git a/modules/client/front/summary/index.js b/modules/client/front/summary/index.js index 40c000118..113fd2ab2 100644 --- a/modules/client/front/summary/index.js +++ b/modules/client/front/summary/index.js @@ -3,6 +3,21 @@ import Summary from 'salix/components/summary'; import './style.scss'; class Controller extends Summary { + constructor($element, $) { + super($element, $); + + this.ticketFilter = { + include: { + relation: 'ticketState', + scope: { + fields: ['stateFk', 'code', 'alertLevel'], + include: { + relation: 'state' + } + } + } + }; + } $onChanges() { if (!this.client) return; @@ -18,6 +33,7 @@ class Controller extends Summary { } }); } + get isEmployee() { return this.aclService.hasAny(['employee']); } @@ -41,13 +57,15 @@ class Controller extends Summary { } stateColor(ticket) { - if (ticket.alertLevelCode === 'OK') + const ticketState = ticket.ticketState; + + if (ticketState.code === 'OK') return 'success'; - else if (ticket.alertLevelCode === 'FREE') + else if (ticketState.code === 'FREE') return 'notice'; - else if (ticket.alertLevel === 1) + else if (ticketState.alertLevel === 1) return 'warning'; - else if (ticket.alertLevel === 0) + else if (ticketState.alertLevel === 0) return 'alert'; } From a4f20daf17fee9a6c849a51ef9d79b1bcaddd8cf Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 18 Jun 2021 16:14:30 +0200 Subject: [PATCH 4/4] Updated unit test --- modules/client/front/summary/index.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/client/front/summary/index.spec.js b/modules/client/front/summary/index.spec.js index 08f3f8554..397bb4240 100644 --- a/modules/client/front/summary/index.spec.js +++ b/modules/client/front/summary/index.spec.js @@ -76,25 +76,25 @@ describe('Client', () => { describe('stateColor()', () => { it('should return "success" when the alertLevelCode property is "OK"', () => { - const result = controller.stateColor({alertLevelCode: 'OK'}); + const result = controller.stateColor({ticketState: {code: 'OK'}}); expect(result).toEqual('success'); }); it('should return "notice" when the alertLevelCode property is "FREE"', () => { - const result = controller.stateColor({alertLevelCode: 'FREE'}); + const result = controller.stateColor({ticketState: {code: 'FREE'}}); expect(result).toEqual('notice'); }); it('should return "warning" when the alertLevel property is "1', () => { - const result = controller.stateColor({alertLevel: 1}); + const result = controller.stateColor({ticketState: {code: 'PACKING', alertLevel: 1}}); expect(result).toEqual('warning'); }); it('should return "alert" when the alertLevel property is "0"', () => { - const result = controller.stateColor({alertLevel: 0}); + const result = controller.stateColor({ticketState: {code: 'FIXING', alertLevel: 0}}); expect(result).toEqual('alert'); });