CREATE TABLE TBPDV_CFE_ITEM (
    ID INTEGER NOT NULL,
    PDV_CFE_ID INTEGER,
    ESTOQUE_ID INTEGER,
    SEQUENCIA INTEGER,
    CFOP_CODIGO VARCHAR(5),
    OPERACAO_CODIGO VARCHAR(3),
    PRODUTO_ID INTEGER,
    PRODUTO_DESCRICAO VARCHAR(200),
    NCM_CODIGO VARCHAR(10),
    LOCALIZACAO_ID INTEGER,
    TAMANHO INTEGER,
    EAN VARCHAR(13),
    QUANTIDADE DECIMAL(15,4),
    VALOR_UNITARIO DECIMAL(15,4),
    VALOR_DESCONTO DECIMAL(15,2),
    VALOR_DESCONTO_RATEIO DECIMAL(15,2),
    VALOR_ACRESCIMO DECIMAL(15,2),
    VALOR_ACRESCIMO_RATEIO DECIMAL(15,2),
    VALOR_TOTAL DECIMAL(15,2),
    VALOR_LIQUIDO DECIMAL(15,2),
    VALOR_CONTABIL DECIMAL(15,2),
    TRIBUTACAO_ORIGEM INTEGER,
    TRIBUTACAO_ICMS INTEGER,
    PERCENTUAL_BASECALCULO_ICMS DECIMAL(15,2),
    BASECALCULO_ICMS DECIMAL(15,2),
    ALIQUOTA_ICMS DECIMAL(15,2),
    VALOR_ICMS DECIMAL(15,2),
    TRIBUTACAO_PIS CHAR(2),
    BASECALCULO_PIS DECIMAL(15,2),
    ALIQUOTA_PIS DECIMAL(15,2),
    VALOR_PIS DECIMAL(15,2),
    TRIBUTACAO_COFINS CHAR(2),
    BASECALCULO_COFINS DECIMAL(15,2),
    ALIQUOTA_COFINS DECIMAL(15,2),
    VALOR_COFINS DECIMAL(15,2),
    VALOR_OUTRAS_ICMS DECIMAL(15,2),
    INFORMACOES_COMPLEMENTARES VARCHAR(255),
    PEDIDO INTEGER DEFAULT 0,
    PEDIDO_ITEM_ID INTEGER DEFAULT 0,
    REDUCAO_BASE_PISCOF CHAR(1));

ALTER TABLE TBPDV_CFE_ITEM
ADD CONSTRAINT PK_TBPDV_CFE_ITEM
PRIMARY KEY (ID);

CREATE SEQUENCE GTBPDV_CFE_ITEM;

create trigger tbpdv_cfe_item_b01i for tbpdv_cfe_item
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbpdv_cfe_item,1);
end;
