-- Create table
create table ANAF_EFACTURA
(
  id                    NUMBER(20) not null,
  id_fact               NUMBER(20),
  trimis                NUMBER(1),
  data_trimis           DATE,
  stare                 VARCHAR2(100),
  id_incarcare          VARCHAR2(36),
  mesaj_trimis          VARCHAR2(250),
  id_util               NUMBER(5),
  dataora               DATE default SYSDATE not null,
  id_descarcare         VARCHAR2(36),
  data_raspuns          DATE,
  tip_mesaj_raspuns     VARCHAR2(50),
  mesaj_raspuns         VARCHAR2(250),
  factura_emisa         NUMBER(1),
  cod_fiscal_emitent    VARCHAR2(30),
  cod_fiscal_beneficiar VARCHAR2(30),
  detalii               CLOB,
  xdata_act             DATE,
  xnumar_act            VARCHAR2(30),
  xtotal_cu_tva         NUMBER(20,4),
  xnume_valuta          VARCHAR2(5),
  test                  NUMBER(1) default 0 not null,
  xdata_scad            DATE,
  xtotal_fara_tva       NUMBER(20,4),
  xtotal_tva            NUMBER(20,4),
  xdescriere            VARCHAR2(4000),
  xfurnizor             VARCHAR2(250),
  xdiscount_fara_tva    NUMBER(20,4),
  xtaxe_fara_tva        NUMBER(20,4),
  xvaloare_fara_tva     NUMBER(20,4),
  xtotal_de_plata       NUMBER(20,4),
  xdetalii_plata        VARCHAR2(500),
  xclient               VARCHAR2(250),
  detalii_zip           BLOB,
  procesat              NUMBER(1) default 0 not null,
  descarcat             NUMBER(1) default 0 not null,
  filepath              VARCHAR2(250),
  xtotal_tva_ron        NUMBER(20,4),
  procesat_server       NUMBER(1) default 0 not null,
  creditnote            NUMBER(1) default 0
);
-- Add comments to the columns 
comment on column ANAF_EFACTURA.id_incarcare
  is 'Id incarcare ANAF';
comment on column ANAF_EFACTURA.mesaj_trimis
  is 'mesaj primit la trimiterea eFacturii';
comment on column ANAF_EFACTURA.id_descarcare
  is 'id raspuns ANAF';
comment on column ANAF_EFACTURA.tip_mesaj_raspuns
  is 'FACTURA PRIMITA, FACTURA TRIMISA, ERORI FACTURA';
comment on column ANAF_EFACTURA.factura_emisa
  is 'FACTURA EMISA = 1, FACTURA PRIMITA = 0';
comment on column ANAF_EFACTURA.cod_fiscal_emitent
  is 'COD FISCAL EMITENT PENTRU FACTURILE PRIMITE';
comment on column ANAF_EFACTURA.cod_fiscal_beneficiar
  is 'COD FISCAL BENEFICIAR';
comment on column ANAF_EFACTURA.detalii
  is 'DETALII FACTURA';
comment on column ANAF_EFACTURA.xdata_act
  is 'DATA FACTURA XML';
comment on column ANAF_EFACTURA.xnumar_act
  is 'NUMAR FACTURA XML';
comment on column ANAF_EFACTURA.xtotal_cu_tva
  is 'VALOARE CU TVA DIN XML ANAF - TaxInclusiveAmount';
comment on column ANAF_EFACTURA.xnume_valuta
  is 'NUME VALUTA VALOARE CU TVA DIN XML ANAF';
comment on column ANAF_EFACTURA.test
  is 'S-A TRIMIS PE SERVERUL DE TEST ANAF';
comment on column ANAF_EFACTURA.xdata_scad
  is 'DATA SCADENTA XML';
comment on column ANAF_EFACTURA.xtotal_fara_tva
  is 'VALOARE FARA TVA DIN XML ANAF - TaxExclusiveAmount';
comment on column ANAF_EFACTURA.xtotal_tva
  is 'VALOARE TVA DIN XML ANAF - TaxInclusiveAmount - TaxExclusiveAmount';
comment on column ANAF_EFACTURA.xdescriere
  is 'NOTE FACTURA XML';
comment on column ANAF_EFACTURA.xfurnizor
  is 'DENUMIRE FURNIZOR DIN XML ANAF';
comment on column ANAF_EFACTURA.xdiscount_fara_tva
  is 'DISCOUNT PE FACTURA XML ANAF';
comment on column ANAF_EFACTURA.xtaxe_fara_tva
  is 'TAXE (TRANSPORT) PE FACTURA XML ANAF';
comment on column ANAF_EFACTURA.xvaloare_fara_tva
  is 'SUMA VALOARE FARA TVA ARTICOLE XML ANAF';
comment on column ANAF_EFACTURA.xtotal_de_plata
  is 'TOTAL DE PLATA XML ANAF';
comment on column ANAF_EFACTURA.xdetalii_plata
  is 'DETALII DE PLATA XML ANAF (CONT, BANCA)';
comment on column ANAF_EFACTURA.xclient
  is 'DENUMIRE CLIENT DIN XML ANAF';
comment on column ANAF_EFACTURA.detalii_zip
  is 'ARHIVA ZIP CU RASPUNSUL ANAF, INCLUSIV SIGILIUL MFINANTE';
comment on column ANAF_EFACTURA.procesat
  is '1= RASPUNSUL SI ARHIVA DE LA ANAF AU FOST PROCESATE (NU SE MAI DESCARCA DETALII RASPUNS DE LA ANAF)';
comment on column ANAF_EFACTURA.descarcat
  is 'DACA S-A DESCARCAT ARHIVA ZIP RASPUNS SI S-A SALVAT PE DISK-UL SERVERULUI';
comment on column ANAF_EFACTURA.filepath
  is 'CALE UNDE S-A SALVAT ARHIVA ZIP RASPUNS IN STRUCTURA DE DIRECTOARE EXTRASA DIN DATELE XML';
comment on column ANAF_EFACTURA.xtotal_tva_ron
  is 'VALOARE TVA DIN XML ANAF - PENTRU FACTURILE IN VALUTA';
comment on column ANAF_EFACTURA.procesat_server
  is '1 = ARHIVA EFACTURA S-A COPIAT PE SERVER SAU PE DISK-UL DIN RETEA';
comment on column ANAF_EFACTURA.creditnote
  is '1 = CREDIT NOTE';
-- Create/Recreate indexes 
create index IDX_ANAF_EFACTURA_1 on ANAF_EFACTURA (FACTURA_EMISA, XDATA_ACT, DATA_RASPUNS)
  tablespace ROA
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Create/Recreate primary, unique and foreign key constraints 
alter table ANAF_EFACTURA
  add constraint PK_ANAF_EFACTURA primary key (ID)
  using index 
  tablespace ROA
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table ANAF_EFACTURA
  add constraint UK_ANAF_EFACTURA unique (ID_FACT)
  using index 
  tablespace ROA
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
