CREATE TABLE TBAPI_APP_PERFIL (
    ID INTEGER NOT NULL,
    PERFIL VARCHAR(20),
    STATUS INTEGER);

ALTER TABLE TBAPI_APP_PERFIL
ADD CONSTRAINT PK_TBAPI_APP_PERFIL
PRIMARY KEY (ID);

CREATE SEQUENCE GTBAPI_APP_PERFIL;

CREATE OR ALTER trigger ttbapi_app_perfil_b01i for tbapi_app_perfil
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbapi_app_perfil,1);
end;

ALTER TABLE TBMODELO_COR
    ADD ID INTEGER;

CREATE SEQUENCE GTBMODELO_COR;

SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_cor_b01i for tbmodelo_cor
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbmodelo_cor,1);
end
^

SET TERM ; ^

update tbmodelo_cor c set c.id = gen_id(GTBMODELO_COR,1);

SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_cor_b997iud for tbmodelo_cor
active before insert or update or delete position 997
AS
begin
    if(inserting)then execute procedure spi_integracao_mobile('TBMODELO_COR',new.id,'I');
    if(updating )then execute procedure spi_integracao_mobile('TBMODELO_COR',new.id,'A');
    if(deleting )then execute procedure spi_integracao_mobile('TBMODELO_COR',old.id,'D');
end
^

SET TERM ; ^

ALTER trigger "TTBMODELO_COR_biud_API" inactive;
update tbmodelo_cor c set c.id = c.id;
ALTER trigger "TTBMODELO_COR_biud_API" active;

SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_b997iud for tbmodelo
active before insert or update or delete position 997
AS
begin
    if(inserting)then execute procedure spi_integracao_mobile('TBMODELO',new.codigo,'I');
    if(updating )then execute procedure spi_integracao_mobile('TBMODELO',new.codigo,'A');
    if(deleting )then execute procedure spi_integracao_mobile('TBMODELO',old.codigo,'D');
end
^

SET TERM ; ^

ALTER trigger TTBMODELO_B08UI inactive;
update tbmodelo m set m.exige_cor = m.exige_cor;
ALTER trigger TTBMODELO_B08UI active;


SET TERM ^ ;

CREATE trigger ttbfamilia_b987iud for tbfamilia
active before insert or update or delete position 987
AS
begin
    if(inserting)then execute procedure spi_integracao_mobile('TBFAMILIA',new.codigo,'I');
    if(updating )then execute procedure spi_integracao_mobile('TBFAMILIA',new.codigo,'A');
    if(deleting )then execute procedure spi_integracao_mobile('TBFAMILIA',old.codigo,'D');
end
^

SET TERM ; ^

update tbfamilia f set f.status = f.status;

SET TERM ^ ;

CREATE trigger ttbmodelo_linha_b987iud for tbmodelo_linha
active before insert or update or delete position 987
AS
begin
    if(inserting)then execute procedure spi_integracao_mobile('TBMODELO_LINHA',new.codigo,'I');
    if(updating )then execute procedure spi_integracao_mobile('TBMODELO_LINHA',new.codigo,'A');
    if(deleting )then execute procedure spi_integracao_mobile('TBMODELO_LINHA',old.codigo,'D');
end
^

SET TERM ; ^

update tbmodelo_linha d set d.status = d.status;
update tbmodelo_linha d set d.status = d.status;

SET TERM ^ ;

CREATE trigger ttbproduto_b987iud for tbproduto
active before insert or update or delete position 987
AS
begin
    if(inserting)then execute procedure spi_integracao_mobile('TBPRODUTO',new.codigo,'I');
    if(updating )then execute procedure spi_integracao_mobile('TBPRODUTO',new.codigo,'A');
    if(deleting )then execute procedure spi_integracao_mobile('TBPRODUTO',old.codigo,'D');
end
^

SET TERM ; ^

ALTER trigger TTBPRODUTO_BIUD_API inactive;
ALTER trigger TTBPRODUTO_999 inactive;
ALTER trigger TTBPRODUTO_B01U inactive;
ALTER trigger TTBPRODUTO_B03IU inactive;
update tbproduto d set d.status = d.status where d.modelo_codigo > 0 and d.habilita_venda = '1';
ALTER trigger TTBPRODUTO_B03IU active;
ALTER trigger TTBPRODUTO_B03IU inactive;
ALTER trigger TTBPRODUTO_999 active;
ALTER trigger TTBPRODUTO_BIUD_API active;

SET TERM ^ ;

CREATE trigger ttbgrade_b987iud for tbgrade
active before insert or update or delete position 987
AS
begin
    if(inserting)then execute procedure spi_integracao_mobile('TBGRADE',new.codigo,'I');
    if(updating )then execute procedure spi_integracao_mobile('TBGRADE',new.codigo,'A');
    if(deleting )then execute procedure spi_integracao_mobile('TBGRADE',old.codigo,'D');
end
^

SET TERM ; ^

update TBGRADE g set g.status = g.status;


UPDATE OR INSERT INTO TBMENU (CONTROLE, GRUPO, SUBGRUPO, TIPO, URL, DESCRICAO, DATAHORA)
                      VALUES (22680, 'PCP', 'PCP', '1   ', '', 'Relatório de necessidade de produção de peças', '2021-07-06 17:36:41')
                    MATCHING (CONTROLE);
					