SET TERM ^ ;

CREATE trigger ttbminuta_coleta_item_b09i for tbminuta_coleta_item
active before insert position 9
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' DOC.FISCAL: '||FN_LPAD(NEW.DOCUMENTO_FISCAL, 9, '0')||' INCLUÍDO';
    END

    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBMINUTA_COLETA', NEW.MINUTA_COLETA_ID, HISTORICO);
    END
end
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbminuta_coleta_item_b01d for tbminuta_coleta_item
active before delete position 9
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' DOC.FISCAL: '||FN_LPAD(OLD.DOCUMENTO_FISCAL, 9, '0')||' EXCLUÍDO';
    END

    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBMINUTA_COLETA', OLD.MINUTA_COLETA_ID, HISTORICO);
    END
end
^

SET TERM ; ^