From e1b5b449ce19fb5d54ce9078ca30f114562a208d Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 3 Sep 2019 09:57:53 +0200 Subject: [PATCH] #1656 ticket.regularizar eliminar ticket --- .../10071-coffee/00-ticketAfterUpdate.sql | 14 ++++++++++++++ modules/ticket/back/methods/ticket/delete.js | 17 ++++------------- .../ticket/front/basic-data/step-one/index.html | 6 ------ modules/ticket/front/descriptor/index.html | 5 +++++ modules/ticket/front/descriptor/index.js | 2 +- modules/ticket/front/descriptor/locale/es.yml | 3 ++- 6 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 db/changes/10071-coffee/00-ticketAfterUpdate.sql diff --git a/db/changes/10071-coffee/00-ticketAfterUpdate.sql b/db/changes/10071-coffee/00-ticketAfterUpdate.sql new file mode 100644 index 000000000..427ddc977 --- /dev/null +++ b/db/changes/10071-coffee/00-ticketAfterUpdate.sql @@ -0,0 +1,14 @@ +DROP TRIGGER IF EXISTS `vn2008`.`ticket_afterUpdate`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`ticket_afterUpdate` + AFTER UPDATE ON `Tickets` + FOR EACH ROW +BEGIN + IF !(NEW.Id_Ticket <=> OLD.Id_Ticket) + OR !(NEW.warehouse_id <=> OLD.warehouse_id) + OR !(NEW.Fecha <=> OLD.Fecha) THEN + CALL stock.log_add('ticket', NEW.Id_Ticket, OLD.Id_Ticket); + END IF; +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/delete.js b/modules/ticket/back/methods/ticket/delete.js index c44c8d3e4..09dc8cc65 100644 --- a/modules/ticket/back/methods/ticket/delete.js +++ b/modules/ticket/back/methods/ticket/delete.js @@ -1,8 +1,8 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethodCtx('delete', { - description: 'Sets the isDeleted value of a ticket to 1', + Self.remoteMethod('delete', { + description: 'Sets true the isDeleted value of a ticket', accessType: 'WRITE', accepts: [{ arg: 'ticketFk', @@ -21,24 +21,15 @@ module.exports = Self => { } }); - Self.delete = async(ctx, params) => { - const transaction = await Self.beginTransaction({}); + Self.delete = async params => { try { let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}}); if (claimOfATicket) throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id); let currentTicket = await Self.app.models.Ticket.findById(params.id); - await currentTicket.updateAttributes({isDeleted: true}); - - let userId = ctx.req.accessToken.userId; - let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); - params.workerFk = worker.id; - let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}}); - - return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: state.id, workerFk: params.workerFk}); + return await currentTicket.updateAttributes({isDeleted: true}); } catch (e) { - await transaction.rollback(); throw e; } }; diff --git a/modules/ticket/front/basic-data/step-one/index.html b/modules/ticket/front/basic-data/step-one/index.html index 1dc4c14d0..3d79b9b68 100644 --- a/modules/ticket/front/basic-data/step-one/index.html +++ b/modules/ticket/front/basic-data/step-one/index.html @@ -77,11 +77,5 @@ - - - - diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 6d3d74d7f..f3b80a6c1 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -66,6 +66,11 @@ icon="icon-no036" ng-class="{bright: $ctrl.ticket.client.isTaxDataChecked == false}"> + +