
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`;