salix/db/routines/vn/triggers/sale_beforeUpdate.sql

24 lines
696 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`sale_beforeUpdate`
BEFORE UPDATE ON `sale`
FOR EACH ROW
BEGIN
/*
IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN
CALL util.throw('Cannot insert a service item into a ticket');
END IF;
*/
SET NEW.editorFk = account.myUser_getId();
IF NEW.discount > 100 THEN
SET NEW.discount = 0;
END IF;
IF old.discount > 0 AND NEW.discount = 0 THEN
INSERT INTO ticketLog
SET originFk = NEW.ticketFk, userFk = account.myUser_getId(), `action` = 'insert',
description = CONCAT('Cambio de descuento del item :', ' ', new.itemFk, ' de ', old.discount ,' a 0 ');
END IF;
END$$
DELIMITER ;