2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` TRIGGER `vn`.`sale_beforeUpdate`
|
2024-01-15 11:31:03 +00:00
|
|
|
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 ;
|