
ALTER TABLE `entete_achat` ADD `synchronisation_elastic` DATETIME NULL AFTER `ru`;
ALTER TABLE `entete_achat` ADD `validation_admin_elastic` DATETIME NULL AFTER `synchronisation_elastic`;
ALTER TABLE `entete_achat` ADD `date_cloture` DATETIME NULL AFTER `cloture`;

ALTER TABLE `entete_achat` ADD `code_achat` VARCHAR(191) NULL AFTER `code_commande`;



ALTER TABLE `depots` ADD `bloquage_bl_avoir` BOOLEAN NOT NULL DEFAULT FALSE AFTER `adresse`;
ALTER TABLE `parametrages` ADD `param_commande_partiel` BOOLEAN NOT NULL DEFAULT FALSE AFTER `update_caisse_avoir`;
ALTER TABLE `gratuites` ADD `conditions` ENUM('et','ou') NOT NULL DEFAULT 'et' AFTER `cumulable`;


ALTER TABLE `caisses` ADD `ecart_securite` DOUBLE NULL DEFAULT NULL AFTER `ancien_ecart`;
update caisses set ecart_securite = ecart;

ALTER TABLE `caisses` ADD `date_cloture_commission` DATETIME NULL AFTER `ecart_securite`;
ALTER TABLE `caisses` ADD `user_cloture_commission` VARCHAR(255) NULL AFTER `date_cloture_commission`;
ALTER TABLE `caisses` ADD `commission_code` VARCHAR(191) NULL AFTER `user_cloture_commission`;

ALTER TABLE `caisses` CHANGE `user_cloture_commission` `user_cloture_commission` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `caisses` CHANGE `user_code` `user_code` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `caisses` CHANGE `depot_code` `depot_code` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `caisses` CHANGE `commission_code` `commission_code` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;

alter table caisses add FOREIGN key (user_cloture_commission) references users(code);
alter table caisses add FOREIGN key (user_code) references users(code);
alter table caisses add FOREIGN key (depot_code) references depots(code);
alter table caisses add FOREIGN key (commission_code) references commissions_historique(code);


ALTER TABLE `mouvements` CHANGE `type` `type` ENUM('dc','chargement','dechargement','bl','casse','retour','garantie','venteC','retourC','casseC','cadeauxC','gratuiteC','inventaire','demande_avoir','dlc','achat','casse_usine','dlc_usine','inventaire_stock','inventaire_dlc','inventaire_casse','inventaire_reservation','inventaire_securite','dlcC','Rgratuite','Cgratuite','Dgratuite','retourI','retour_usine','securite_usine','casse_stock','dlc_stock','securite_stock','stock_securite') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `entete_achat`  CHANGE `ru` `ru` ENUM('achat', 'retour', 'casse','casse_stock','dlc', 'dlc_stock', 'avoir','avoir_financier','securite', 'securite_stock', 'stock_securite','commande') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;


ALTER TABLE `soussocietes` ADD `code_elastic` VARCHAR(255) NULL AFTER `code`;
ALTER TABLE `societes` ADD `code_elastic` VARCHAR(255) NULL AFTER `code`;

ALTER TABLE `soussocietes` ADD `code_elastic_distributeur` VARCHAR(191) NULL AFTER `code_elastic`;
ALTER TABLE `depots` ADD `prefix_recouvrement` VARCHAR(191) NULL AFTER `prefix_facture`;
UPDATE `depots` SET `prefix_recouvrement` = 'RCV';



ALTER TABLE `ligne_achat` ADD `quantite_valider` INT NULL AFTER `quantite`, 
                          ADD `quantite_livrer` INT NULL AFTER `quantite_valider`, 
                          ADD `quantite_confirmer` INT NULL AFTER `quantite_livrer`;

ALTER TABLE `tournees` ADD `categorie_code` VARCHAR(255) NULL AFTER `updated_at`;
ALTER TABLE `depots` ADD `plafond_credit_pardefaut` DOUBLE NULL DEFAULT '0' AFTER `liste_produit`;

ALTER TABLE `parametrages`  ADD `vente_prospect` ENUM('espece','oui', 'non') NOT NULL DEFAULT 'oui' AFTER `timbre`; 
ALTER TABLE `parametrages` ADD `default_accpeted_mouvements` INT NOT NULL DEFAULT '0' AFTER `vente_prospect`;
ALTER TABLE `visites` ADD `bl_code` VARCHAR(255) NULL AFTER `depot_code`;
ALTER TABLE `visites` CHANGE `type` `type` ENUM('avoir','commande','bl','recouvrement','visite','demandeAvoir','merchandising','cadeaux','ascensseur','machine','blf','Blf annulé') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;

ALTER TABLE `conventions_gms` ADD `code` VARCHAR(255) NOT NULL AFTER `id`, ADD `libelle` VARCHAR(255) NOT NULL AFTER `code`;
ALTER TABLE `paiements` ADD `blRecouvreCode` VARCHAR(255) NULL AFTER `recouvrement_code`;
ALTER TABLE `depots` ADD `closeTextRechecheClient` VARCHAR(255) NULL AFTER `adresse`;
ALTER TABLE `lignecommercials` ADD `note` VARCHAR(255) NULL AFTER `updated_at`;

-- ##############################################2025-04-24 ##########################################
ALTER TABLE `entetecommercials` ADD `from_dash` BOOLEAN NULL DEFAULT FALSE AFTER `type`; 
ALTER TABLE `parametrages` ADD `choix_delete_entete` BOOLEAN NULL DEFAULT FALSE AFTER `impression_recette`; 


ALTER TABLE `produits` CHANGE `hateur` `hauteur` DOUBLE NULL DEFAULT '0', 
                       CHANGE `largeur` `largeur` DOUBLE NULL DEFAULT '0', 
                       CHANGE `profondeur` `profondeur` DOUBLE NULL DEFAULT '0'; 

ALTER TABLE `depots` ADD `largeur` DOUBLE NULL DEFAULT '0' AFTER `chauffeur`,
                     ADD `hauteur` DOUBLE NULL DEFAULT '0' AFTER `largeur`,
                     ADD `profondeur` DOUBLE NULL DEFAULT '0' AFTER `hauteur`,
                     ADD `poids_max_kg` DOUBLE NULL DEFAULT '0' AFTER `profondeur`,
                     ADD `plafond_prix` DOUBLE NULL DEFAULT '0' AFTER `poids_max_kg`,
                     ADD `choix_plafond_prix` ENUM('HT','TTC') NOT NULL DEFAULT 'TTC' AFTER `plafond_prix`; 
ALTER TABLE `gratuites` ADD `soussociete_code` VARCHAR(255) NULL AFTER `famille_code`;
update depots set prefix_client = concat('CL',code);
ALTER TABLE `paiements` ADD `device_code` VARCHAR(191) NULL DEFAULT 'TND' AFTER `updated_at`;
ALTER TABLE `paiements` ADD `impaye` INT NOT NULL DEFAULT '0' AFTER `device_code`;
ALTER TABLE `objectifs` CHANGE `type_objectif` `type_objectif` ENUM('vente','commande','visite') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL DEFAULT 'vente';
ALTER TABLE `parametrages` ADD `enquete_equipement_obligatoire` INT NOT NULL DEFAULT '0' AFTER `default_accpeted_mouvements`;
ALTER TABLE `parametrages` ADD `equivalence_fidelite` DOUBLE NOT NULL DEFAULT '0' AFTER `enquete_equipement_obligatoire`;
ALTER TABLE `detailspgfidelites` ADD `achat` INT NOT NULL DEFAULT '0' AFTER `nbrpoints`;
ALTER TABLE `parametrages` ADD `decoupage_document_selon_societe` INT NOT NULL DEFAULT '0' AFTER `equivalence_fidelite`;
ALTER TABLE `depots` ADD `bloquage_recouvrement` INT NOT NULL DEFAULT '0' AFTER `plafond_credit_pardefaut`, ADD `bloquage_paiement` INT NOT NULL DEFAULT '0' AFTER `bloquage_recouvrement`;
ALTER TABLE `equipements` CHANGE `marque` `marque` ENUM('Intermec','Honeywell','Thermal','Smart','Honeywell_new','SPRT By Nomadis','SPRT','Delice','Sans remise et ttc','MP110','GMS','Text') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL DEFAULT 'Honeywell';

ALTER TABLE `deleted_entetes` ADD `type` VARCHAR(50) NULL AFTER `user_code`;
ALTER TABLE `deleted_entetes` ADD `JSON` JSON NULL AFTER `wavesoft`;

ALTER TABLE `depots` ADD `ajout_bl_sans_stock` INT NOT NULL DEFAULT '0' AFTER `bloquage_paiement`;


ALTER TABLE `objectifs` ADD `colisage` INT NULL DEFAULT NULL AFTER `qte`;
ALTER TABLE `objectifs` ADD `realise_carton` DOUBLE NULL DEFAULT '0' AFTER `realise_poids`;


ALTER TABLE `ligne_achat` ADD `cause` VARCHAR(255) NULL DEFAULT NULL AFTER `quantite_confirmer`;
ALTER TABLE `entete_achat` ADD `date_document` DATE NULL AFTER `date_cloture`;

ALTER TABLE `entete_achat` ADD `conflit` BOOLEAN NULL DEFAULT FALSE AFTER `date_document`;
ALTER TABLE `ligne_achat` ADD `update_quantite_nomadis` DATETIME NULL AFTER `quantite`;
ALTER TABLE `depots` ADD `modification_position_client_ajout` INT(1) NOT NULL DEFAULT '1' AFTER `ajout_bl_sans_stock`;
ALTER TABLE `depots` ADD `obligation_photo` INT(1) NOT NULL DEFAULT '1' AFTER `ajout_bl_sans_stock`;
ALTER TABLE `depots` ADD `depot_type` VARCHAR(255) NULL DEFAULT NULL AFTER `ajout_bl_sans_stock`;


ALTER TABLE `deleted_entetes` ADD `cloture` VARCHAR(1) NULL DEFAULT '0' AFTER `JSON`;
 
   ALTER TABLE `ligne_achat` ADD `quantite_valider` int(11) DEFAULT NULL AFTER `quantite`,
 ADD `quantite_livrer` int(11) DEFAULT NULL AFTER `quantite_valider`,
 ADD `quantite_confirmer` int(11) DEFAULT NULL AFTER `quantite_livrer`;
   ALTER TABLE `ligne_achat` ADD `quantite_nomadis` int(11) DEFAULT NULL AFTER `quantite_confirmer`;
   ALTER TABLE `ligne_achat` ADD `cause` VARCHAR(255) NULL DEFAULT NULL AFTER `quantite_nomadis`;
    ALTER TABLE `ligne_achat` ADD `conflit` BOOLEAN NULL AFTER `cause`;
   ALTER TABLE `entete_achat` ADD `created_by` VARCHAR(255) NULL AFTER `ru`, ADD `quantite_used` VARCHAR(255) NULL AFTER `created_by`;


ALTER TABLE `clients` ADD `soumis_remise` INT  NULL DEFAULT '1' AFTER `superficier`, ADD `soumis_gratuite` INT  NULL DEFAULT '1' AFTER `soumis_remise` ,ADD `soumis_fidelite` INT  NULL DEFAULT '1' AFTER `soumis_remise`;
ALTER TABLE `gratuites` ADD `quantite_max` INT NULL DEFAULT '0' AFTER `quantite_gratuit`;
ALTER TABLE `pgfidelites` ADD `type` ENUM('piece','carton') NOT NULL DEFAULT 'piece' AFTER `equivalance`;
ALTER TABLE `requests` ADD `cloture` INT(1) NULL DEFAULT '0' AFTER `date`;


ALTER TABLE `parametrages` ADD `double_acceptation_chargement` INT(1) NOT NULL DEFAULT '0' AFTER `decoupage_document_selon_societe`;
ALTER TABLE `depots` ADD `prefix_recouvrement` VARCHAR(255) NOT NULL DEFAULT 'RCV' AFTER `prefix_devis`;

ALTER TABLE `produits` CHANGE `prix_ht3` `prix_ht3` DOUBLE NULL DEFAULT '0';
ALTER TABLE `produits` CHANGE `prix_ttc3` `prix_ttc3` DOUBLE NULL DEFAULT '0';

ALTER TABLE `parametrages` ADD `obligation_choix_bl_recouvrement` INT NOT NULL DEFAULT '0' AFTER `decoupage_document_selon_societe`;
ALTER TABLE `produits` ADD `gratuit` INT(1) NOT NULL DEFAULT '0' AFTER `concurrent`;
ALTER TABLE `parametrages` ADD `accept_paiement_superieure_bl` INT NOT NULL DEFAULT '0' AFTER `obligation_choix_bl_recouvrement`;
ALTER TABLE `produits` ADD `parent_code` VARCHAR(255) NULL AFTER `gratuit`;
ALTER TABLE `parametrages` ADD `gestion_parfum_couleur` INT NOT NULL DEFAULT '0' AFTER `accept_paiement_superieure_bl`;

ALTER TABLE `parametrages` ADD `politique_password` INT NOT NULL DEFAULT '0' AFTER `gestion_parfum_couleur`;
ALTER TABLE `parametrages` ADD `souche` ENUM('3','4','5','6') NOT NULL DEFAULT '5' AFTER `politique_password`;
ALTER TABLE `depots` ADD `changement_prix` INT(1) NOT NULL DEFAULT '0' AFTER `modification_position_client_ajout`;
ALTER TABLE `equipements` CHANGE `marque` `marque` ENUM('Intermec','Honeywell','Thermal','Smart','Honeywell_new','SPRT By Nomadis','SPRT','Delice','Sans remise et ttc','MP110','GMS','Text','Arabe','Sans entete') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL DEFAULT 'Honeywell';
ALTER TABLE `parametrages` ADD `toucher_stock_commande` INT NOT NULL DEFAULT '0' AFTER `souche`;
ALTER TABLE `parametrages` ADD `compte_comptable_client` VARCHAR(10) NOT NULL DEFAULT '' AFTER `toucher_stock_commande`;
ALTER TABLE `produits` ADD `is_parent` INT(1) NOT NULL DEFAULT '0' AFTER `gratuit`;
ALTER TABLE `parametrages` ADD `envoie_sms_confirmation_superviseur` INT(1) NOT NULL DEFAULT '0' AFTER `compte_comptable_client`;


-- ##########################################2025-09-30 #################################################################""
ALTER TABLE `stock_depot_transfert` ADD `cloture` BOOLEAN NOT NULL DEFAULT FALSE AFTER `type`;
ALTER TABLE `gestion_commandes` CHANGE `status` `status` ENUM('Non traité','Preparation','Chargé','Sortie','Livré','Annulé','Retour') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;
ALTER TABLE `parametrages` ADD `accept_stock_negatif_envoie_retour` INT(1) NOT NULL DEFAULT '0' AFTER `compte_comptable_client`;
ALTER TABLE `soussocietes` ADD `cachet` VARCHAR(255) NULL AFTER `code_elastic_distributeur`;

ALTER TABLE `mouvement_clients` ADD `codeAnnulation` VARCHAR(255) NULL DEFAULT NULL AFTER `entetcommercial_numero`;
ALTER TABLE `parametrages` ADD `changement_statut_prospect_client_apres_vente` INT(1) NOT NULL DEFAULT '0' AFTER `accept_stock_negatif_envoie_retour`;
ALTER TABLE `affectation_clients` ADD `user_code` VARCHAR(255) NULL AFTER `route`;



ALTER TABLE `mouvements` ADD `code_envoie_merbiss` VARCHAR(255) NULL DEFAULT NULL AFTER `numero`;
ALTER TABLE `produits` ADD `colisage_2` INT(1) NOT NULL DEFAULT '0' AFTER `colisage`;
ALTER TABLE `parametrages` ADD `postion_automatique` INT(1) NOT NULL DEFAULT '0' AFTER `vente_prospect`;


ALTER TABLE `entete_achat` CHANGE `user_code` `user_code` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL;
ALTER TABLE `ligne_achat` CHANGE `code` `code` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL;
ALTER TABLE `clients` ADD `club_football_prefere` ENUM('Club africain','Autre') NULL AFTER `soumis_fidelite`;

ALTER TABLE `clients` CHANGE `potentiel` `potentiel` VARCHAR(5) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL DEFAULT NULL, 
                      CHANGE `potentiel_societe` `potentiel_societe` VARCHAR(5) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL DEFAULT NULL;

ALTER TABLE `paiements` ADD `codeAnnulation` VARCHAR(255) NULL DEFAULT NULL AFTER `code_bl`;
ALTER TABLE `users` ADD `serial_number` VARCHAR(50) NULL AFTER `ordre`;

ALTER TABLE `parametrages` ADD `useCommercialInNewBl` BOOLEAN NOT NULL DEFAULT FALSE AFTER `impression_recette`;

ALTER TABLE `soussocietes` ADD `service_reclamation` VARCHAR(55) NULL AFTER `code_elastic`;
ALTER TABLE `parametrages` ADD `visuel_impression_avant_validation` INT NOT NULL DEFAULT '1' AFTER `changement_statut_prospect_client_apres_vente`;

ALTER TABLE `mouvements` ADD `quantite_superviseur` INT NULL AFTER `qte_demande`, 
                         ADD `date_accept_superviseur` DATETIME NULL AFTER `quantite_superviseur`, 
                         ADD `quantite_magasinier` INT NULL AFTER `date_accept_superviseur`, 
                         ADD `date_accept_magasinier` DATETIME NULL AFTER `quantite_magasinier`;

ALTER TABLE `mouvements_dc` ADD `quantite_superviseur` INT NULL AFTER `qte_demande`, 
                         ADD `date_accept_superviseur` DATETIME NULL AFTER `quantite_superviseur`, 
                         ADD `quantite_magasinier` INT NULL AFTER `date_accept_superviseur`, 
                         ADD `date_accept_magasinier` DATETIME NULL AFTER `quantite_magasinier`;

ALTER TABLE `caisses` ADD `caisse_session_code` VARCHAR(191) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL DEFAULT NULL AFTER `code`;
alter table caisses add FOREIGN key (caisse_session_code) references caisses_sessions(code);
ALTER TABLE `paiements` ADD `remise_additionelle` DOUBLE NOT NULL DEFAULT '0' AFTER `virement`;
ALTER TABLE `clients` ADD `choix_tarif` INT(1) NOT NULL DEFAULT '0' AFTER `changement_prix`;
ALTER TABLE `equipements` CHANGE `marque` `marque` ENUM('Intermec','Honeywell','Thermal','Smart','Honeywell_new','SPRT By Nomadis','SPRT','Delice','Sans remise et ttc','MP110','GMS','Text','Arabe','Sans entete','SPRT By Nomadis Modele 2') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL DEFAULT 'Honeywell';

ALTER TABLE `parametrages` ADD `obligation_saise_regime` INT NOT NULL DEFAULT '0' AFTER `envoie_sms_confirmation_superviseur`;



ALTER TABLE `parametrages` ADD `dc_methode` ENUM('DC_NORMAL_TRAITMENT','DC_DOUBLE_TRAITMENT') NOT NULL DEFAULT 'DC_NORMAL_TRAITMENT' AFTER `id`, 
                           ADD `dc_methode_accept` ENUM('ACCEPT_DC','NOT_ACCEPT_DC') NOT NULL DEFAULT 'ACCEPT_DC' AFTER `dc_methode`;

ALTER TABLE `caisses` ADD `retenue` DOUBLE NULL AFTER `tarifs_special`;
ALTER TABLE `caisses_sessions` ADD `retenue` DOUBLE NULL AFTER `tarifs_special`;
                     
ALTER TABLE `lignecommercials` ADD `prix_produit` DOUBLE NOT NULL DEFAULT '0' AFTER `pu_ttc`;
ALTER TABLE `visites` ADD `objectif` VARCHAR(255) NULL DEFAULT NULL AFTER `cause`;
ALTER TABLE `users` ADD `region_rapport` VARCHAR(255) NULL AFTER `serial_number`;
ALTER TABLE `users` ADD `zone_rapport` VARCHAR(255) NULL AFTER `region_rapport`;


ALTER TABLE `visites` ADD `caisse_code` VARCHAR(191) NULL DEFAULT NULL AFTER `visite_code`;
ALTER TABLE `deleted_visites` ADD `caisse_code` VARCHAR(191) NULL DEFAULT NULL AFTER `visite_code`;



ALTER TABLE `parametrages` ADD `change_password_chaque` INT NOT NULL DEFAULT '0' AFTER `tri_produit_mobile`;
ALTER TABLE `users` ADD `last_password_change` DATE NULL DEFAULT NULL AFTER `password`;


alter table sousfamilles add FOREIGN key (famille_code) references familles(code);
alter table stock_depots add FOREIGN key (produit_code) references produits(code);
alter table stock_depots add FOREIGN key (soussociete_code) references soussocietes(code);

ALTER TABLE `entete_achat` CHANGE `ru` `ru` ENUM('achat','casse','dlc','avoir','avoir_financier','retour_Stock','commande','retour','casse_stock','dlc_stock','retour_usine_qualite','retour_stock_qualite') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `mouvements` CHANGE `type` `type` ENUM('dc','chargement','dechargement','bl','casse','retour','garantie','venteC','retourC','casseC','cadeauxC','gratuiteC','inventaire','demande_avoir','dlc','achat','casse_usine','dlc_usine','inventaire_stock','inventaire_dlc','inventaire_casse','inventaire_reservation','inventaire_securite','dlcC','Rgratuite','Cgratuite','Dgratuite','retourI','retour_usine','securite_usine','casse_stock','dlc_stock','securite_stock','stock_securite','retour_usine_qualite','retour_stock_qualite') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `stock_depots` ADD `qualite` INT NULL DEFAULT '0' AFTER `casse`;

ALTER TABLE `parametrages` ADD `ajout_nv_tarif_dans_tarification` INT NOT NULL DEFAULT '0' AFTER `change_password_chaque`;


ALTER TABLE `mouvements` CHANGE `type` `type` ENUM('dc','chargement','dechargement','bl','casse','retour','garantie','venteC','retourC','casseC','cadeauxC','gratuiteC','inventaire','demande_avoir','dlc','achat','casse_usine','dlc_usine','inventaire_stock','inventaire_dlc','inventaire_casse','inventaire_reservation','inventaire_securite','dlcC','Rgratuite','Cgratuite','Dgratuite','retourI','retour_usine','securite_usine','casse_stock','dlc_stock','securite_stock','stock_securite','retour_usine_qualite','retour_stock_qualite','pre-chargement') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;

ALTER TABLE `parametrages` ADD `chargement_par_soussociete` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'affichage des produits dans ajout chargement' AFTER `id`;

ALTER TABLE `parametrages` ADD `useCaisse` ENUM('CAISSE','SESSIONCAISSE') NOT NULL DEFAULT 'CAISSE' AFTER `id`;
ALTER TABLE `parametrages` ADD `impression_list_produit_dans_recap` INT NOT NULL DEFAULT '1' AFTER `ajout_nv_tarif_dans_tarification`;
ALTER TABLE `users` ADD `groupe_rapport` VARCHAR(255) NULL AFTER `zone_rapport`
ALTER TABLE `users` ADD `ordre_rapport` VARCHAR(255) NULL AFTER `zone_rapport`


ALTER TABLE `parametrages` ADD `useOneCaisse` BOOLEAN NOT NULL DEFAULT TRUE AFTER `id`;
ALTER TABLE `lignecommercials` ADD `tarif` VARCHAR(20) NULL AFTER `quantite_facture`;
update lignecommercials set tarif='tarif1';
ALTER TABLE `entete_achat` ADD `export` INT(1) NOT NULL DEFAULT '0' AFTER `date_cloture`;
ALTER TABLE `parametrages` ADD `facon_calcul_fidelite` ENUM('programme','par_produit') NOT NULL DEFAULT 'programme' AFTER `impression_list_produit_dans_recap`;
ALTER TABLE produits ADD point_fidelite DOUBLE NULL AFTER parent_code;
ALTER TABLE `parametrages` ADD `objectif_fidelite` INT(44) NOT NULL DEFAULT '0' AFTER `facon_calcul_fidelite`;

ALTER TABLE `marques` ADD `ordre` INT NOT NULL DEFAULT '1' AFTER `image`, ADD `veille` INT NOT NULL DEFAULT '1' AFTER `ordre`;

CREATE INDEX idx_tournees_routing_actif ON tournees (routing_code, actif);
CREATE INDEX idx_tournees_date ON tournees (date_debut, date_fin);
CREATE INDEX idx_tournees_depot ON tournees (depot_code);
CREATE INDEX idx_depots_soussociete ON depots (soussociete_code);

ALTER TABLE `parametrages` ADD `use_dc_disable_chargement` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'Lors de lajout du chargement, si on sélectionne dc en cache, le chargement.' AFTER `id`;


ALTER TABLE `clients`
ADD `type_zone` VARCHAR(255) NULL AFTER `club_football_prefere`,
ADD `entourage` VARCHAR(255) NULL AFTER `type_zone`,
ADD `clientelle_dominante` VARCHAR(255) NULL AFTER `entourage`,
ADD `nbr_client_par_jour` VARCHAR(255) NULL AFTER `clientelle_dominante`,
ADD `nbr_portes` INT NULL AFTER `nbr_client_par_jour`,
ADD `accessibilite` VARCHAR(255) NULL AFTER `nbr_portes`,
ADD `visibilite` VARCHAR(255) NULL AFTER `accessibilite`,
ADD `materiel_exposition` VARCHAR(255) NULL AFTER `visibilite`,
ADD `presence_plv_promotion` VARCHAR(255) NULL AFTER `materiel_exposition`,
ADD `organisation_rayon` VARCHAR(255) NULL AFTER `presence_plv_promotion`,
ADD `nbr_bl_par_semaine` VARCHAR(255) NULL AFTER `organisation_rayon`,
ADD `volume_vente_par_semaine` VARCHAR(255) NULL AFTER `nbr_bl_par_semaine`,
ADD `taille_lineaire_produit` VARCHAR(255) NULL AFTER `volume_vente_par_semaine`,
ADD `gammes_plus_vendus` TEXT NULL AFTER `taille_lineaire_produit`;

ALTER TABLE `depots` ADD `obligation_photo_client` INT NOT NULL DEFAULT '0' AFTER `changement_prix`;

ALTER TABLE `depots` ADD `statut_client_par_defaut` ENUM('Client','Prospect','Choix') NOT NULL DEFAULT 'Client' AFTER `obligation_photo_client`;


-- Ajout de la colonne sens.
ALTER TABLE `mouvements` ADD `sens` ENUM('E','S','N') NULL DEFAULT NULL AFTER `id`;
ALTER TABLE `stock_depot_info` ADD `sens` ENUM('E','S','N') NULL DEFAULT NULL AFTER `id`;
ALTER TABLE `parametrages` ADD `affichage_ecart_prix` INT(1) NOT NULL DEFAULT '0' AFTER `double_acceptation_chargement`;
ALTER TABLE `paiements` ADD `commercial_commande` VARCHAR(255) NULL AFTER `commercial_code`;
ALTER TABLE `paiements` ADD `bl_montants` VARCHAR(255) NULL AFTER `impaye`;
ALTER TABLE `paiements` ADD `montant_devise` DOUBLE NULL AFTER `device_code`, ADD `cours` DOUBLE NULL AFTER `montant_devise`;
ALTER TABLE `paiements` ADD `montant_wave` DOUBLE NULL AFTER `tolerance`, ADD `montant_orange` DOUBLE NULL AFTER `montant_wave`;


update `clients` set categorie_statistique =NULL where categorie_statistique = '' ;
update `clients` set classement =NULL where classement = '' ;

update `clients` set statut =NULL where statut = '' ;
ALTER TABLE `stock_depot_info` ADD `soussociete_code` VARCHAR(255) NULL AFTER `commercial_code`;
ALTER TABLE `clients` ADD `valide` INT(1)  NULL DEFAULT '0' AFTER `statut`;
ALTER TABLE `parametrages` ADD `useCommercialInNewBl` BOOLEAN NOT NULL DEFAULT FALSE AFTER `impression_recette`;

ALTER TABLE `parametrages` ADD `obligation_facture_bl` INT NOT NULL DEFAULT '0' AFTER `facon_calcul_fidelite`;
ALTER TABLE `parametrages` ADD `stock_demande_chargement` ENUM('stock_depot','stock_camion') NOT NULL DEFAULT 'stock_camion' AFTER `facon_calcul_fidelite`;

ALTER TABLE `entete_achat` ADD `sens` ENUM('E','S','N') NULL DEFAULT NULL AFTER `id`;
ALTER TABLE `entete_achat` CHANGE `ru` `ru` ENUM('achat','casse','dlc','avoir','avoir_financier','retour_Stock','commande','retour','casse_stock','dlc_stock','retour_usine_qualite','entresortiestock') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;
ALTER TABLE `mouvements` CHANGE `type` `type` ENUM('dc','chargement','dechargement','bl','casse','retour','garantie','venteC','retourC','casseC','cadeauxC','gratuiteC','inventaire','demande_avoir','dlc','achat','casse_usine','dlc_usine','inventaire_stock','inventaire_dlc','inventaire_casse','inventaire_reservation','inventaire_securite','dlcC','Rgratuite','Cgratuite','Dgratuite','retourI','retour_usine','securite_usine','casse_stock','dlc_stock','securite_stock','stock_securite','retour_usine_qualite','retour_stock_qualite','pre-chargement','entresortiestock') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;

ALTER TABLE `stock_depot_info` CHANGE `module_nomadis` `module_nomadis` ENUM('Achat','Mouvement','Inventaire','Correction','TransfertStock','StockDepot') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL DEFAULT NULL;
ALTER TABLE `entete_achat` CHANGE `date_cloture` `date_cloture` DATETIME NULL DEFAULT NULL;

ALTER TABLE `parametrages` ADD `showHtOnFacture` BOOLEAN NOT NULL DEFAULT TRUE AFTER `id`;
ALTER TABLE `familles` ADD `veille` INT(1) NOT NULL DEFAULT '1' AFTER `ordre`;
ALTER TABLE `clients` ADD `pret_travailler_avec_nous` INT(1) NOT NULL DEFAULT '0' AFTER `gammes_plus_vendus`;
ALTER TABLE `clients` CHANGE `statut` `statut` ENUM('Prospect','Client','CL','Actif','Inactif') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'Prospect';

ALTER TABLE `mouvements` ADD `user_quantite_superviseur` VARCHAR(191) NULL AFTER `date_accept_magasinier`, 
                          ADD `user_quantite_magasinier` VARCHAR(191) NULL AFTER `user_quantite_superviseur`;

ALTER TABLE `mouvements_dc` ADD `user_quantite_superviseur` VARCHAR(191) NULL AFTER `date_accept_magasinier`, 
                          ADD `user_quantite_magasinier` VARCHAR(191) NULL AFTER `user_quantite_superviseur`;


ALTER TABLE `mouvement_clients` ADD `lettrage` BOOLEAN NULL DEFAULT NULL AFTER `societe_code`;
ALTER TABLE `paiements` ADD `lettrage` BOOLEAN NULL DEFAULT NULL AFTER `societe_code`;
ALTER TABLE `mouvement_clients` CHANGE `lettrage` `lettrage` ENUM('Non traité','Partiel','Traité') NULL DEFAULT NULL;
ALTER TABLE `paiements` CHANGE `lettrage` `lettrage` ENUM('Non traité','Partiel','Traité') NULL DEFAULT NULL;
ALTER TABLE `mouvements` ADD INDEX(`soussociete_code`, `produit_code`, `numero`);



ALTER TABLE `depots` CHANGE `livraison` `livraison` ENUM('0','1','2','3') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL DEFAULT '1';

ALTER TABLE `reporting_visite_commercial` ADD `probleme_rencontre` TEXT NULL AFTER `adresse`, 
                                          ADD `action_concurence` TEXT NULL AFTER `probleme_rencontre`;
ALTER TABLE `clients` ADD `price_list` VARCHAR(191)  NULL AFTER `soumis_fidelite`;

ALTER TABLE `stock_depot_info` CHANGE `module_nomadis` `module_nomadis` ENUM('Achat','Mouvement','Inventaire','Correction','TransfertStock','StockDepot','Commande') CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;

ALTER TABLE `tournees` CHANGE `code_jour` `code_jour` ENUM('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche') CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL;

ALTER TABLE `caisses` ADD `traite` DOUBLE(8,3) NULL DEFAULT 0 AFTER `espece`;
ALTER TABLE `caisses_sessions` ADD `traite` DOUBLE(8,3) DEFAULT 0 AFTER `espece`;

ALTER TABLE `parametrages` ADD `useSelectOnChargement` BOOLEAN NOT NULL DEFAULT FALSE AFTER `showHtOnFacture`;


ALTER TABLE `produits` ADD `couleur_code` VARCHAR(255)  NULL AFTER `details`, ADD FOREIGN KEY (couleur_code) REFERENCES couleurs(code);

ALTER TABLE `users` ADD `google2fa_secret` VARCHAR(255) NULL AFTER `email`, 
                    ADD `google2fa_enabled` BOOLEAN NOT NULL DEFAULT FALSE AFTER `google2fa_secret`,
                    ADD `google2fa_ts` BIGINT NULL AFTER `google2fa_enabled`,
                    ADD `email_2fa_code` VARCHAR(255) NULL AFTER `google2fa_ts`,
                    ADD `email_2fa_expires_at` DATETIME NULL AFTER `email_2fa_code`;

ALTER TABLE `produits` ADD `exclure_calcul` VARCHAR(1) NOT NULL DEFAULT '0' AFTER `is_parent`;
ALTER TABLE `entetecommercials` ADD `remise_pied_chiffre` DOUBLE(8,3) NOT NULL DEFAULT '0' AFTER `remise_pied`;
ALTER TABLE `reporting_visite_commercial` ADD `recommendation` VARCHAR(500) NULL AFTER `activite_realise`;


ALTER TABLE `users` ADD `password_expire_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP AFTER `password`;
ALTER TABLE `parametrages` ADD `change_password_apres` INT NOT NULL DEFAULT '7' AFTER `change_password_chaque`, 
                           ADD `activate_expire_password` DATETIME NULL DEFAULT NULL AFTER `change_password_apres`;


ALTER TABLE `mouvements` CHANGE `type` `type` ENUM('dc','chargement','dechargement','bl','casse','retour','garantie','venteC','retourC','casseC','cadeauxC','gratuiteC','inventaire','demande_avoir','dlc','achat','casse_usine','dlc_usine','inventaire_stock','inventaire_dlc','inventaire_casse','inventaire_reservation','inventaire_securite','dlcC','Rgratuite','Cgratuite','Dgratuite','retourI','retour_usine','securite_usine','casse_stock','dlc_stock','securite_stock','stock_securite','retour_usine_qualite','retour_stock_qualite','pre-chargement','entresortiestock','demandeRetour','qualite','qualiteC') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `caisses` ADD `qualite` DOUBLE(8,3) NULL DEFAULT '0' AFTER `dlc`;
ALTER TABLE `caisses_sessions` ADD `qualite` DOUBLE(8,3) NULL DEFAULT '0' AFTER `dlc`;


ALTER TABLE `parametrages` ADD `showPasswordIntegration` BOOLEAN NOT NULL DEFAULT TRUE AFTER `showHtOnFacture`;


ALTER TABLE `tournees` ADD `cause` VARCHAR(255) NULL AFTER `code_layer`;
ALTER TABLE `tournees`
 ADD `type_tourne` ENUM('Recouvrement','Vente','Commande','Superviseur','Resencement','Satisfaction','Installation','Réparation','Reclamation','Autre') NULL AFTER `libelle`;


ALTER TABLE `tournees` CHANGE `routing_code` `routing_code` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL;
