SET TERM ^ ;

CREATE OR ALTER trigger ttbempresa_biud998 for tbempresa
active before insert or update or delete position 998
AS
BEGIN

    IF(INSERTING) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBEMPRESA', NEW.CODIGO, 2);
    END ELSE
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBEMPRESA', OLD.CODIGO, 2);
    END

    if(inserting)then if(new.habilita_cliente = '1')then execute procedure spi_integracao_mobile('TBCLIENTE',new.codigo,'I');
    if(updating )then if(new.habilita_cliente = '1')then execute procedure spi_integracao_mobile('TBCLIENTE',new.codigo,'A');
    if(deleting )then if(old.habilita_cliente = '1')then execute procedure spi_integracao_mobile('TBCLIENTE',old.codigo,'D');
END
^

SET TERM ; ^

