CREATE OR ALTER trigger ttbremessa_item_processado_b12u for tbremessa_item_processado
active before update position 12
AS
declare variable tipo varchar(1);
begin
  if(new.situacao = 3 and old.situacao is distinct from new.situacao and new.familia_codigo > 0)then
  begin

     select first 1
        R1.Tipo
     From TbRemessa R1
     Where R1.Numero = NEW.remessa
        into :tipo;
    
     --se remessa principal, talao nao e de placa e nao enctrou no cd
     if(coalesce(tipo,'0') = '1' and coalesce(new.entrada_cd,0) = 0 and not (new.controle between 5500 and 5999))then
     begin
        Exception "..." 'ATENCAO, TALAO NAO DEU ENTRADA NO CD, OPERACAO CANCELADA!';
     end

     execute procedure SP_BLOQUEAR_REMESSA_EM_ABERTO(NEW.PROGRAMACAO_ESTEIRA, NEW.up_id, NEW.remessa, 0);
  end
end;

