DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`creditClassification_beforeUpdate`
	BEFORE UPDATE ON `creditClassification`
	FOR EACH ROW
BEGIN
	IF NEW.client <> OLD.client THEN
		CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT');
    END IF;
    IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN
		UPDATE `client` c
			SET creditInsurance = NULL WHERE c.id = NEW.client;
    END IF;
END$$
DELIMITER ;
