SET TERM ^ ;

CREATE OR ALTER trigger ttbestoque_det_alocacao_b0i_01 for tbestoque_detalhe_alocacao
active before insert position 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
  BEGIN
    NEW.ID = GEN_ID(GTBESTOQUE_DETALHE_ALOCACAO,1);
  END


  IF (NEW.SALDO < 0) THEN
  BEGIN
    NEW.SALDO = 0;
  END

END
^

SET TERM ; ^

