SET TERM ^ ;

CREATE OR ALTER trigger ttbestoque_minimo_b0iu_01 for tbestoque_minimo
active before insert or update position 0
AS
begin
  if (NEW.ESTOQUE_MAX < NEW.QUANTIDADE) then NEW.ESTOQUE_MAX = NEW.QUANTIDADE;
  if (NEW.M01 < NEW.T01 OR NEW.T01 = 0) then NEW.M01 = NEW.T01;
  if (NEW.M02 < NEW.T02 OR NEW.T02 = 0) then NEW.M02 = NEW.T02;
  if (NEW.M03 < NEW.T03 OR NEW.T03 = 0) then NEW.M03 = NEW.T03;
  if (NEW.M04 < NEW.t04 OR NEW.T04 = 0) then NEW.M04 = NEW.T04;
  if (NEW.M05 < NEW.T05 OR NEW.T05 = 0) then NEW.M05 = NEW.T05;
  if (NEW.M06 < NEW.T06 OR NEW.T06 = 0) then NEW.M06 = NEW.T06;
  if (NEW.M07 < NEW.T07 OR NEW.T07 = 0) then NEW.M07 = NEW.T07;
  if (NEW.M08 < NEW.T08 OR NEW.T08 = 0) then NEW.M08 = NEW.T08;
  if (NEW.M09 < NEW.T09 OR NEW.T09 = 0) then NEW.M09 = NEW.T09;
  if (NEW.M10 < NEW.T10 OR NEW.T10 = 0) then NEW.M10 = NEW.T10;
  if (NEW.M11 < NEW.T11 OR NEW.T11 = 0) then NEW.M11 = NEW.T11;
  if (NEW.M12 < NEW.T12 OR NEW.T12 = 0) then NEW.M12 = NEW.T12;
  if (NEW.M13 < NEW.T13 OR NEW.T13 = 0) then NEW.M13 = NEW.T13;
  if (NEW.M14 < NEW.T14 OR NEW.T14 = 0) then NEW.M14 = NEW.T14;
  if (NEW.M15 < NEW.T15 OR NEW.T15 = 0) then NEW.M15 = NEW.T15;
  if (NEW.M16 < NEW.T16 OR NEW.T16 = 0) then NEW.M16 = NEW.T16;
  if (NEW.M17 < NEW.T17 OR NEW.T17 = 0) then NEW.M17 = NEW.T17;
  if (NEW.M18 < NEW.T18 OR NEW.T18 = 0) then NEW.M18 = NEW.T18;
  if (NEW.M19 < NEW.T19 OR NEW.T19 = 0) then NEW.M19 = NEW.T19;
  if (NEW.M20 < NEW.T20 OR NEW.T20 = 0) then NEW.M20 = NEW.T20;
end^

SET TERM ; ^

