VERS='5.68.01'

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

isql - - <<EOT

database gc;

UPDATE 
  gc_parsys 
SET 
  version='$VERS';

create table gc_versmnt 
 (
   nodos    integer,
   dteinit  date,
   dtdeb    date,
   dtfin    date,
   bnk      char(2),
   total    float,
   comptant smallint,
   nodep    smallint
 );

create unique index ix_versmnt01 on gc_versmnt (nodos);
create index ix_versmnt02 on gc_versmnt (dteinit);

create table gc_lgvers 
 (
   nodos    integer,
   numlig   smallint,
   bnkemet  char(2),
   mont     float,
   numpiec  char(10),
   numreg   char(15),   
   dteche   date
 );

create unique index ix_lgvers01 on gc_lgvers (nodos, numlig);

alter table gc_bnk add (vrsmnt smallint before par1);

UPDATE 
  gc_bnk 
SET 
  vrsmnt = 0
WHERE
  vrsmnt IS NULL;

ALTER TABLE
  gc_trsfer
ADD
 (
   stade smallint
 );

UPDATE
  gc_trsfer
SET
  stade=0
WHERE
  stade IS NULL;

ALTER TABLE
  gc_trsfer
ADD
 (
   motif char (40)
 );

ALTER TABLE
  gc_soc
ADD (
  etiqcli1 integer,
  etiqcli2 integer
);

UPDATE
  gc_soc
SET
  etiqcli2=0,
  etiqcli1=noprof
WHERE
  etiqcli1 IS NULL;

ALTER TABLE
  gc_soc
ADD (
  clibrcm	char(6)
);

create table gc_mdfregl 
 (
   nofac    char(10),
   dteinit  date,
   dtregl   date,
   nseek    serial,
   mont     float,
   debit    smallint,
   mdreg    smallint,
   dteche   date,
   numreg   char(15)   
 );

create unique index ix_mdfregl01 on gc_mdfregl (dteinit, nseek);

ALTER TABLE
  gc_cli
ADD 
(
  subroge smallint,
  classub char (1),
  coefsav1 float,
  coefsav2 float 
);

UPDATE 
  gc_cli
SET
 subroge = 0,
 coefsav1= 0,
 coefsav2= 0
WHERE
  subroge IS NULL; 

ALTER TABLE
  gc_art
ADD 
(
  garantie smallint
);

UPDATE 
  gc_art
SET
 garantie = 0
WHERE
  garantie IS NULL; 

create table gc_marque 
 (
   code     integer,
   desig    char(15)
 );

create unique index ix_marque01 on gc_marque (code);

create table gc_typmach
(
  code      integer , 
  desig     char(15), 
  delai     integer  
);

create unique index ix_typmach01 on gc_typmach (code);

create table gc_tech
(
  code      integer ,
  nom       char(25) ,
  revh      float  
);

create unique index ix_tech01 on gc_tech (code);

create table gc_strait 
(
  code      integer,
  rsoc      char(25), 
  respon    char(25),
  ad1       char(25),
  ad2       char(25),
  cpv       char(25),
  tel       char(15),
  tel2      char(15),
  fax       char(15)
);

create unique index ix_strait01 on gc_strait (code);

create table gc_bordaf
(
  num integer, 
  dtbor date, 
  ddeb  date, 
  dfin  date, 
  codecli1 char (6), 
  codecli2 char (6), 
  typepiece smallint, 
  numdep smallint  
);

create unique index ix_bordaf01 on gc_bordaf (num);

ALTER TABLE
  gc_facveh 
ADD
(
  numbor char (7) 
);  

CREATE TABLE
gc_nobor
(
 num integer 
);


CREATE TABLE
gc_lbordaf
(
 num    integer,
 numlig integer,
 nofac  char(10)
);

create index ix_lbordaf01 on gc_lbordaf (num,numlig);

CREATE TABLE
gc_nosav
(
 num integer 
);

CREATE TABLE
gc_sav
(  
  code 	  integer,
  nocli   char(6),
  nomcl   char(30),
  statut  smallint,
  dtcre   date,
  adres   char (25),
  tel     char (15),
  marq1   smallint,
  marq    char (15),
  type1   smallint,
  type    char (15),
  gsm     char (15),
  noser   char (20),
  art     char (12),
  pxven   float,
  garan   smallint,
  pourc   float,
  repar   float,
  techn   smallint,
  nomte   char(25),
  strai   smallint,
  nomst   char(25),
  dtsor   date,
  pann1   char(60),
  pann2   char(60),
  acce1   char(60),
  acce2   char(60),
  comm1   char(60),
  comm2   char(60),
  comm3   char(60),
  rev     float,
  numdep  smallint,
  newfac  char(10),
  fachat  char(10)  
 
);

create unique index ix_sav01 on gc_sav (code);

CREATE TABLE
gc_lsav
(  
  numdos integer,
  num    integer,
  code   char(12),  
  desig  char(30), 
  quant  float,
  pxht   float,
  pxrev  float
);

create unique index ix_lsav01 on gc_lsav (numdos, num);

ALTER TABLE
  gc_soc
ADD (
    fourcess00 char(6),
    fourcess01 char(6),
    fourcess02 char(6),
    fourcess03 char(6),
    fourcess04 char(6),
    fourcess05 char(6),
    fourcess06 char(6),
    fourcess07 char(6),
    fourcess08 char(6),
    fourcess09 char(6),
    fourcess10 char(6),
    fourcess11 char(6),
    fourcess12 char(6),
    fourcess13 char(6),
    fourcess14 char(6),
    fourcess15 char(6),
    fourcess16 char(6),
    fourcess17 char(6),
    fourcess18 char(6),
    fourcess19 char(6),
    achcess00 char(8),
    achcess01 char(8),
    achcess02 char(8),
    achcess03 char(8),
    achcess04 char(8),
    achcess05 char(8),
    achcess06 char(8),
    achcess07 char(8),
    achcess08 char(8),
    achcess09 char(8),
    achcess10 char(8),
    achcess11 char(8),
    achcess12 char(8),
    achcess13 char(8),
    achcess14 char(8),
    achcess15 char(8),
    achcess16 char(8),
    achcess17 char(8),
    achcess18 char(8),
    achcess19 char(8)
);

UPDATE
  gc_soc
SET
  fourcess00 = frncentr, 
  fourcess01 = frncentr, 
  fourcess02 = frncentr, 
  fourcess03 = frncentr, 
  fourcess04 = frncentr, 
  fourcess05 = frncentr, 
  fourcess06 = frncentr, 
  fourcess07 = frncentr, 
  fourcess08 = frncentr, 
  fourcess09 = frncentr, 
  fourcess10 = frncentr, 
  fourcess11 = frncentr, 
  fourcess12 = frncentr, 
  fourcess13 = frncentr, 
  fourcess14 = frncentr, 
  fourcess15 = frncentr, 
  fourcess16 = frncentr, 
  fourcess17 = frncentr, 
  fourcess18 = frncentr, 
  fourcess19 = frncentr
WHERE
  fourcess00 is null;

ALTER TABLE
  gc_art
ADD 
(
  contrmq smallint
);

CREATE TABLE gc_lgf2
 (
   numfac  char(10),
   numlig  smallint,
   dtlivrs date,
   qtalloc float,
   nocomf  char(7)    
 );
 
create unique index ix_lgf201 on gc_lgf2 (numfac, numlig);

CLOSE DATABASE;

EOT

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

echo "Mise a jour terminee"
