CREATE TABLE TBGNRE_NF (
    ID INTEGER NOT NULL,
    PDV_CFE_ID INTEGER,
    NF_ID INTEGER,
    SEQUENCIA INTEGER,
    GNRE_RECEITA_ID INTEGER,
    GNRE_DET_RECEITA_ID INTEGER,
    GNRE_CLASS_PROD_ID INTEGER,
    GNRE_TIPO_DOCUMENTO_ID INTEGER,
    DATA_VENCIMENTO DATE,
    DATA_PAGAMENTO DATE,
    PERIODO_REFERENCIA INTEGER,
    MES_REFERENCIA INTEGER,
    ANO_REFERENCIA INTEGER,
    CONVENIO VARCHAR(200),
    XML_LOTE BLOB SUB_TYPE 0 SEGMENT SIZE 80,
    XML_AUTORIZADO BLOB SUB_TYPE 0 SEGMENT SIZE 80);

ALTER TABLE TBGNRE_NF
ADD CONSTRAINT PK_TBGNRE_NF
PRIMARY KEY (ID);

CREATE SEQUENCE GTBGNRE_NF;

SET TERM ^ ;

create trigger ttbgnre_nf_b01i for tbgnre_nf
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbgnre_nf,1);
end
^

SET TERM ; ^

CREATE INDEX ITBGNRE_NF_01
ON TBGNRE_NF (PDV_CFE_ID);

CREATE INDEX ITBGNRE_NF_02
ON TBGNRE_NF (NF_ID);

CREATE INDEX ITBGNRE_NF_03
ON TBGNRE_NF (SEQUENCIA);

CREATE INDEX ITBGNRE_NF_04
ON TBGNRE_NF (GNRE_RECEITA_ID);

CREATE INDEX ITBGNRE_NF_05
ON TBGNRE_NF (GNRE_DET_RECEITA_ID);

CREATE INDEX ITBGNRE_NF_06
ON TBGNRE_NF (GNRE_CLASS_PROD_ID);

CREATE INDEX ITBGNRE_NF_07
ON TBGNRE_NF (GNRE_TIPO_DOCUMENTO_ID);

