VERS='5.70.57'

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

isql - - <<EOT

DATABASE gc;

UPDATE 
  gc_parsys 
SET 
  version='$VERS'
WHERE
  version<'$VERS';

drop table gc_vndc;
drop table gc_vndlc;
drop table gc_fobj;
drop table gc_vndblr;
drop table gc_vndp;


CREATE TABLE
gc_vndc
(
  code     char(2),
  dtdepart date,
  txmrg    float,
  txcom    float,
  primobj  float,
  txbalag  float,
  primbal  float,
  prgbase  float,
  grp      smallint  
);

CREATE INDEX ix_vndc01 ON gc_vndc (code);

CREATE TABLE
gc_vndlc 
(
  code char(2),
  dtdepart date,
  fam  char(4),
  an   smallint,
  mois smallint,
  dtper date,
  nbpnt smallint,
  ca   float,
  prgf float,
  prgv float,
  nbj  float,
  grp  smallint
);

CREATE INDEX ix_vndlc01 ON gc_vndlc (code, dtdepart);

CREATE TABLE
gc_fobj
(
  code char(4),
  nbpnt smallint, 
  grp1  smallint,
  grp2  smallint,
  grp3  smallint,
  grp4  smallint,
  grp5  smallint
);

CREATE INDEX ix_fobj01 ON gc_fobj (code);

CREATE TABLE gc_vndblr
(
  code		CHAR(2),
  an		SMALLINT,
  mois		SMALLINT,
  trch1		FLOAT,
  trch2		FLOAT,
  trch3		FLOAT,
  trch4		FLOAT,
  echu		FLOAT,
  nechu		FLOAT
);

CREATE UNIQUE INDEX ux_vndblr01
ON gc_vndblr (code, an, mois);

CREATE TABLE
gc_vndp
(
  code char(2),
  libel char(20), 
  grp  smallint,
  nbj1 smallint,
  nbj2 smallint,
  nbj3 smallint,
  nbj4 smallint,
  nbj5 smallint,
  nbj6 smallint,
  nbj7 smallint,
  nbj8 smallint,
  nbj9 smallint,
  nbj10 smallint,
  nbj11 smallint,
  nbj12 smallint
);

CREATE INDEX ix_vndp01 ON gc_vndp (code);

ALTER TABLE
 gc_vnd
ADD
(
 profil char(2)
);

CLOSE DATABASE;

EOT

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

echo "Mise a jour terminee"
