ALTER TABLE `bdmenuiz`.`articles` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`clients` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`dem_devis` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`dem_lig` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`devis` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`devis_lig` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`facture` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`facture_lig` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`facture_reg` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`facture_sui` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`lettre` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`liv_bnq` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`ordres` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`ordres_lig` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`p_cabinet` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`p_experts` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`p_numero` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`p_societe` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`proforma` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`proforma_lig` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`rdvous` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`rdvous_lig` ADD COLUMN `societe` CHAR(2) NULL DEFAULT 'ME'  FIRST ;
ALTER TABLE `bdmenuiz`.`articles` DROP COLUMN `PRIXHT1_E` , DROP COLUMN `EnEuro` ;
ALTER TABLE `bdmenuiz`.`dem_devis` DROP COLUMN `Asupprimer` ;
ALTER TABLE `bdmenuiz`.`ordres_lig` DROP COLUMN `CHANTIER` , DROP COLUMN `HEURE_FIN` , DROP COLUMN `DATE_FIN` , DROP COLUMN `OUVRIER` , DROP COLUMN `DUREE`;

========================
-- solder les factures
UPDATE facture as f
     SET totalht = (SELECT SUM(mtht) FROM facture_lig as l WHERE societe="PE" AND l.no_id=f.no_id),
         totaltva = ROUND(totalht * tauxtva / 100,2),
         totalttc = totalht + totaltva
     WHERE societe="PE" ;
==========================
SELECT no_id,date,totalttc,mtregl from bddevfac.facture 
     WHERE year(date)< 2000 AND totalttc > mtregl+1 ;

