SET TERM ^ ;

CREATE OR ALTER trigger ttbremessa_item_processado_b14u for tbremessa_item_processado
active before update position 0
AS
begin
  if(new.entrada_cd is distinct from old.entrada_cd and new.entrada_cd = 1)then
  begin

    if(new.controle between 6000 and 6999)then
    begin
        new.situacao      = 3;
        new.DATA_PRODUCAO = (SELECT FIRST 1 T.DATA_PRODUCAO FROM TBTURNO T WHERE T.TURNO_CORRENTE = '1');
        new.HORA_PRODUCAO = CURRENT_TIMESTAMP;
        new.TURNO         = (SELECT FIRST 1 T.CODIGO FROM TBTURNO T WHERE T.TURNO_CORRENTE = '1');
    end else
    begin

        if(new.situacao = 1)then
        begin
            Exception "..." 'ATENCAO, TALAO NAO CORTADO, OPERACAO CANCELADA!';
        end
    
        if(new.situacao = 3)then
        begin
            Exception "..." 'ATENCAO, TALAO LIBERADO PARA PRODUCAO, OPERACAO CANCELADA!';
        end

    end

    new.data_entrada_cd = current_timestamp;
    new.data_prod_entrada_cd = fn_data_producao();
  end
end
^

SET TERM ; ^

