CREATE TABLE TBCHEQUE_PDV (
    ID INTEGER NOT NULL,
    PAGAMENTO_CONDICAO_ID INTEGER,
    BANCO_ID INTEGER,
    AGENCIA VARCHAR(15),
    CONTA_DV VARCHAR(15),
    NUMERO_CHEQUE VARCHAR(15),
    NOME_TITULAR VARCHAR(100),
    DATA_EMISSAO DATE,
    VALOR NUMERIC(15,2),
    SALDO NUMERIC(15,2),
    OBSERVACAO VARCHAR(200),
    STATUS INTEGER);

ALTER TABLE TBCHEQUE_PDV
ADD CONSTRAINT PK_TBCHEQUE_PDV
PRIMARY KEY (ID);

CREATE SEQUENCE GTBCHEQUE_PDV;

SET TERM ^ ;

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

SET TERM ; ^


CREATE TABLE TBCHEQUE_PDV_ITEM (
    ID INTEGER NOT NULL,
    CHEQUE_PDV_ID INTEGER,
    SEQUENCIA INTEGER,
    DATA_VENCIMENTO DATE,
    VALOR NUMERIC(15,2));

ALTER TABLE TBCHEQUE_PDV_ITEM
ADD CONSTRAINT PK_TBCHEQUE_PDV_ITEM
PRIMARY KEY (ID);

CREATE SEQUENCE GTBCHEQUE_PDV_ITEM;

SET TERM ^ ;

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

SET TERM ; ^


COMMENT ON COLUMN TBCHEQUE_PDV.STATUS IS
'0 - EM ABERTO;
1 - PARCIAL;
2 - FECHADO;';

CREATE INDEX ITBCHEQUE_PDV_01
ON TBCHEQUE_PDV (PAGAMENTO_CONDICAO_ID);

CREATE INDEX ITBCHEQUE_PDV_02
ON TBCHEQUE_PDV (BANCO_ID);

CREATE INDEX ITBCHEQUE_PDV_03
ON TBCHEQUE_PDV (AGENCIA);

CREATE INDEX ITBCHEQUE_PDV_04
ON TBCHEQUE_PDV (CONTA_DV);

CREATE INDEX ITBCHEQUE_PDV_05
ON TBCHEQUE_PDV (NUMERO_CHEQUE);

CREATE INDEX ITBCHEQUE_PDV_06
ON TBCHEQUE_PDV (DATA_EMISSAO);

CREATE INDEX ITBCHEQUE_PDV_07
ON TBCHEQUE_PDV (STATUS);

