VERS='5.70.89'

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

isql - - <<EOT

DATABASE gc;

SELECT codart, tva, pvht, qttar1, qttar2, qttar3, qttar4, qttar5,
tarif1, tarif2, tarif3, tarif4, tarif5  FROM gc_vrev
WHERE iddep = 1 AND
codart IN (
  SELECT DISTINCT code FROM gc_loc
  ) 
INTO temp t1;
CREATE INDEX ixt1 ON t1(codart);

UPDATE gc_loc 
   SET 
 gc_loc.tva= ( 
    select t1.tva from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 gc_loc.qttar1= ( 
    select t1.qttar1 from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 gc_loc.qttar2= ( 
    select t1.qttar2 from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 gc_loc.qttar3= ( 
    select t1.qttar3 from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 gc_loc.qttar4= ( 
    select t1.qttar4 from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 gc_loc.qttar5= ( 
    select t1.qttar5 from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
      pvht1 = ( 
    select tarif1 * pvht from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 pvht2= ( 
    select tarif2 * pvht from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 pvht3= ( 
    select tarif3 * pvht from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 pvht4= ( 
    select tarif4 * pvht from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

UPDATE gc_loc 
   SET 
 pvht5= ( 
    select tarif5 * pvht from t1 where t1.codart=gc_loc.code)
WHERE 
 code in (select codart from t1);

CLOSE DATABASE;

EOT

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

echo "Mise a jour terminee"
