SET TERM ^ ;

CREATE OR ALTER TRIGGER TTBESTOQUE_MINIMO_B1IU_02 FOR TBESTOQUE_MINIMO
ACTIVE BEFORE INSERT OR UPDATE POSITION 1
AS
BEGIN

   IF (NEW.T01 > 0 OR NEW.T02 > 0 OR NEW.T03 > 0 OR NEW.T04 > 0  OR
       NEW.T05 > 0 OR NEW.T06 > 0 OR NEW.T07 > 0 OR NEW.T08 > 0  OR
       NEW.T09 > 0 OR NEW.T10 > 0 OR NEW.T11 > 0 OR NEW.T12 > 0  OR
       NEW.T13 > 0 OR NEW.T14 > 0 OR NEW.T15 > 0 OR NEW.T16 > 0  OR
       NEW.T17 > 0 OR NEW.T18 > 0 OR NEW.T19 > 0 OR NEW.T20 > 0) THEN
       BEGIN
       NEW.QUANTIDADE = NEW.T01+NEW.T02+NEW.T03+NEW.T04+NEW.T05+
                        NEW.T06+NEW.T07+NEW.T08+NEW.T09+NEW.T10+
                        NEW.T11+NEW.T12+NEW.T13+NEW.T14+NEW.T15+
                        NEW.T16+NEW.T17+NEW.T18+NEW.T19+NEW.T20;
       END

   IF (NEW.M01 > 0 OR NEW.M02 > 0 OR NEW.M03 > 0 OR NEW.M04 > 0  OR
       NEW.M05 > 0 OR NEW.M06 > 0 OR NEW.M07 > 0 OR NEW.M08 > 0  OR
       NEW.M09 > 0 OR NEW.M10 > 0 OR NEW.M11 > 0 OR NEW.M12 > 0  OR
       NEW.M13 > 0 OR NEW.M14 > 0 OR NEW.M15 > 0 OR NEW.M16 > 0  OR
       NEW.M17 > 0 OR NEW.M18 > 0 OR NEW.M19 > 0 OR NEW.M20 > 0) THEN
       BEGIN
       NEW.ESTOQUE_MAX = NEW.M01+NEW.M02+NEW.M03+NEW.M04+NEW.M05+
                        NEW.M06+NEW.M07+NEW.M08+NEW.M09+NEW.M10+
                        NEW.M11+NEW.M12+NEW.M13+NEW.M14+NEW.M15+
                        NEW.M16+NEW.M17+NEW.M18+NEW.M19+NEW.M20;
       END

  /*
   IF (NEW.PONTO_REPOSICAO >= 100) THEN
       NEW.TIPO_REPOSICAO = '1';
  */

END^

SET TERM ; ^