SET TERM ^ ;

CREATE OR ALTER TRIGGER TTBPERFIL00IU FOR TBPERFIL
ACTIVE BEFORE INSERT OR UPDATE POSITION 0
AS
BEGIN
  IF(NEW.ID <> ' ')THEN
  BEGIN
     NEW.ID = TRIM(NEW.ID);
  END

  IF(NEW.EXIGE_CANAL_VENDAS = 1 AND NEW.TABELA = 'PED') THEN
  BEGIN
     UPDATE TBPERFIL_PEDIDO_CAMPOS P SET P.CANAL_VENDAS = 1 WHERE P.PERFIL = NEW.ID;
  END

  IF(NEW.EXIGE_VENDEDOR = 1 AND NEW.TABELA = 'PED') THEN
  BEGIN
     UPDATE TBPERFIL_PEDIDO_CAMPOS P SET P.VENDEDOR = 1 WHERE P.PERFIL = NEW.ID;
  END

  IF(NEW.EXIGE_OBSERVACAO = 1 AND NEW.TABELA = 'PED') THEN
  BEGIN
     UPDATE TBPERFIL_PEDIDO_CAMPOS P SET P.OBSERVACAO = 1 WHERE P.PERFIL = NEW.ID;
  END
END
^

SET TERM ; ^

