--
--
--  TABELA DOCCARGA
--
--
--DROP TABLE doccarga;

CREATE TABLE doccarga (
  doccarga_seq          NUMBER(20,0)  NOT NULL,
  empres_codigo         VARCHAR2(4)   NOT NULL,
  filial_codigo         VARCHAR2(4)   NOT NULL,
  doctip_codigo         VARCHAR2(10)  NULL,
  doccarga_numero       VARCHAR2(20)  NULL,
  doccarga_dataemissao  VARCHAR2(8)   NULL,
  doccarga_horaemissao  VARCHAR2(6)   NULL,
  doccarga_datalimite   VARCHAR2(8)   NULL,
  doccarga_status       NUMBER(2,0)   NULL,
  transp_codigo         VARCHAR2(10)  NULL,
  doccarga_dataini      VARCHAR2(8)   NULL,
  doccarga_horaini      VARCHAR2(6)   NULL,
  doccarga_datafim      VARCHAR2(8)   NULL,
  doccarga_horafim      VARCHAR2(6)   NULL,
  trpcar_placa          VARCHAR2(7)   NULL,
  trpmot_driver         VARCHAR2(10)  NULL,
PRIMARY KEY (doccarga_seq)
);

--CREATE INDEX Index_1 On doccarga (DOCCARGA_SEQ);

DROP SEQUENCE seq_doccarga;
CREATE SEQUENCE seq_doccarga INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tg_bi_doccarga
BEFORE INSERT
    ON doccarga
    FOR EACH ROW
DECLARE

BEGIN
   SELECT seq_doccarga.NEXTVAL
   INTO :NEW.DOCCARGA_SEQ FROM dual;
EXCEPTION
    WHEN OTHERS THEN ROLLBACK;
END;
--
--
-- DOCCGITM -Itens da DOCCARGA
--
--
--DROP TABLE doccgitm;

CREATE TABLE doccgitm (
  doccgitm_seq          NUMBER(20,0)  NOT NULL,
  doccarga_seq          NUMBER(20,0)  NOT NULL,
  doccab_seq            NUMBER(20,0)  NOT NULL,
  doccgitm_seqcarreg    NUMBER(4,0)   NULL,  
  doccgitm_status       NUMBER(2,0)   NULL,
  doccgitm_nvol         NUMBER(4,0)   NULL,
  doccgitm_nvolconf     NUMBER(4,0)   NULL,  
PRIMARY KEY (doccgitm_seq)
);

DROP SEQUENCE seq_doccgitm;
CREATE SEQUENCE seq_doccgitm INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tg_bi_doccgitm
BEFORE INSERT
    ON doccgitm
    FOR EACH ROW
DECLARE

BEGIN
   SELECT seq_doccgitm.NEXTVAL
   INTO :NEW.DOCCGITM_SEQ FROM dual;
EXCEPTION
    WHEN OTHERS THEN ROLLBACK;
END;
/


ALTER TABLE DOCCGITM ADD DOCCGITM_ORDEM INT NULL;


--SQL SERVER


CREATE TABLE doccarga (
  doccarga_seq          bigint IDENTITY(1,1) NOT NULL,
  empres_codigo         VARCHAR(4)   NOT NULL,
  filial_codigo         VARCHAR(4)   NOT NULL,
  doctip_codigo         VARCHAR(10)  NULL,
  doccarga_numero       VARCHAR(20)  NULL,
  doccarga_dataemissao  VARCHAR(8)   NULL,
  doccarga_horaemissao  VARCHAR(6)   NULL,
  doccarga_datalimite   VARCHAR(8)   NULL,
  doccarga_status       NUMERIC(2,0)   NULL,
  transp_codigo         VARCHAR(10)  NULL,
  doccarga_dataini      VARCHAR(8)   NULL,
  doccarga_horaini      VARCHAR(6)   NULL,
  doccarga_datafim      VARCHAR(8)   NULL,
  doccarga_horafim      VARCHAR(6)   NULL,
  trpcar_placa          VARCHAR(7)   NULL,
  trpmot_driver         VARCHAR(10)  NULL,
PRIMARY KEY (doccarga_seq)
);


CREATE TABLE doccgitm (
  doccgitm_seq           bigint IDENTITY(1,1)  NOT NULL,
  doccarga_seq          NUMERIC(20,0)  NOT NULL,
  doccab_seq            NUMERIC(20,0)  NOT NULL,
  doccgitm_seqcarreg    NUMERIC(4,0)   NULL,  
  doccgitm_status       NUMERIC(2,0)   NULL,
  doccgitm_nvol         NUMERIC(4,0)   NULL,
  doccgitm_nvolconf     NUMERIC(4,0)   NULL,  
PRIMARY KEY (doccgitm_seq)
);


ALTER TABLE DOCCGITM ADD DOCCGITM_ORDEM INT NULL;

