VERS='PHOTO'

echo "Mise a jour de la base de donnees pour Version $VERS"

isql - - <<EOT

database gc;

create table gc_pochette 
  (
    poc_bar char(6),
    poc_num integer not null,
    code_vnd char(2) not null,
    code_cli char(6) not null,
    poc_nomcli char(30) not null,
    poc_datdep date not null,
    poc_heudep integer not null,
    poc_datrec date not null,
    poc_heurec integer not null,
    code_art char(12) not null,
    code_sart char(12) not null,
    maf_code integer not null,
    tpf_code integer not null,
    tpb_code integer not null,
    psf_code integer not null,
    sef_code integer not null,
    poc_arrhes float not null,
    poc_datven date not null,
    poc_heuven integer not null,
    numbl char(10),
    numdep smallint not null,
    poc_in smallint not null,
    poc_datin date not null,
    poc_heurin integer not null,
    poc_out smallint not null,
    poc_datout date not null,
    poc_heurout integer not null,
    poc_sent smallint not null,
    code_sart2 char(12),
    code_sart3 char(12),
    poc_tel char(15),
    poc_aps char(9),
    poc_tirage char(6)
  );

create unique index ix_poc1 on gc_pochette (poc_num);
create index ix194_5 on gc_pochette (poc_datdep);

create table gc_production 
  (
    poc_num integer not null,
    code_lab char(2) not null,
    code_art char(12) not null,
    code_sart char(12) not null,
    pro_date date not null,
    pro_heure integer not null,
    pro_nbtrav smallint not null,
    pro_pxtrav float not null,
    pro_nbstrav smallint not null,
    pro_pxstrav float not null,
    pro_comment char(50) not null,
    numdep smallint not null,
    pro_in smallint not null,
    pro_datin date not null,
    pro_heurin integer not null,
    pro_out smallint not null,
    pro_datout date not null,
    pro_heurout integer not null,
    pro_sent smallint not null,
    code_sart2 char(12),
    code_sart3 char(12),
    pro_nbstrav2 smallint,
    pro_pxstrav2 float,
    pro_nbstrav3 smallint,
    pro_pxstrav3 float,
    code_ctrl char(2)
  );

create unique index ix_pro1 on gc_production (poc_num);

create table gc_stt 
  (
    stt_date date not null,
    numdep smallint not null,
    stt_gache1 integer not null,
    stt_gache2 integer not null,
    stt_gache3 integer not null,
    stt_gache4 integer not null,
    stt_gache5 integer not null,
    stt_cpt1 integer not null,
    stt_cpt2 integer not null,
    stt_cpt3 integer not null,
    stt_cpt4 integer not null,
    stt_cpt5 integer not null,
    stt_cpt6 integer not null,
    stt_cpt7 integer not null,
    stt_cpt8 integer not null,
    stt_cpt9 integer not null,
    stt_cpt10 integer not null,
    stt_cpt11 integer not null,
    stt_cpt12 integer not null,
    stt_cpt13 integer not null,
    stt_cpt14 integer not null,
    stt_cpt15 integer not null,
    stt_11012 integer not null,
    stt_11024 integer not null,
    stt_120 integer not null,
    stt_12612 integer not null,
    stt_12624 integer not null,
    stt_13512 integer not null,
    stt_13524 integer not null,
    stt_13536 integer not null,
    stt_kodak integer not null,
    stt_agfa integer not null,
    stt_fuji integer not null,
    stt_france integer not null,
    stt_konica integer not null,
    stt_divers integer not null,
    stt_sent smallint not null,
    stt_13515 integer,
    stt_13527 integer,
    stt_13539 integer,
    stt_aps15 integer,
    stt_aps25 integer,
    stt_aps40 integer
  );

create unique index ix_stt1 on gc_stt (stt_date,numdep);

create table gc_thp 
  (
    codvnd char(2),
    numdep smallint,
    dt date,
    dtfin date,
    fh1 smallint,
    lun float,
    fh2 smallint,
    mar float,
    fh3 smallint,
    mer float,
    fh4 smallint,
    jeu float,
    fh5 smallint,
    ven float,
    fh6 smallint,
    sam float,
    fh7 smallint,
    dim float,
    total float,
    traite smallint
  );

create unique index ix_thp01 on gc_thp (codvnd,numdep,dt);

create table gc_serie 
  (
    codart char(12),
    noser1 char(20),
    noser2 char(20),
    noser3 char(20),
    four char(6),
    cli char(6),
    numpiec char(10),
    dt date,
    codmvt smallint,
    qtt float,
    numdep smallint,
    numrpl smallint,
    pxach float,
    numint integer,
    traite smallint
  );

create index ix_serie2 on gc_serie (numpiec);
create index ix_serie3 on gc_serie (noser1);
create index ix_serie4 on gc_serie (noser2);
create index ix_serie5 on gc_serie (noser3);
create index ix_serie1 on gc_serie (codart,noser1,noser2,noser3,numdep,codmvt);

close database;

EOT

chmod 666 $DBPATH/gc.dbs/*.idx
chmod 666 $DBPATH/gc.dbs/*.dat

echo "Mise a jour terminee"
